diff --git a/.changelog/4377.txt b/.changelog/4377.txt new file mode 100644 index 00000000000..add0ad0ea1c --- /dev/null +++ b/.changelog/4377.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: fixed an issue where `google_compute_region_per_instance_config`, `google_compute_per_instance_config`, `google_compute_region_instance_group_manager` resources were not inferring the region/zone from the provider. +``` diff --git a/google/resource_compute_per_instance_config.go b/google/resource_compute_per_instance_config.go index 86825b5fb83..5ab14250c7e 100644 --- a/google/resource_compute_per_instance_config.go +++ b/google/resource_compute_per_instance_config.go @@ -55,13 +55,6 @@ func resourceComputePerInstanceConfig() *schema.Resource { ForceNew: true, Description: `The name for this per-instance config and its corresponding instance.`, }, - "zone": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - DiffSuppressFunc: compareSelfLinkOrResourceName, - Description: `Zone where the containing instance group manager is located`, - }, "preserved_state": { Type: schema.TypeList, Optional: true, @@ -85,6 +78,13 @@ func resourceComputePerInstanceConfig() *schema.Resource { }, }, }, + "zone": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + Description: `Zone where the containing instance group manager is located`, + }, "minimal_action": { Type: schema.TypeString, Optional: true, diff --git a/google/resource_compute_per_instance_config_test.go b/google/resource_compute_per_instance_config_test.go index 1f8aac6c5b1..42704286a5c 100644 --- a/google/resource_compute_per_instance_config_test.go +++ b/google/resource_compute_per_instance_config_test.go @@ -24,7 +24,7 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) { "config_name4": fmt.Sprintf("instance-%s", randString(t, 10)), } igmId := fmt.Sprintf("projects/%s/zones/%s/instanceGroupManagers/%s", - getTestProjectFromEnv(), "us-central1-c", igmName) + getTestProjectFromEnv(), getTestZoneFromEnv(), igmName) vcrTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -38,7 +38,7 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "zone"}, }, { // Force-recreate old config @@ -51,7 +51,7 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "zone"}, }, { // Add two new endpoints @@ -61,7 +61,7 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "zone"}, }, { ResourceName: "google_compute_per_instance_config.with_disks", @@ -73,7 +73,7 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_per_instance_config.add2", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "zone"}, }, { // delete all configs @@ -109,7 +109,7 @@ func TestAccComputePerInstanceConfig_update(t *testing.T) { ResourceName: "google_compute_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "zone"}, }, { // Update an existing config @@ -119,7 +119,7 @@ func TestAccComputePerInstanceConfig_update(t *testing.T) { ResourceName: "google_compute_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "zone"}, }, }, }) @@ -128,7 +128,6 @@ func TestAccComputePerInstanceConfig_update(t *testing.T) { func testAccComputePerInstanceConfig_statefulBasic(context map[string]interface{}) string { return Nprintf(` resource "google_compute_per_instance_config" "default" { - zone = google_compute_instance_group_manager.igm.zone instance_group_manager = google_compute_instance_group_manager.igm.name name = "%{config_name}" remove_instance_state_on_destroy = true @@ -144,7 +143,6 @@ resource "google_compute_per_instance_config" "default" { func testAccComputePerInstanceConfig_update(context map[string]interface{}) string { return Nprintf(` resource "google_compute_per_instance_config" "default" { - zone = google_compute_instance_group_manager.igm.zone instance_group_manager = google_compute_instance_group_manager.igm.name name = "%{config_name}" remove_instance_state_on_destroy = true @@ -293,7 +291,6 @@ resource "google_compute_instance_group_manager" "igm" { } base_instance_name = "igm-no-tp" - zone = "us-central1-c" } `, context) } diff --git a/google/resource_compute_region_instance_group_manager.go b/google/resource_compute_region_instance_group_manager.go index 7fea96788d0..f9405810cb2 100644 --- a/google/resource_compute_region_instance_group_manager.go +++ b/google/resource_compute_region_instance_group_manager.go @@ -90,7 +90,8 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource { "region": { Type: schema.TypeString, - Required: true, + Computed: true, + Optional: true, ForceNew: true, Description: `The region where the managed instance group resides.`, }, diff --git a/google/resource_compute_region_instance_group_manager_test.go b/google/resource_compute_region_instance_group_manager_test.go index 9cb7f5f67ae..b7222eb7519 100644 --- a/google/resource_compute_region_instance_group_manager_test.go +++ b/google/resource_compute_region_instance_group_manager_test.go @@ -445,7 +445,6 @@ resource "google_compute_region_instance_group_manager" "igm-basic" { target_pools = [google_compute_target_pool.igm-basic.self_link] base_instance_name = "igm-basic" - region = "us-central1" target_size = 2 } diff --git a/google/resource_compute_region_per_instance_config.go b/google/resource_compute_region_per_instance_config.go index 42378a40977..5e92db4722e 100644 --- a/google/resource_compute_region_per_instance_config.go +++ b/google/resource_compute_region_per_instance_config.go @@ -48,13 +48,6 @@ func resourceComputeRegionPerInstanceConfig() *schema.Resource { ForceNew: true, Description: `The name for this per-instance config and its corresponding instance.`, }, - "region": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - DiffSuppressFunc: compareSelfLinkOrResourceName, - Description: `Region where the containing instance group manager is located`, - }, "region_instance_group_manager": { Type: schema.TypeString, Required: true, @@ -85,6 +78,14 @@ func resourceComputeRegionPerInstanceConfig() *schema.Resource { }, }, }, + "region": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + Description: `Region where the containing instance group manager is located`, + }, "minimal_action": { Type: schema.TypeString, Optional: true, @@ -288,6 +289,14 @@ func resourceComputeRegionPerInstanceConfigRead(d *schema.ResourceData, meta int return fmt.Errorf("Error reading RegionPerInstanceConfig: %s", err) } + region, err := getRegion(d, config) + if err != nil { + return err + } + if err := d.Set("region", region); err != nil { + return fmt.Errorf("Error reading RegionPerInstanceConfig: %s", err) + } + if err := d.Set("name", flattenNestedComputeRegionPerInstanceConfigName(res["name"], d, config)); err != nil { return fmt.Errorf("Error reading RegionPerInstanceConfig: %s", err) } diff --git a/google/resource_compute_region_per_instance_config_test.go b/google/resource_compute_region_per_instance_config_test.go index c70a2d670fd..41b5f6add08 100644 --- a/google/resource_compute_region_per_instance_config_test.go +++ b/google/resource_compute_region_per_instance_config_test.go @@ -24,7 +24,7 @@ func TestAccComputeRegionPerInstanceConfig_statefulBasic(t *testing.T) { "config_name4": fmt.Sprintf("instance-%s", randString(t, 10)), } rigmId := fmt.Sprintf("projects/%s/regions/%s/instanceGroupManagers/%s", - getTestProjectFromEnv(), "us-central1", rigmName) + getTestProjectFromEnv(), getTestRegionFromEnv(), rigmName) vcrTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -38,7 +38,7 @@ func TestAccComputeRegionPerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_region_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "region"}, }, { // Force-recreate old config @@ -51,7 +51,7 @@ func TestAccComputeRegionPerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_region_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "region"}, }, { // Add two new endpoints @@ -61,7 +61,7 @@ func TestAccComputeRegionPerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_region_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "region"}, }, { ResourceName: "google_compute_region_per_instance_config.with_disks", @@ -73,7 +73,7 @@ func TestAccComputeRegionPerInstanceConfig_statefulBasic(t *testing.T) { ResourceName: "google_compute_region_per_instance_config.add2", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "region"}, }, { // delete all configs @@ -109,7 +109,7 @@ func TestAccComputeRegionPerInstanceConfig_update(t *testing.T) { ResourceName: "google_compute_region_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "region"}, }, { // Update an existing config @@ -119,7 +119,7 @@ func TestAccComputeRegionPerInstanceConfig_update(t *testing.T) { ResourceName: "google_compute_region_per_instance_config.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"}, + ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy", "region"}, }, }, }) @@ -128,7 +128,6 @@ func TestAccComputeRegionPerInstanceConfig_update(t *testing.T) { func testAccComputeRegionPerInstanceConfig_statefulBasic(context map[string]interface{}) string { return Nprintf(` resource "google_compute_region_per_instance_config" "default" { - region = google_compute_region_instance_group_manager.rigm.region region_instance_group_manager = google_compute_region_instance_group_manager.rigm.name name = "%{config_name}" remove_instance_state_on_destroy = true @@ -144,7 +143,6 @@ resource "google_compute_region_per_instance_config" "default" { func testAccComputeRegionPerInstanceConfig_update(context map[string]interface{}) string { return Nprintf(` resource "google_compute_region_per_instance_config" "default" { - region = google_compute_region_instance_group_manager.rigm.region region_instance_group_manager = google_compute_region_instance_group_manager.rigm.name name = "%{config_name}" remove_instance_state_on_destroy = true @@ -293,7 +291,6 @@ resource "google_compute_region_instance_group_manager" "rigm" { } base_instance_name = "rigm-no-tp" - region = "us-central1" update_policy { instance_redistribution_type = "NONE" diff --git a/website/docs/r/compute_instance.html.markdown b/website/docs/r/compute_instance.html.markdown index 6457ee77ff2..43617edd687 100644 --- a/website/docs/r/compute_instance.html.markdown +++ b/website/docs/r/compute_instance.html.markdown @@ -81,7 +81,7 @@ The following arguments are supported: * `name` - (Required) A unique name for the resource, required by GCE. Changing this forces a new resource to be created. -* `zone` - (Required) The zone that the machine should be created in. +* `zone` - (Optional) The zone that the machine should be created in. If it is not provided, the provider zone is used. * `network_interface` - (Required) Networks to attach to the instance. This can be specified multiple times. Structure is documented below. diff --git a/website/docs/r/compute_per_instance_config.html.markdown b/website/docs/r/compute_per_instance_config.html.markdown index f050445410d..0a7bc9c7538 100644 --- a/website/docs/r/compute_per_instance_config.html.markdown +++ b/website/docs/r/compute_per_instance_config.html.markdown @@ -115,10 +115,6 @@ The following arguments are supported: (Required) The name for this per-instance config and its corresponding instance. -* `zone` - - (Required) - Zone where the containing instance group manager is located - * `instance_group_manager` - (Required) The instance group manager this instance config is part of. @@ -132,6 +128,10 @@ The following arguments are supported: The preserved state for this instance. Structure is documented below. +* `zone` - + (Optional) + Zone where the containing instance group manager is located + * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. diff --git a/website/docs/r/compute_region_instance_group_manager.html.markdown b/website/docs/r/compute_region_instance_group_manager.html.markdown index bbda21f0fa9..ef4bf7e1c42 100644 --- a/website/docs/r/compute_region_instance_group_manager.html.markdown +++ b/website/docs/r/compute_region_instance_group_manager.html.markdown @@ -101,7 +101,7 @@ The following arguments are supported: [RFC1035](https://www.ietf.org/rfc/rfc1035.txt). Supported characters include lowercase letters, numbers, and hyphens. -* `region` - (Required) The region where the managed instance group resides. +* `region` - (Optional) The region where the managed instance group resides. If not provided, the provider region is used. - - - diff --git a/website/docs/r/compute_region_per_instance_config.html.markdown b/website/docs/r/compute_region_per_instance_config.html.markdown index 0e1b584da97..5fa3cc11078 100644 --- a/website/docs/r/compute_region_per_instance_config.html.markdown +++ b/website/docs/r/compute_region_per_instance_config.html.markdown @@ -116,10 +116,6 @@ The following arguments are supported: (Required) The name for this per-instance config and its corresponding instance. -* `region` - - (Required) - Region where the containing instance group manager is located - * `region_instance_group_manager` - (Required) The region instance group manager this instance config is part of. @@ -133,6 +129,10 @@ The following arguments are supported: The preserved state for this instance. Structure is documented below. +* `region` - + (Optional) + Region where the containing instance group manager is located + * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.