From f2dd796f8c4876220ac6430616023cf5b1aa631e Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Thu, 22 Nov 2018 00:14:46 +0000 Subject: [PATCH] New Resource: Stackdriver uptime check --- google/provider_monitoring_gen.go | 1 + ...resource_monitoring_uptime_check_config.go | 1057 +++++++++++++++++ ...ring_uptime_check_config_generated_test.go | 138 +++ ...rce_monitoring_uptime_check_config_test.go | 71 ++ ...nitoring_uptime_check_config.html.markdown | 257 ++++ 5 files changed, 1524 insertions(+) create mode 100644 google/resource_monitoring_uptime_check_config.go create mode 100644 google/resource_monitoring_uptime_check_config_generated_test.go create mode 100644 google/resource_monitoring_uptime_check_config_test.go create mode 100644 website/docs/r/monitoring_uptime_check_config.html.markdown diff --git a/google/provider_monitoring_gen.go b/google/provider_monitoring_gen.go index 959f0b4c..25a1319d 100644 --- a/google/provider_monitoring_gen.go +++ b/google/provider_monitoring_gen.go @@ -20,4 +20,5 @@ var GeneratedMonitoringResourcesMap = map[string]*schema.Resource{ "google_monitoring_alert_policy": resourceMonitoringAlertPolicy(), "google_monitoring_group": resourceMonitoringGroup(), "google_monitoring_notification_channel": resourceMonitoringNotificationChannel(), + "google_monitoring_uptime_check_config": resourceMonitoringUptimeCheckConfig(), } diff --git a/google/resource_monitoring_uptime_check_config.go b/google/resource_monitoring_uptime_check_config.go new file mode 100644 index 00000000..e533dd73 --- /dev/null +++ b/google/resource_monitoring_uptime_check_config.go @@ -0,0 +1,1057 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "strconv" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" +) + +func resourceMonitoringUptimeCheckConfig() *schema.Resource { + return &schema.Resource{ + Create: resourceMonitoringUptimeCheckConfigCreate, + Read: resourceMonitoringUptimeCheckConfigRead, + Update: resourceMonitoringUptimeCheckConfigUpdate, + Delete: resourceMonitoringUptimeCheckConfigDelete, + + Importer: &schema.ResourceImporter{ + State: resourceMonitoringUptimeCheckConfigImport, + }, + + Schema: map[string]*schema.Schema{ + "display_name": { + Type: schema.TypeString, + Required: true, + }, + "timeout": { + Type: schema.TypeString, + Required: true, + }, + "content_matchers": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "content": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "http_check": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "auth_info": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "password": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + }, + "username": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "headers": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "mask_headers": { + Type: schema.TypeBool, + Optional: true, + }, + "path": { + Type: schema.TypeString, + Optional: true, + Default: "/", + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Default: 80, + }, + "use_ssl": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, + ConflictsWith: []string{"tcp_check"}, + }, + "internal_checkers": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "display_name": { + Type: schema.TypeString, + Optional: true, + }, + "gcp_zone": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "network": { + Type: schema.TypeString, + Optional: true, + }, + "peer_project_id": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "is_internal": { + Type: schema.TypeBool, + Optional: true, + }, + "monitored_resource": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "labels": { + Type: schema.TypeMap, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "type": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + ConflictsWith: []string{"resource_group"}, + }, + "period": { + Type: schema.TypeString, + Optional: true, + Default: "300s", + }, + "resource_group": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "group_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "resource_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"RESOURCE_TYPE_UNSPECIFIED", "INSTANCE", "AWS_ELB_LOAD_BALANCER", ""}, false), + }, + }, + }, + ConflictsWith: []string{"monitored_resource"}, + }, + "selected_regions": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "tcp_check": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "port": { + Type: schema.TypeInt, + Required: true, + }, + }, + }, + ConflictsWith: []string{"http_check"}, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceMonitoringUptimeCheckConfigCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + displayNameProp, err := expandMonitoringUptimeCheckConfigDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + periodProp, err := expandMonitoringUptimeCheckConfigPeriod(d.Get("period"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("period"); !isEmptyValue(reflect.ValueOf(periodProp)) && (ok || !reflect.DeepEqual(v, periodProp)) { + obj["period"] = periodProp + } + timeoutProp, err := expandMonitoringUptimeCheckConfigTimeout(d.Get("timeout"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("timeout"); !isEmptyValue(reflect.ValueOf(timeoutProp)) && (ok || !reflect.DeepEqual(v, timeoutProp)) { + obj["timeout"] = timeoutProp + } + contentMatchersProp, err := expandMonitoringUptimeCheckConfigContentMatchers(d.Get("content_matchers"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("content_matchers"); !isEmptyValue(reflect.ValueOf(contentMatchersProp)) && (ok || !reflect.DeepEqual(v, contentMatchersProp)) { + obj["contentMatchers"] = contentMatchersProp + } + selectedRegionsProp, err := expandMonitoringUptimeCheckConfigSelectedRegions(d.Get("selected_regions"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("selected_regions"); !isEmptyValue(reflect.ValueOf(selectedRegionsProp)) && (ok || !reflect.DeepEqual(v, selectedRegionsProp)) { + obj["selectedRegions"] = selectedRegionsProp + } + isInternalProp, err := expandMonitoringUptimeCheckConfigIsInternal(d.Get("is_internal"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("is_internal"); !isEmptyValue(reflect.ValueOf(isInternalProp)) && (ok || !reflect.DeepEqual(v, isInternalProp)) { + obj["isInternal"] = isInternalProp + } + internalCheckersProp, err := expandMonitoringUptimeCheckConfigInternalCheckers(d.Get("internal_checkers"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("internal_checkers"); !isEmptyValue(reflect.ValueOf(internalCheckersProp)) && (ok || !reflect.DeepEqual(v, internalCheckersProp)) { + obj["internalCheckers"] = internalCheckersProp + } + httpCheckProp, err := expandMonitoringUptimeCheckConfigHttpCheck(d.Get("http_check"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("http_check"); !isEmptyValue(reflect.ValueOf(httpCheckProp)) && (ok || !reflect.DeepEqual(v, httpCheckProp)) { + obj["httpCheck"] = httpCheckProp + } + tcpCheckProp, err := expandMonitoringUptimeCheckConfigTcpCheck(d.Get("tcp_check"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("tcp_check"); !isEmptyValue(reflect.ValueOf(tcpCheckProp)) && (ok || !reflect.DeepEqual(v, tcpCheckProp)) { + obj["tcpCheck"] = tcpCheckProp + } + resourceGroupProp, err := expandMonitoringUptimeCheckConfigResourceGroup(d.Get("resource_group"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("resource_group"); !isEmptyValue(reflect.ValueOf(resourceGroupProp)) && (ok || !reflect.DeepEqual(v, resourceGroupProp)) { + obj["resourceGroup"] = resourceGroupProp + } + monitoredResourceProp, err := expandMonitoringUptimeCheckConfigMonitoredResource(d.Get("monitored_resource"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("monitored_resource"); !isEmptyValue(reflect.ValueOf(monitoredResourceProp)) && (ok || !reflect.DeepEqual(v, monitoredResourceProp)) { + obj["monitoredResource"] = monitoredResourceProp + } + + url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/projects/{{project}}/uptimeCheckConfigs") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new UptimeCheckConfig: %#v", obj) + res, err := sendRequest(config, "POST", url, obj) + if err != nil { + return fmt.Errorf("Error creating UptimeCheckConfig: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating UptimeCheckConfig %q: %#v", d.Id(), res) + + // `name` is autogenerated from the api so needs to be set post-create + name, ok := res["name"] + if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") + } + d.Set("name", name.(string)) + d.SetId(name.(string)) + + return resourceMonitoringUptimeCheckConfigRead(d, meta) +} + +func resourceMonitoringUptimeCheckConfigRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/{{name}}") + if err != nil { + return err + } + + res, err := sendRequest(config, "GET", url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("MonitoringUptimeCheckConfig %q", d.Id())) + } + + project, err := getProject(d, config) + if err != nil { + return err + } + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + + if err := d.Set("name", flattenMonitoringUptimeCheckConfigName(res["name"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("display_name", flattenMonitoringUptimeCheckConfigDisplayName(res["displayName"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("period", flattenMonitoringUptimeCheckConfigPeriod(res["period"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("timeout", flattenMonitoringUptimeCheckConfigTimeout(res["timeout"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("content_matchers", flattenMonitoringUptimeCheckConfigContentMatchers(res["contentMatchers"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("selected_regions", flattenMonitoringUptimeCheckConfigSelectedRegions(res["selectedRegions"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("is_internal", flattenMonitoringUptimeCheckConfigIsInternal(res["isInternal"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("internal_checkers", flattenMonitoringUptimeCheckConfigInternalCheckers(res["internalCheckers"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("http_check", flattenMonitoringUptimeCheckConfigHttpCheck(res["httpCheck"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("tcp_check", flattenMonitoringUptimeCheckConfigTcpCheck(res["tcpCheck"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("resource_group", flattenMonitoringUptimeCheckConfigResourceGroup(res["resourceGroup"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + if err := d.Set("monitored_resource", flattenMonitoringUptimeCheckConfigMonitoredResource(res["monitoredResource"], d)); err != nil { + return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) + } + + return nil +} + +func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + displayNameProp, err := expandMonitoringUptimeCheckConfigDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + periodProp, err := expandMonitoringUptimeCheckConfigPeriod(d.Get("period"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("period"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, periodProp)) { + obj["period"] = periodProp + } + timeoutProp, err := expandMonitoringUptimeCheckConfigTimeout(d.Get("timeout"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("timeout"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, timeoutProp)) { + obj["timeout"] = timeoutProp + } + contentMatchersProp, err := expandMonitoringUptimeCheckConfigContentMatchers(d.Get("content_matchers"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("content_matchers"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, contentMatchersProp)) { + obj["contentMatchers"] = contentMatchersProp + } + selectedRegionsProp, err := expandMonitoringUptimeCheckConfigSelectedRegions(d.Get("selected_regions"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("selected_regions"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, selectedRegionsProp)) { + obj["selectedRegions"] = selectedRegionsProp + } + isInternalProp, err := expandMonitoringUptimeCheckConfigIsInternal(d.Get("is_internal"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("is_internal"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, isInternalProp)) { + obj["isInternal"] = isInternalProp + } + internalCheckersProp, err := expandMonitoringUptimeCheckConfigInternalCheckers(d.Get("internal_checkers"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("internal_checkers"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, internalCheckersProp)) { + obj["internalCheckers"] = internalCheckersProp + } + httpCheckProp, err := expandMonitoringUptimeCheckConfigHttpCheck(d.Get("http_check"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("http_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, httpCheckProp)) { + obj["httpCheck"] = httpCheckProp + } + tcpCheckProp, err := expandMonitoringUptimeCheckConfigTcpCheck(d.Get("tcp_check"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("tcp_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tcpCheckProp)) { + obj["tcpCheck"] = tcpCheckProp + } + resourceGroupProp, err := expandMonitoringUptimeCheckConfigResourceGroup(d.Get("resource_group"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("resource_group"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, resourceGroupProp)) { + obj["resourceGroup"] = resourceGroupProp + } + monitoredResourceProp, err := expandMonitoringUptimeCheckConfigMonitoredResource(d.Get("monitored_resource"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("monitored_resource"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, monitoredResourceProp)) { + obj["monitoredResource"] = monitoredResourceProp + } + + url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating UptimeCheckConfig %q: %#v", d.Id(), obj) + _, err = sendRequest(config, "PATCH", url, obj) + + if err != nil { + return fmt.Errorf("Error updating UptimeCheckConfig %q: %s", d.Id(), err) + } + + return resourceMonitoringUptimeCheckConfigRead(d, meta) +} + +func resourceMonitoringUptimeCheckConfigDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting UptimeCheckConfig %q", d.Id()) + res, err := sendRequest(config, "DELETE", url, obj) + if err != nil { + return handleNotFoundError(err, d, "UptimeCheckConfig") + } + + log.Printf("[DEBUG] Finished deleting UptimeCheckConfig %q: %#v", d.Id(), res) + return nil +} + +func resourceMonitoringUptimeCheckConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + + config := meta.(*Config) + + // current import_formats can't import id's with forward slashes in them. + parseImportId([]string{"(?P.+)"}, d, config) + + return []*schema.ResourceData{d}, nil +} + +func flattenMonitoringUptimeCheckConfigName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigDisplayName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigPeriod(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigTimeout(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigContentMatchers(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "content": flattenMonitoringUptimeCheckConfigContentMatchersContent(original["content"], d), + }) + } + return transformed +} +func flattenMonitoringUptimeCheckConfigContentMatchersContent(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigSelectedRegions(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigIsInternal(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigInternalCheckers(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "gcp_zone": flattenMonitoringUptimeCheckConfigInternalCheckersGcpZone(original["gcpZone"], d), + "peer_project_id": flattenMonitoringUptimeCheckConfigInternalCheckersPeerProjectId(original["peerProjectId"], d), + "name": flattenMonitoringUptimeCheckConfigInternalCheckersName(original["name"], d), + "network": flattenMonitoringUptimeCheckConfigInternalCheckersNetwork(original["network"], d), + "display_name": flattenMonitoringUptimeCheckConfigInternalCheckersDisplayName(original["displayName"], d), + }) + } + return transformed +} +func flattenMonitoringUptimeCheckConfigInternalCheckersGcpZone(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigInternalCheckersPeerProjectId(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigInternalCheckersName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigInternalCheckersNetwork(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigInternalCheckersDisplayName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigHttpCheck(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["auth_info"] = + flattenMonitoringUptimeCheckConfigHttpCheckAuthInfo(original["authInfo"], d) + transformed["port"] = + flattenMonitoringUptimeCheckConfigHttpCheckPort(original["port"], d) + transformed["headers"] = + flattenMonitoringUptimeCheckConfigHttpCheckHeaders(original["headers"], d) + transformed["path"] = + flattenMonitoringUptimeCheckConfigHttpCheckPath(original["path"], d) + transformed["use_ssl"] = + flattenMonitoringUptimeCheckConfigHttpCheckUseSsl(original["useSsl"], d) + transformed["mask_headers"] = + flattenMonitoringUptimeCheckConfigHttpCheckMaskHeaders(original["maskHeaders"], d) + return []interface{}{transformed} +} +func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["password"] = + flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoPassword(original["password"], d) + transformed["username"] = + flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(original["username"], d) + return []interface{}{transformed} +} +func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoPassword(v interface{}, d *schema.ResourceData) interface{} { + return d.Get("http_check.0.auth_info.0.password") +} + +func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigHttpCheckPort(v interface{}, d *schema.ResourceData) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil { + return intVal + } // let terraform core handle it if we can't convert the string to an int. + } + return v +} + +func flattenMonitoringUptimeCheckConfigHttpCheckHeaders(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigHttpCheckPath(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigHttpCheckUseSsl(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigHttpCheckMaskHeaders(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigTcpCheck(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["port"] = + flattenMonitoringUptimeCheckConfigTcpCheckPort(original["port"], d) + return []interface{}{transformed} +} +func flattenMonitoringUptimeCheckConfigTcpCheckPort(v interface{}, d *schema.ResourceData) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil { + return intVal + } // let terraform core handle it if we can't convert the string to an int. + } + return v +} + +func flattenMonitoringUptimeCheckConfigResourceGroup(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["resource_type"] = + flattenMonitoringUptimeCheckConfigResourceGroupResourceType(original["resourceType"], d) + transformed["group_id"] = + flattenMonitoringUptimeCheckConfigResourceGroupGroupId(original["groupId"], d) + return []interface{}{transformed} +} +func flattenMonitoringUptimeCheckConfigResourceGroupResourceType(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigResourceGroupGroupId(v interface{}, d *schema.ResourceData) interface{} { + project := d.Get("project").(string) + return fmt.Sprintf("projects/%s/groups/%s", project, v) +} + +func flattenMonitoringUptimeCheckConfigMonitoredResource(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["type"] = + flattenMonitoringUptimeCheckConfigMonitoredResourceType(original["type"], d) + transformed["labels"] = + flattenMonitoringUptimeCheckConfigMonitoredResourceLabels(original["labels"], d) + return []interface{}{transformed} +} +func flattenMonitoringUptimeCheckConfigMonitoredResourceType(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenMonitoringUptimeCheckConfigMonitoredResourceLabels(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func expandMonitoringUptimeCheckConfigDisplayName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigPeriod(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigTimeout(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigContentMatchers(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedContent, err := expandMonitoringUptimeCheckConfigContentMatchersContent(original["content"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedContent); val.IsValid() && !isEmptyValue(val) { + transformed["content"] = transformedContent + } + + req = append(req, transformed) + } + return req, nil +} + +func expandMonitoringUptimeCheckConfigContentMatchersContent(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigSelectedRegions(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigIsInternal(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigInternalCheckers(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedGcpZone, err := expandMonitoringUptimeCheckConfigInternalCheckersGcpZone(original["gcp_zone"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedGcpZone); val.IsValid() && !isEmptyValue(val) { + transformed["gcpZone"] = transformedGcpZone + } + + transformedPeerProjectId, err := expandMonitoringUptimeCheckConfigInternalCheckersPeerProjectId(original["peer_project_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPeerProjectId); val.IsValid() && !isEmptyValue(val) { + transformed["peerProjectId"] = transformedPeerProjectId + } + + transformedName, err := expandMonitoringUptimeCheckConfigInternalCheckersName(original["name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) { + transformed["name"] = transformedName + } + + transformedNetwork, err := expandMonitoringUptimeCheckConfigInternalCheckersNetwork(original["network"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedNetwork); val.IsValid() && !isEmptyValue(val) { + transformed["network"] = transformedNetwork + } + + transformedDisplayName, err := expandMonitoringUptimeCheckConfigInternalCheckersDisplayName(original["display_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !isEmptyValue(val) { + transformed["displayName"] = transformedDisplayName + } + + req = append(req, transformed) + } + return req, nil +} + +func expandMonitoringUptimeCheckConfigInternalCheckersGcpZone(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigInternalCheckersPeerProjectId(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigInternalCheckersName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigInternalCheckersNetwork(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigInternalCheckersDisplayName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheck(v interface{}, d *schema.ResourceData, config *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{}) + + transformedAuthInfo, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfo(original["auth_info"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAuthInfo); val.IsValid() && !isEmptyValue(val) { + transformed["authInfo"] = transformedAuthInfo + } + + transformedPort, err := expandMonitoringUptimeCheckConfigHttpCheckPort(original["port"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) { + transformed["port"] = transformedPort + } + + transformedHeaders, err := expandMonitoringUptimeCheckConfigHttpCheckHeaders(original["headers"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHeaders); val.IsValid() && !isEmptyValue(val) { + transformed["headers"] = transformedHeaders + } + + transformedPath, err := expandMonitoringUptimeCheckConfigHttpCheckPath(original["path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPath); val.IsValid() && !isEmptyValue(val) { + transformed["path"] = transformedPath + } + + transformedUseSsl, err := expandMonitoringUptimeCheckConfigHttpCheckUseSsl(original["use_ssl"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUseSsl); val.IsValid() && !isEmptyValue(val) { + transformed["useSsl"] = transformedUseSsl + } + + transformedMaskHeaders, err := expandMonitoringUptimeCheckConfigHttpCheckMaskHeaders(original["mask_headers"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedMaskHeaders); val.IsValid() && !isEmptyValue(val) { + transformed["maskHeaders"] = transformedMaskHeaders + } + + return transformed, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d *schema.ResourceData, config *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{}) + + transformedPassword, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfoPassword(original["password"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPassword); val.IsValid() && !isEmptyValue(val) { + transformed["password"] = transformedPassword + } + + transformedUsername, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(original["username"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUsername); val.IsValid() && !isEmptyValue(val) { + transformed["username"] = transformedUsername + } + + return transformed, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheckAuthInfoPassword(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheckAuthInfoUsername(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheckPort(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheckHeaders(v interface{}, d *schema.ResourceData, config *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 expandMonitoringUptimeCheckConfigHttpCheckPath(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheckUseSsl(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigHttpCheckMaskHeaders(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigTcpCheck(v interface{}, d *schema.ResourceData, config *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{}) + + transformedPort, err := expandMonitoringUptimeCheckConfigTcpCheckPort(original["port"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) { + transformed["port"] = transformedPort + } + + return transformed, nil +} + +func expandMonitoringUptimeCheckConfigTcpCheckPort(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigResourceGroup(v interface{}, d *schema.ResourceData, config *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{}) + + transformedResourceType, err := expandMonitoringUptimeCheckConfigResourceGroupResourceType(original["resource_type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedResourceType); val.IsValid() && !isEmptyValue(val) { + transformed["resourceType"] = transformedResourceType + } + + transformedGroupId, err := expandMonitoringUptimeCheckConfigResourceGroupGroupId(original["group_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedGroupId); val.IsValid() && !isEmptyValue(val) { + transformed["groupId"] = transformedGroupId + } + + return transformed, nil +} + +func expandMonitoringUptimeCheckConfigResourceGroupResourceType(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigResourceGroupGroupId(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return GetResourceNameFromSelfLink(v.(string)), nil +} + +func expandMonitoringUptimeCheckConfigMonitoredResource(v interface{}, d *schema.ResourceData, config *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{}) + + transformedType, err := expandMonitoringUptimeCheckConfigMonitoredResourceType(original["type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedType); val.IsValid() && !isEmptyValue(val) { + transformed["type"] = transformedType + } + + transformedLabels, err := expandMonitoringUptimeCheckConfigMonitoredResourceLabels(original["labels"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedLabels); val.IsValid() && !isEmptyValue(val) { + transformed["labels"] = transformedLabels + } + + return transformed, nil +} + +func expandMonitoringUptimeCheckConfigMonitoredResourceType(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandMonitoringUptimeCheckConfigMonitoredResourceLabels(v interface{}, d *schema.ResourceData, config *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 +} diff --git a/google/resource_monitoring_uptime_check_config_generated_test.go b/google/resource_monitoring_uptime_check_config_generated_test.go new file mode 100644 index 00000000..1a991b9a --- /dev/null +++ b/google/resource_monitoring_uptime_check_config_generated_test.go @@ -0,0 +1,138 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(acctest.RandString(10)), + }, + { + ResourceName: "google_monitoring_uptime_check_config.http", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(val string) string { + return fmt.Sprintf(` +resource "google_monitoring_uptime_check_config" "http" { + display_name = "http-uptime-check-%s" + timeout = "60s" + + http_check = { + path = "/some-path" + port = "8010" + } + + monitored_resource { + type = "uptime_url" + labels = { + project_id = "example" + host = "192.168.1.1" + } + } + + content_matchers = { + content = "example" + } +} +`, val, + ) +} + +func TestAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(acctest.RandString(10)), + }, + { + ResourceName: "google_monitoring_uptime_check_config.tcp_group", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(val string) string { + return fmt.Sprintf(` +resource "google_monitoring_uptime_check_config" "tcp_group" { + display_name = "tcp-uptime-check-%s" + timeout = "60s" + + tcp_check = { + port = 888 + } + + resource_group { + resource_type = "INSTANCE" + group_id = "${google_monitoring_group.check.name}" + } +} + + +resource "google_monitoring_group" "check" { + display_name = "uptime-check-group-%s" + filter = "resource.metadata.name=has_substring(\"foo\")" +} +`, val, val, + ) +} + +func testAccCheckMonitoringUptimeCheckConfigDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "google_monitoring_uptime_check_config" { + continue + } + + config := testAccProvider.Meta().(*Config) + + url, err := replaceVarsForTest(rs, "https://monitoring.googleapis.com/v3/{{name}}") + if err != nil { + return err + } + + _, err = sendRequest(config, "GET", url, nil) + if err == nil { + return fmt.Errorf("MonitoringUptimeCheckConfig still exists at %s", url) + } + } + + return nil +} diff --git a/google/resource_monitoring_uptime_check_config_test.go b/google/resource_monitoring_uptime_check_config_test.go new file mode 100644 index 00000000..c58171c5 --- /dev/null +++ b/google/resource_monitoring_uptime_check_config_test.go @@ -0,0 +1,71 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) { + t.Parallel() + project := getTestProjectFromEnv() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMonitoringUptimeCheckConfig_update("mypath", "password1", project), + }, + { + ResourceName: "google_monitoring_uptime_check_config.http", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"}, + }, + { + Config: testAccMonitoringUptimeCheckConfig_update("", "password2", project), + }, + { + ResourceName: "google_monitoring_uptime_check_config.http", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"}, + }, + }, + }) +} + +func testAccMonitoringUptimeCheckConfig_update(path, project, pwd string) string { + return fmt.Sprintf(` +resource "google_monitoring_uptime_check_config" "http" { + display_name = "http-uptime-check-%s" + timeout = "60s" + + http_check = { + path = "/%s" + port = "8010" + auth_info = { + username = "name" + password = "%s" + } + } + + monitored_resource { + type = "uptime_url" + labels = { + project_id = "%s" + host = "192.168.1.1" + } + } + + content_matchers = { + content = "example" + } +} +`, acctest.RandString(4), path, project, pwd, + ) +} diff --git a/website/docs/r/monitoring_uptime_check_config.html.markdown b/website/docs/r/monitoring_uptime_check_config.html.markdown new file mode 100644 index 00000000..07ba6842 --- /dev/null +++ b/website/docs/r/monitoring_uptime_check_config.html.markdown @@ -0,0 +1,257 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +layout: "google" +page_title: "Google: google_monitoring_uptime_check_config" +sidebar_current: "docs-google-monitoring-uptime-check-config" +description: |- + This message configures which resources and services to monitor for availability. +--- + +# google\_monitoring\_uptime\_check\_config + +This message configures which resources and services to monitor for availability. + + +To get more information about UptimeCheckConfig, see: + +* [API documentation](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs) +* How-to Guides + * [Official Documentation](https://cloud.google.com/monitoring/api/v3/) + + +## Example Usage - Uptime Check Config Http + + +```hcl +resource "google_monitoring_uptime_check_config" "http" { + display_name = "http-uptime-check" + timeout = "60s" + + http_check = { + path = "/some-path" + port = "8010" + } + + monitored_resource { + type = "uptime_url" + labels = { + project_id = "example" + host = "192.168.1.1" + } + } + + content_matchers = { + content = "example" + } +} +``` + +## Example Usage - Uptime Check Tcp + + +```hcl +resource "google_monitoring_uptime_check_config" "tcp_group" { + display_name = "tcp-uptime-check" + timeout = "60s" + + tcp_check = { + port = 888 + } + + resource_group { + resource_type = "INSTANCE" + group_id = "${google_monitoring_group.check.name}" + } +} + + +resource "google_monitoring_group" "check" { + display_name = "uptime-check-group" + filter = "resource.metadata.name=has_substring(\"foo\")" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `display_name` - + (Required) + A human-friendly name for the uptime check configuration. The display name should be unique within a Stackdriver Workspace in order to make it easier to identify; however, uniqueness is not enforced. + +* `timeout` - + (Required) + The maximum amount of time to wait for the request to complete (must be between 1 and 60 seconds). Accepted formats https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Duration + + +- - - + + +* `period` - + (Optional) + How often, in seconds, the uptime check is performed. Currently, the only supported values are 60s (1 minute), 300s (5 minutes), 600s (10 minutes), and 900s (15 minutes). Optional, defaults to 300s. + +* `content_matchers` - + (Optional) + The expected content on the page the check is run against. Currently, only the first entry in the list is supported, and other entries will be ignored. The server will look for an exact match of the string in the page response's content. This field is optional and should only be specified if a content match is required. Structure is documented below. + +* `selected_regions` - + (Optional) + The list of regions from which the check will be run. Some regions contain one location, and others contain more than one. If this field is specified, enough regions to include a minimum of 3 locations must be provided, or an error message is returned. Not specifying this field will result in uptime checks running from all regions. + +* `is_internal` - + (Optional) + If this is true, then checks are made only from the 'internal_checkers'. If it is false, then checks are made only from the 'selected_regions'. It is an error to provide 'selected_regions' when is_internal is true, or to provide 'internal_checkers' when is_internal is false. + +* `internal_checkers` - + (Optional) + The internal checkers that this check will egress from. If is_internal is true and this list is empty, the check will egress from all the InternalCheckers configured for the project that owns this CheckConfig. Structure is documented below. + +* `http_check` - + (Optional) + Contains information needed to make an HTTP or HTTPS check. Structure is documented below. + +* `tcp_check` - + (Optional) + Contains information needed to make a TCP check. Structure is documented below. + +* `resource_group` - + (Optional) + The group resource associated with the configuration. Structure is documented below. + +* `monitored_resource` - + (Optional) + The monitored resource (https://cloud.google.com/monitoring/api/resources) associated with the configuration. The following monitored resource types are supported for uptime checks: uptime_url gce_instance gae_app aws_ec2_instance aws_elb_load_balancer Structure is documented below. +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +The `content_matchers` block supports: + +* `content` - + (Optional) + String or regex content to match (max 1024 bytes) + +The `internal_checkers` block supports: + +* `gcp_zone` - + (Optional) + The GCP zone the uptime check should egress from. Only respected for internal uptime checks, where internal_network is specified. + +* `peer_project_id` - + (Optional) + The GCP project_id where the internal checker lives. Not necessary the same as the workspace project. + +* `name` - + (Optional) + A unique resource name for this InternalChecker. The format is:projects/[PROJECT_ID]/internalCheckers/[INTERNAL_CHECKER_ID].PROJECT_ID is the stackdriver workspace project for the uptime check config associated with the internal checker. + +* `network` - + (Optional) + The GCP VPC network (https://cloud.google.com/vpc/docs/vpc) where the internal resource lives (ex: "default"). + +* `display_name` - + (Optional) + The checker's human-readable name. The display name should be unique within a Stackdriver Workspace in order to make it easier to identify; however, uniqueness is not enforced. + +The `http_check` block supports: + +* `auth_info` - + (Optional) + The authentication information. Optional when creating an HTTP check; defaults to empty. Structure is documented below. + +* `port` - + (Optional) + The port to the page to run the check against. Will be combined with host (specified within the MonitoredResource) and path to construct the full URL. Optional (defaults to 80 without SSL, or 443 with SSL). + +* `headers` - + (Optional) + The list of headers to send as part of the uptime check request. If two headers have the same key and different values, they should be entered as a single header, with the value being a comma-separated list of all the desired values as described at https://www.w3.org/Protocols/rfc2616/rfc2616.txt (page 31). Entering two separate headers with the same key in a Create call will cause the first to be overwritten by the second. The maximum number of headers allowed is 100. + +* `path` - + (Optional) + The path to the page to run the check against. Will be combined with the host (specified within the MonitoredResource) and port to construct the full URL. Optional (defaults to "/"). + +* `use_ssl` - + (Optional) + If true, use HTTPS instead of HTTP to run the check. + +* `mask_headers` - + (Optional) + Boolean specifiying whether to encrypt the header information. Encryption should be specified for any headers related to authentication that you do not wish to be seen when retrieving the configuration. The server will be responsible for encrypting the headers. On Get/List calls, if mask_headers is set to True then the headers will be obscured with ******. + + +The `auth_info` block supports: + +* `password` - + (Optional) + The password to authenticate. + +* `username` - + (Optional) + The username to authenticate. + +The `tcp_check` block supports: + +* `port` - + (Required) + The port to the page to run the check against. Will be combined with host (specified within the MonitoredResource) to construct the full URL. + +The `resource_group` block supports: + +* `resource_type` - + (Optional) + The resource type of the group members. + +* `group_id` - + (Optional) + The group of resources being monitored. Should be the `name` of a group + +The `monitored_resource` block supports: + +* `type` - + (Required) + The monitored resource type. This field must match the type field of a MonitoredResourceDescriptor (https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.monitoredResourceDescriptors#MonitoredResourceDescriptor) object. For example, the type of a Compute Engine VM instance is gce_instance. For a list of types, see Monitoring resource types (https://cloud.google.com/monitoring/api/resources) and Logging resource types (https://cloud.google.com/logging/docs/api/v2/resource-list). + +* `labels` - + (Required) + Values for all of the labels listed in the associated monitored resource descriptor. For example, Compute Engine VM instances use the labels "project_id", "instance_id", and "zone". + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + + +* `name` - + A unique resource name for this UptimeCheckConfig. The format is:projects/[PROJECT_ID]/uptimeCheckConfigs/[UPTIME_CHECK_ID]. on create the resource name is assigned by the server and included in the response. + + + +## Import + +UptimeCheckConfig can be imported using any of these accepted formats: + +``` +$ terraform import google_monitoring_uptime_check_config.default {{name}} +```