Skip to content

Commit b5122f4

Browse files
Promote source_regions field in google_compute_healthcheck to ga (#11374) (#19006)
[upstream:9ec8aa084b6d66b7c8fb25f1e4fc3007714e1605] Signed-off-by: Modular Magician <[email protected]>
1 parent 6a51f9a commit b5122f4

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

.changelog/11374.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `source_regions` field to `google_compute_healthcheck` resource (ga)
3+
```

google/services/compute/resource_compute_health_check.go

+49
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,32 @@ which means no health check logging will be done.`,
485485
},
486486
},
487487
},
488+
"source_regions": {
489+
Type: schema.TypeList,
490+
Optional: true,
491+
Description: `The list of cloud regions from which health checks are performed. If
492+
any regions are specified, then exactly 3 regions should be specified.
493+
The region names must be valid names of Google Cloud regions. This can
494+
only be set for global health check. If this list is non-empty, then
495+
there are restrictions on what other health check fields are supported
496+
and what other resources can use this health check:
497+
498+
* SSL, HTTP2, and GRPC protocols are not supported.
499+
500+
* The TCP request field is not supported.
501+
502+
* The proxyHeader field for HTTP, HTTPS, and TCP is not supported.
503+
504+
* The checkIntervalSec field must be at least 30.
505+
506+
* The health check cannot be used with BackendService nor with managed
507+
instance group auto-healing.`,
508+
MinItems: 3,
509+
MaxItems: 3,
510+
Elem: &schema.Schema{
511+
Type: schema.TypeString,
512+
},
513+
},
488514
"ssl_health_check": {
489515
Type: schema.TypeList,
490516
Optional: true,
@@ -707,6 +733,12 @@ func resourceComputeHealthCheckCreate(d *schema.ResourceData, meta interface{})
707733
} else if v, ok := d.GetOkExists("timeout_sec"); !tpgresource.IsEmptyValue(reflect.ValueOf(timeoutSecProp)) && (ok || !reflect.DeepEqual(v, timeoutSecProp)) {
708734
obj["timeoutSec"] = timeoutSecProp
709735
}
736+
sourceRegionsProp, err := expandComputeHealthCheckSourceRegions(d.Get("source_regions"), d, config)
737+
if err != nil {
738+
return err
739+
} else if v, ok := d.GetOkExists("source_regions"); !tpgresource.IsEmptyValue(reflect.ValueOf(sourceRegionsProp)) && (ok || !reflect.DeepEqual(v, sourceRegionsProp)) {
740+
obj["sourceRegions"] = sourceRegionsProp
741+
}
710742
unhealthyThresholdProp, err := expandComputeHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold"), d, config)
711743
if err != nil {
712744
return err
@@ -877,6 +909,9 @@ func resourceComputeHealthCheckRead(d *schema.ResourceData, meta interface{}) er
877909
if err := d.Set("timeout_sec", flattenComputeHealthCheckTimeoutSec(res["timeoutSec"], d, config)); err != nil {
878910
return fmt.Errorf("Error reading HealthCheck: %s", err)
879911
}
912+
if err := d.Set("source_regions", flattenComputeHealthCheckSourceRegions(res["sourceRegions"], d, config)); err != nil {
913+
return fmt.Errorf("Error reading HealthCheck: %s", err)
914+
}
880915
if err := d.Set("unhealthy_threshold", flattenComputeHealthCheckUnhealthyThreshold(res["unhealthyThreshold"], d, config)); err != nil {
881916
return fmt.Errorf("Error reading HealthCheck: %s", err)
882917
}
@@ -957,6 +992,12 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
957992
} else if v, ok := d.GetOkExists("timeout_sec"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, timeoutSecProp)) {
958993
obj["timeoutSec"] = timeoutSecProp
959994
}
995+
sourceRegionsProp, err := expandComputeHealthCheckSourceRegions(d.Get("source_regions"), d, config)
996+
if err != nil {
997+
return err
998+
} else if v, ok := d.GetOkExists("source_regions"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceRegionsProp)) {
999+
obj["sourceRegions"] = sourceRegionsProp
1000+
}
9601001
unhealthyThresholdProp, err := expandComputeHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold"), d, config)
9611002
if err != nil {
9621003
return err
@@ -1191,6 +1232,10 @@ func flattenComputeHealthCheckTimeoutSec(v interface{}, d *schema.ResourceData,
11911232
return v // let terraform core handle it otherwise
11921233
}
11931234

1235+
func flattenComputeHealthCheckSourceRegions(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1236+
return v
1237+
}
1238+
11941239
func flattenComputeHealthCheckUnhealthyThreshold(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11951240
// Handles the string fixed64 format
11961241
if strVal, ok := v.(string); ok {
@@ -1611,6 +1656,10 @@ func expandComputeHealthCheckTimeoutSec(v interface{}, d tpgresource.TerraformRe
16111656
return v, nil
16121657
}
16131658

1659+
func expandComputeHealthCheckSourceRegions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1660+
return v, nil
1661+
}
1662+
16141663
func expandComputeHealthCheckUnhealthyThreshold(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
16151664
return v, nil
16161665
}

google/services/compute/resource_compute_health_check_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,61 @@ resource "google_compute_health_check" "foobar" {
338338
}
339339
`, hckName)
340340
}
341+
342+
func TestAccComputeHealthCheck_srcRegions_update(t *testing.T) {
343+
t.Parallel()
344+
345+
hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
346+
347+
acctest.VcrTest(t, resource.TestCase{
348+
PreCheck: func() { acctest.AccTestPreCheck(t) },
349+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
350+
CheckDestroy: testAccCheckComputeHealthCheckDestroyProducer(t),
351+
Steps: []resource.TestStep{
352+
{
353+
Config: testAccComputeHealthCheck_srcRegions(hckName),
354+
},
355+
{
356+
ResourceName: "google_compute_health_check.src_region",
357+
ImportState: true,
358+
ImportStateVerify: true,
359+
},
360+
{
361+
Config: testAccComputeHealthCheck_srcRegions_update(hckName),
362+
},
363+
{
364+
ResourceName: "google_compute_health_check.src_region",
365+
ImportState: true,
366+
ImportStateVerify: true,
367+
},
368+
},
369+
})
370+
}
371+
372+
func testAccComputeHealthCheck_srcRegions(hckName string) string {
373+
return fmt.Sprintf(`
374+
resource "google_compute_health_check" "src_region" {
375+
name = "%s"
376+
description = "Resource created for Terraform acceptance testing"
377+
check_interval_sec = 30
378+
source_regions = ["us-central1", "us-east1", "asia-south1"]
379+
http_health_check {
380+
port = "80"
381+
}
382+
}
383+
`, hckName)
384+
}
385+
386+
func testAccComputeHealthCheck_srcRegions_update(hckName string) string {
387+
return fmt.Sprintf(`
388+
resource "google_compute_health_check" "src_region" {
389+
name = "%s"
390+
description = "Resource updated for Terraform acceptance testing"
391+
check_interval_sec = 30
392+
source_regions = ["us-west1", "europe-north1", "asia-south1"]
393+
http_health_check {
394+
port = "80"
395+
}
396+
}
397+
`, hckName)
398+
}

website/docs/r/compute_health_check.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ The following arguments are supported:
390390
greater value than checkIntervalSec.
391391

392392
* `source_regions` -
393-
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
393+
(Optional)
394394
The list of cloud regions from which health checks are performed. If
395395
any regions are specified, then exactly 3 regions should be specified.
396396
The region names must be valid names of Google Cloud regions. This can

0 commit comments

Comments
 (0)