Skip to content

Commit ab57dd5

Browse files
monitoring: added password_wo write-only field to google_monitoring_uptime_check_config (#13536) (#9727)
[upstream:41398e45b93639d102fbf44728740df552b517a0] Signed-off-by: Modular Magician <[email protected]>
1 parent 98fd12b commit ab57dd5

6 files changed

+300
-32
lines changed

.changelog/13536.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
monitoring: added `password_wo` write-only field and `password_wo_version` field to `google_monitoring_uptime_check_config` resource
3+
```

google-beta/services/monitoring/resource_monitoring_uptime_check_config.go

+78-6
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,33 @@ func ResourceMonitoringUptimeCheckConfig() *schema.Resource {
166166
MaxItems: 1,
167167
Elem: &schema.Resource{
168168
Schema: map[string]*schema.Schema{
169-
"password": {
170-
Type: schema.TypeString,
171-
Required: true,
172-
Description: `The password to authenticate.`,
173-
Sensitive: true,
174-
},
175169
"username": {
176170
Type: schema.TypeString,
177171
Required: true,
178172
Description: `The username to authenticate.`,
179173
},
174+
"password": {
175+
Type: schema.TypeString,
176+
Optional: true,
177+
Description: `The password to authenticate.`,
178+
Sensitive: true,
179+
ExactlyOneOf: []string{},
180+
},
181+
"password_wo": {
182+
Type: schema.TypeString,
183+
Optional: true,
184+
Description: `The password to authenticate.`,
185+
WriteOnly: true,
186+
ExactlyOneOf: []string{},
187+
RequiredWith: []string{"http_check.0.auth_info.0.password_wo_version"},
188+
},
189+
"password_wo_version": {
190+
Type: schema.TypeString,
191+
Optional: true,
192+
ForceNew: true,
193+
Description: `The password write-only version.`,
194+
RequiredWith: []string{"http_check.0.auth_info.0.password_wo"},
195+
},
180196
},
181197
},
182198
AtLeastOneOf: []string{"http_check.0.auth_info", "http_check.0.port", "http_check.0.headers", "http_check.0.path", "http_check.0.use_ssl", "http_check.0.mask_headers"},
@@ -525,6 +541,11 @@ func resourceMonitoringUptimeCheckConfigCreate(d *schema.ResourceData, meta inte
525541
obj["syntheticMonitor"] = syntheticMonitorProp
526542
}
527543

544+
obj, err = resourceMonitoringUptimeCheckConfigEncoder(d, meta, obj)
545+
if err != nil {
546+
return err
547+
}
548+
528549
lockName, err := tpgresource.ReplaceVars(d, config, "stackdriver/groups/{{project}}")
529550
if err != nil {
530551
return err
@@ -754,6 +775,11 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
754775
obj["tcpCheck"] = tcpCheckProp
755776
}
756777

778+
obj, err = resourceMonitoringUptimeCheckConfigEncoder(d, meta, obj)
779+
if err != nil {
780+
return err
781+
}
782+
757783
lockName, err := tpgresource.ReplaceVars(d, config, "stackdriver/groups/{{project}}")
758784
if err != nil {
759785
return err
@@ -1054,6 +1080,8 @@ func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d *schem
10541080
transformed := make(map[string]interface{})
10551081
transformed["password"] =
10561082
flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoPassword(original["password"], d, config)
1083+
transformed["password_wo_version"] =
1084+
flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoPasswordWoVersion(original["passwordWoVersion"], d, config)
10571085
transformed["username"] =
10581086
flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(original["username"], d, config)
10591087
return []interface{}{transformed}
@@ -1062,6 +1090,10 @@ func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoPassword(v interface{},
10621090
return d.Get("http_check.0.auth_info.0.password")
10631091
}
10641092

1093+
func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoPasswordWoVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1094+
return d.Get("http_check.0.auth_info.0.password_wo_version")
1095+
}
1096+
10651097
func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
10661098
return v
10671099
}
@@ -1580,6 +1612,20 @@ func expandMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d tpgreso
15801612
transformed["password"] = transformedPassword
15811613
}
15821614

1615+
transformedPasswordWo, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfoPasswordWo(original["password_wo"], d, config)
1616+
if err != nil {
1617+
return nil, err
1618+
} else if val := reflect.ValueOf(transformedPasswordWo); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1619+
transformed["passwordWo"] = transformedPasswordWo
1620+
}
1621+
1622+
transformedPasswordWoVersion, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfoPasswordWoVersion(original["password_wo_version"], d, config)
1623+
if err != nil {
1624+
return nil, err
1625+
} else if val := reflect.ValueOf(transformedPasswordWoVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1626+
transformed["passwordWoVersion"] = transformedPasswordWoVersion
1627+
}
1628+
15831629
transformedUsername, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(original["username"], d, config)
15841630
if err != nil {
15851631
return nil, err
@@ -1594,6 +1640,14 @@ func expandMonitoringUptimeCheckConfigHttpCheckAuthInfoPassword(v interface{}, d
15941640
return v, nil
15951641
}
15961642

1643+
func expandMonitoringUptimeCheckConfigHttpCheckAuthInfoPasswordWo(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1644+
return v, nil
1645+
}
1646+
1647+
func expandMonitoringUptimeCheckConfigHttpCheckAuthInfoPasswordWoVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1648+
return v, nil
1649+
}
1650+
15971651
func expandMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
15981652
return v, nil
15991653
}
@@ -1885,3 +1939,21 @@ func expandMonitoringUptimeCheckConfigSyntheticMonitorCloudFunctionV2(v interfac
18851939
func expandMonitoringUptimeCheckConfigSyntheticMonitorCloudFunctionV2Name(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
18861940
return v, nil
18871941
}
1942+
1943+
func resourceMonitoringUptimeCheckConfigEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
1944+
// remove passwordWoVersion from the request body
1945+
if v, ok := obj["httpCheck"]; ok {
1946+
httpCheck := v.(map[string]interface{})
1947+
if authInfo, ok := httpCheck["authInfo"].(map[string]interface{}); ok {
1948+
delete(authInfo, "passwordWoVersion")
1949+
if len(authInfo) > 0 {
1950+
httpCheck["authInfo"] = authInfo
1951+
} else {
1952+
delete(httpCheck, "authInfo")
1953+
}
1954+
obj["httpCheck"] = httpCheck
1955+
}
1956+
}
1957+
1958+
return obj, nil
1959+
}

google-beta/services/monitoring/resource_monitoring_uptime_check_config_generated_meta.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ fields:
1414
- field: 'http_check.accepted_response_status_codes.status_class'
1515
- field: 'http_check.accepted_response_status_codes.status_value'
1616
- field: 'http_check.auth_info.password'
17+
- field: 'http_check.auth_info.password_wo'
18+
- field: 'http_check.auth_info.password_wo_version'
1719
- field: 'http_check.auth_info.username'
1820
- field: 'http_check.body'
1921
- field: 'http_check.content_type'

google-beta/services/monitoring/resource_monitoring_uptime_check_config_generated_test.go

+94-15
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(t *testing.
4848
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(context),
4949
},
5050
{
51-
ResourceName: "google_monitoring_uptime_check_config.http",
52-
ImportState: true,
53-
ImportStateVerify: true,
51+
ResourceName: "google_monitoring_uptime_check_config.http",
52+
ImportState: true,
53+
ImportStateVerify: true,
54+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password_wo_version"},
5455
},
5556
},
5657
})
@@ -99,6 +100,80 @@ resource "google_monitoring_uptime_check_config" "http" {
99100
`, context)
100101
}
101102

103+
func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpPasswordWoExample(t *testing.T) {
104+
t.Parallel()
105+
106+
context := map[string]interface{}{
107+
"project_id": envvar.GetTestProjectFromEnv(),
108+
"random_suffix": acctest.RandString(t, 10),
109+
}
110+
111+
acctest.VcrTest(t, resource.TestCase{
112+
PreCheck: func() { acctest.AccTestPreCheck(t) },
113+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
114+
CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroyProducer(t),
115+
Steps: []resource.TestStep{
116+
{
117+
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpPasswordWoExample(context),
118+
},
119+
{
120+
ResourceName: "google_monitoring_uptime_check_config.http",
121+
ImportState: true,
122+
ImportStateVerify: true,
123+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password_wo_version"},
124+
},
125+
},
126+
})
127+
}
128+
129+
func testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpPasswordWoExample(context map[string]interface{}) string {
130+
return acctest.Nprintf(`
131+
resource "google_monitoring_uptime_check_config" "http" {
132+
display_name = "tf-test-http-uptime-check%{random_suffix}"
133+
timeout = "60s"
134+
user_labels = {
135+
example-key = "example-value"
136+
}
137+
138+
http_check {
139+
path = "some-path"
140+
port = "8010"
141+
request_method = "POST"
142+
content_type = "USER_PROVIDED"
143+
custom_content_type = "application/json"
144+
body = "Zm9vJTI1M0RiYXI="
145+
ping_config {
146+
pings_count = 1
147+
}
148+
auth_info {
149+
username = "name"
150+
password_wo = "password1"
151+
password_wo_version = "1"
152+
}
153+
}
154+
155+
monitored_resource {
156+
type = "uptime_url"
157+
labels = {
158+
project_id = "%{project_id}"
159+
host = "192.168.1.1"
160+
}
161+
}
162+
163+
content_matchers {
164+
content = "\"example\""
165+
matcher = "MATCHES_JSON_PATH"
166+
json_path_matcher {
167+
json_path = "$.path"
168+
json_matcher = "EXACT_MATCH"
169+
}
170+
}
171+
172+
checker_type = "STATIC_IP_CHECKERS"
173+
}
174+
`, context)
175+
}
176+
102177
func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigStatusCodeExample(t *testing.T) {
103178
t.Parallel()
104179

@@ -116,9 +191,10 @@ func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigStatusCodeExample(t *te
116191
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigStatusCodeExample(context),
117192
},
118193
{
119-
ResourceName: "google_monitoring_uptime_check_config.status_code",
120-
ImportState: true,
121-
ImportStateVerify: true,
194+
ResourceName: "google_monitoring_uptime_check_config.status_code",
195+
ImportState: true,
196+
ImportStateVerify: true,
197+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password_wo_version"},
122198
},
123199
},
124200
})
@@ -187,9 +263,10 @@ func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpsExample(t *testing
187263
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpsExample(context),
188264
},
189265
{
190-
ResourceName: "google_monitoring_uptime_check_config.https",
191-
ImportState: true,
192-
ImportStateVerify: true,
266+
ResourceName: "google_monitoring_uptime_check_config.https",
267+
ImportState: true,
268+
ImportStateVerify: true,
269+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password_wo_version"},
193270
},
194271
},
195272
})
@@ -247,9 +324,10 @@ func TestAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(t *testing.T) {
247324
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(context),
248325
},
249326
{
250-
ResourceName: "google_monitoring_uptime_check_config.tcp_group",
251-
ImportState: true,
252-
ImportStateVerify: true,
327+
ResourceName: "google_monitoring_uptime_check_config.tcp_group",
328+
ImportState: true,
329+
ImportStateVerify: true,
330+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password_wo_version"},
253331
},
254332
},
255333
})
@@ -299,9 +377,10 @@ func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigSyntheticMonitorExample
299377
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigSyntheticMonitorExample(context),
300378
},
301379
{
302-
ResourceName: "google_monitoring_uptime_check_config.synthetic_monitor",
303-
ImportState: true,
304-
ImportStateVerify: true,
380+
ResourceName: "google_monitoring_uptime_check_config.synthetic_monitor",
381+
ImportState: true,
382+
ImportStateVerify: true,
383+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password_wo_version"},
305384
},
306385
},
307386
})

google-beta/services/monitoring/resource_monitoring_uptime_check_config_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@ func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) {
4343
})
4444
}
4545

46+
func TestAccMonitoringUptimeCheckConfig_update_wo(t *testing.T) {
47+
t.Parallel()
48+
project := envvar.GetTestProjectFromEnv()
49+
host := "192.168.1.1"
50+
51+
acctest.VcrTest(t, resource.TestCase{
52+
PreCheck: func() { acctest.AccTestPreCheck(t) },
53+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
54+
CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroyProducer(t),
55+
Steps: []resource.TestStep{
56+
{
57+
Config: testAccMonitoringUptimeCheckConfig_update_wo(acctest.RandString(t, 4), "60s", "mypath", "password1", "1", project, host),
58+
},
59+
{
60+
ResourceName: "google_monitoring_uptime_check_config.http",
61+
ImportState: true,
62+
ImportStateVerify: true,
63+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"},
64+
},
65+
{
66+
Config: testAccMonitoringUptimeCheckConfig_update_wo(acctest.RandString(t, 4), "60s", "", "password2", "2", project, host),
67+
},
68+
{
69+
ResourceName: "google_monitoring_uptime_check_config.http",
70+
ImportState: true,
71+
ImportStateVerify: true,
72+
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"},
73+
},
74+
},
75+
})
76+
}
77+
4678
func TestAccMonitoringUptimeCheckConfig_noProjectId(t *testing.T) {
4779
t.Parallel()
4880
host := "192.168.1.1"
@@ -178,6 +210,41 @@ resource "google_monitoring_uptime_check_config" "http" {
178210
)
179211
}
180212

213+
func testAccMonitoringUptimeCheckConfig_update_wo(suffix, period, path, pwd_wo, pwd_wo_version, project, host string) string {
214+
return fmt.Sprintf(`
215+
resource "google_monitoring_uptime_check_config" "http" {
216+
display_name = "http-uptime-check-%s"
217+
timeout = "60s"
218+
period = "%s"
219+
220+
http_check {
221+
path = "/%s"
222+
port = "8010"
223+
request_method = "GET"
224+
auth_info {
225+
username = "name"
226+
password_wo = "%s"
227+
password_wo_version = "%s"
228+
}
229+
}
230+
231+
monitored_resource {
232+
type = "uptime_url"
233+
labels = {
234+
project_id = "%s"
235+
host = "%s"
236+
}
237+
}
238+
239+
content_matchers {
240+
content = "example"
241+
matcher = "CONTAINS_STRING"
242+
}
243+
}
244+
`, suffix, period, path, pwd_wo, pwd_wo_version, project, host,
245+
)
246+
}
247+
181248
func testAccMonitoringUptimeCheckConfig_jsonPathUpdate(suffix, project, host, content, json_path, json_path_matcher string) string {
182249
return fmt.Sprintf(`
183250
resource "google_monitoring_uptime_check_config" "http" {

0 commit comments

Comments
 (0)