Skip to content

Commit

Permalink
Remove internal fields from monitoring uptime check (hashicorp#888)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Jun 25, 2019
1 parent 92dbffa commit a348a61
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 220 deletions.
231 changes: 41 additions & 190 deletions google-beta/resource_monitoring_uptime_check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,6 @@ func resourceMonitoringUptimeCheckConfig() *schema.Resource {
},
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,
Expand Down Expand Up @@ -227,6 +195,47 @@ func resourceMonitoringUptimeCheckConfig() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"is_internal": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Deprecated: "This field never worked, and will be removed in 3.0.0.",
},
"internal_checkers": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Deprecated: "This field never worked, and will be removed in 3.0.0.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"display_name": {
Type: schema.TypeString,
Optional: true,
Deprecated: "This field never worked, and will be removed in 3.0.0.",
},
"gcp_zone": {
Type: schema.TypeString,
Optional: true,
Deprecated: "This field never worked, and will be removed in 3.0.0.",
},
"name": {
Type: schema.TypeString,
Optional: true,
Deprecated: "This field never worked, and will be removed in 3.0.0.",
},
"network": {
Type: schema.TypeString,
Optional: true,
Deprecated: "This field never worked, and will be removed in 3.0.0.",
},
"peer_project_id": {
Type: schema.TypeString,
Optional: true,
Deprecated: "This field never worked, and will be removed in 3.0.0.",
},
},
},
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -271,18 +280,6 @@ func resourceMonitoringUptimeCheckConfigCreate(d *schema.ResourceData, meta inte
} 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
Expand Down Expand Up @@ -381,12 +378,6 @@ func resourceMonitoringUptimeCheckConfigRead(d *schema.ResourceData, meta interf
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)
}
Expand Down Expand Up @@ -431,18 +422,6 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
} 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
Expand Down Expand Up @@ -480,14 +459,6 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
updateMask = append(updateMask, "selectedRegions")
}

if d.HasChange("is_internal") {
updateMask = append(updateMask, "isInternal")
}

if d.HasChange("internal_checkers") {
updateMask = append(updateMask, "internalCheckers")
}

if d.HasChange("http_check") {
updateMask = append(updateMask, "httpCheck")
}
Expand Down Expand Up @@ -588,52 +559,6 @@ func flattenMonitoringUptimeCheckConfigSelectedRegions(v interface{}, d *schema.
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
Expand Down Expand Up @@ -818,80 +743,6 @@ func expandMonitoringUptimeCheckConfigSelectedRegions(v interface{}, d Terraform
return v, nil
}

func expandMonitoringUptimeCheckConfigIsInternal(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigInternalCheckers(v interface{}, d TerraformResourceData, 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 TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigInternalCheckersPeerProjectId(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigInternalCheckersName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigInternalCheckersNetwork(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigInternalCheckersDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigHttpCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
30 changes: 0 additions & 30 deletions website/docs/r/monitoring_uptime_check_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ The following arguments are supported:
(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.
Expand All @@ -154,28 +146,6 @@ The `content_matchers` block supports:
(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` -
Expand Down

0 comments on commit a348a61

Please sign in to comment.