Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding missing pingsCount, userLabels, and customContentType fields #16420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/9388.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
monitoring: added `pings_count`, `user_labels`, and `custom_content_type` fields to `google_monitoring_uptime_check_config` resource
```
220 changes: 218 additions & 2 deletions google/services/monitoring/resource_monitoring_uptime_check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ func ResourceMonitoringUptimeCheckConfig() *schema.Resource {
"content_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"TYPE_UNSPECIFIED", "URL_ENCODED", ""}),
Description: `The content type to use for the check. Possible values: ["TYPE_UNSPECIFIED", "URL_ENCODED"]`,
ValidateFunc: verify.ValidateEnum([]string{"TYPE_UNSPECIFIED", "URL_ENCODED", "USER_PROVIDED", ""}),
Description: `The content type to use for the check. Possible values: ["TYPE_UNSPECIFIED", "URL_ENCODED", "USER_PROVIDED"]`,
},
"custom_content_type": {
Type: schema.TypeString,
Optional: true,
Description: `A user provided content type header to use for the check. The invalid configurations outlined in the 'content_type' field apply to custom_content_type', as well as the following 1. 'content_type' is 'URL_ENCODED' and 'custom_content_type' is set. 2. 'content_type' is 'USER_PROVIDED' and 'custom_content_type' is not set.`,
},
"headers": {
Type: schema.TypeMap,
Expand All @@ -201,6 +206,21 @@ func ResourceMonitoringUptimeCheckConfig() *schema.Resource {
Default: "/",
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"},
},
"ping_config": {
Type: schema.TypeList,
Optional: true,
Description: `Contains information needed to add pings to an HTTP check.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pings_count": {
Type: schema.TypeInt,
Required: true,
Description: `Number of ICMP pings. A maximum of 3 ICMP pings is currently supported.`,
},
},
},
},
"port": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -339,9 +359,30 @@ func ResourceMonitoringUptimeCheckConfig() *schema.Resource {
Required: true,
Description: `The port to the page to run the check against. Will be combined with host (specified within the MonitoredResource) to construct the full URL.`,
},
"ping_config": {
Type: schema.TypeList,
Optional: true,
Description: `Contains information needed to add pings to a TCP check.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pings_count": {
Type: schema.TypeInt,
Required: true,
Description: `Number of ICMP pings. A maximum of 3 ICMP pings is currently supported.`,
},
},
},
},
},
},
},
"user_labels": {
Type: schema.TypeMap,
Optional: true,
Description: `User-supplied key/value data to be used for organizing and identifying the 'UptimeCheckConfig' objects. The field can contain up to 64 entries. Each key and value is limited to 63 Unicode characters or 128 bytes, whichever is smaller. Labels and values can contain only lowercase letters, numerals, underscores, and dashes. Keys must begin with a letter.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -407,6 +448,12 @@ func resourceMonitoringUptimeCheckConfigCreate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("checker_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(checkerTypeProp)) && (ok || !reflect.DeepEqual(v, checkerTypeProp)) {
obj["checkerType"] = checkerTypeProp
}
userLabelsProp, err := expandMonitoringUptimeCheckConfigUserLabels(d.Get("user_labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("user_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(userLabelsProp)) && (ok || !reflect.DeepEqual(v, userLabelsProp)) {
obj["userLabels"] = userLabelsProp
}
httpCheckProp, err := expandMonitoringUptimeCheckConfigHttpCheck(d.Get("http_check"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -576,6 +623,9 @@ func resourceMonitoringUptimeCheckConfigRead(d *schema.ResourceData, meta interf
if err := d.Set("checker_type", flattenMonitoringUptimeCheckConfigCheckerType(res["checkerType"], d, config)); err != nil {
return fmt.Errorf("Error reading UptimeCheckConfig: %s", err)
}
if err := d.Set("user_labels", flattenMonitoringUptimeCheckConfigUserLabels(res["userLabels"], d, config)); err != nil {
return fmt.Errorf("Error reading UptimeCheckConfig: %s", err)
}
if err := d.Set("http_check", flattenMonitoringUptimeCheckConfigHttpCheck(res["httpCheck"], d, config)); err != nil {
return fmt.Errorf("Error reading UptimeCheckConfig: %s", err)
}
Expand Down Expand Up @@ -641,6 +691,12 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("selected_regions"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, selectedRegionsProp)) {
obj["selectedRegions"] = selectedRegionsProp
}
userLabelsProp, err := expandMonitoringUptimeCheckConfigUserLabels(d.Get("user_labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("user_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, userLabelsProp)) {
obj["userLabels"] = userLabelsProp
}
httpCheckProp, err := expandMonitoringUptimeCheckConfigHttpCheck(d.Get("http_check"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -689,6 +745,10 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
updateMask = append(updateMask, "selectedRegions")
}

if d.HasChange("user_labels") {
updateMask = append(updateMask, "userLabels")
}

if d.HasChange("http_check") {
updateMask = append(updateMask, "httpCheck")
}
Expand Down Expand Up @@ -877,6 +937,10 @@ func flattenMonitoringUptimeCheckConfigCheckerType(v interface{}, d *schema.Reso
return v
}

func flattenMonitoringUptimeCheckConfigUserLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenMonitoringUptimeCheckConfigHttpCheck(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand All @@ -890,6 +954,8 @@ func flattenMonitoringUptimeCheckConfigHttpCheck(v interface{}, d *schema.Resour
flattenMonitoringUptimeCheckConfigHttpCheckRequestMethod(original["requestMethod"], d, config)
transformed["content_type"] =
flattenMonitoringUptimeCheckConfigHttpCheckContentType(original["contentType"], d, config)
transformed["custom_content_type"] =
flattenMonitoringUptimeCheckConfigHttpCheckCustomContentType(original["customContentType"], d, config)
transformed["auth_info"] =
flattenMonitoringUptimeCheckConfigHttpCheckAuthInfo(original["authInfo"], d, config)
transformed["port"] =
Expand All @@ -908,6 +974,8 @@ func flattenMonitoringUptimeCheckConfigHttpCheck(v interface{}, d *schema.Resour
flattenMonitoringUptimeCheckConfigHttpCheckBody(original["body"], d, config)
transformed["accepted_response_status_codes"] =
flattenMonitoringUptimeCheckConfigHttpCheckAcceptedResponseStatusCodes(original["acceptedResponseStatusCodes"], d, config)
transformed["ping_config"] =
flattenMonitoringUptimeCheckConfigHttpCheckPingConfig(original["pingConfig"], d, config)
return []interface{}{transformed}
}
func flattenMonitoringUptimeCheckConfigHttpCheckRequestMethod(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand All @@ -918,6 +986,10 @@ func flattenMonitoringUptimeCheckConfigHttpCheckContentType(v interface{}, d *sc
return v
}

func flattenMonitoringUptimeCheckConfigHttpCheckCustomContentType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1022,6 +1094,36 @@ func flattenMonitoringUptimeCheckConfigHttpCheckAcceptedResponseStatusCodesStatu
return v
}

func flattenMonitoringUptimeCheckConfigHttpCheckPingConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["pings_count"] =
flattenMonitoringUptimeCheckConfigHttpCheckPingConfigPingsCount(original["pingsCount"], d, config)
return []interface{}{transformed}
}
func flattenMonitoringUptimeCheckConfigHttpCheckPingConfigPingsCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenMonitoringUptimeCheckConfigTcpCheck(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand All @@ -1033,6 +1135,8 @@ func flattenMonitoringUptimeCheckConfigTcpCheck(v interface{}, d *schema.Resourc
transformed := make(map[string]interface{})
transformed["port"] =
flattenMonitoringUptimeCheckConfigTcpCheckPort(original["port"], d, config)
transformed["ping_config"] =
flattenMonitoringUptimeCheckConfigTcpCheckPingConfig(original["pingConfig"], d, config)
return []interface{}{transformed}
}
func flattenMonitoringUptimeCheckConfigTcpCheckPort(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand All @@ -1052,6 +1156,36 @@ func flattenMonitoringUptimeCheckConfigTcpCheckPort(v interface{}, d *schema.Res
return v // let terraform core handle it otherwise
}

func flattenMonitoringUptimeCheckConfigTcpCheckPingConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["pings_count"] =
flattenMonitoringUptimeCheckConfigTcpCheckPingConfigPingsCount(original["pingsCount"], d, config)
return []interface{}{transformed}
}
func flattenMonitoringUptimeCheckConfigTcpCheckPingConfigPingsCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenMonitoringUptimeCheckConfigResourceGroup(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1227,6 +1361,17 @@ func expandMonitoringUptimeCheckConfigCheckerType(v interface{}, d tpgresource.T
return v, nil
}

func expandMonitoringUptimeCheckConfigUserLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandMonitoringUptimeCheckConfigHttpCheck(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand All @@ -1250,6 +1395,13 @@ func expandMonitoringUptimeCheckConfigHttpCheck(v interface{}, d tpgresource.Ter
transformed["contentType"] = transformedContentType
}

transformedCustomContentType, err := expandMonitoringUptimeCheckConfigHttpCheckCustomContentType(original["custom_content_type"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedCustomContentType); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["customContentType"] = transformedCustomContentType
}

transformedAuthInfo, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfo(original["auth_info"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1313,6 +1465,13 @@ func expandMonitoringUptimeCheckConfigHttpCheck(v interface{}, d tpgresource.Ter
transformed["acceptedResponseStatusCodes"] = transformedAcceptedResponseStatusCodes
}

transformedPingConfig, err := expandMonitoringUptimeCheckConfigHttpCheckPingConfig(original["ping_config"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPingConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["pingConfig"] = transformedPingConfig
}

return transformed, nil
}

Expand All @@ -1324,6 +1483,10 @@ func expandMonitoringUptimeCheckConfigHttpCheckContentType(v interface{}, d tpgr
return v, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckCustomContentType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -1430,6 +1593,29 @@ func expandMonitoringUptimeCheckConfigHttpCheckAcceptedResponseStatusCodesStatus
return v, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckPingConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedPingsCount, err := expandMonitoringUptimeCheckConfigHttpCheckPingConfigPingsCount(original["pings_count"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPingsCount); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["pingsCount"] = transformedPingsCount
}

return transformed, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckPingConfigPingsCount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigTcpCheck(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand All @@ -1446,13 +1632,43 @@ func expandMonitoringUptimeCheckConfigTcpCheck(v interface{}, d tpgresource.Terr
transformed["port"] = transformedPort
}

transformedPingConfig, err := expandMonitoringUptimeCheckConfigTcpCheckPingConfig(original["ping_config"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPingConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["pingConfig"] = transformedPingConfig
}

return transformed, nil
}

func expandMonitoringUptimeCheckConfigTcpCheckPort(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigTcpCheckPingConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedPingsCount, err := expandMonitoringUptimeCheckConfigTcpCheckPingConfigPingsCount(original["pings_count"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPingsCount); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["pingsCount"] = transformedPingsCount
}

return transformed, nil
}

func expandMonitoringUptimeCheckConfigTcpCheckPingConfigPingsCount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigResourceGroup(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down