From fd631abdf91fb194e557e57ee78da4d69b9e7721 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Mon, 19 Nov 2018 22:44:13 +0000 Subject: [PATCH] Start removing beta igm/rigm fields. --- google/data_source_google_iam_role.go | 48 --- google/data_source_google_iam_role_test.go | 51 --- google/provider.go | 1 - ...resource_compute_instance_group_manager.go | 266 +++--------- ...rce_compute_instance_group_manager_test.go | 407 ------------------ ...e_compute_region_instance_group_manager.go | 201 +++------ ...pute_region_instance_group_manager_test.go | 306 ------------- .../datasource_google_iam_role.html.markdown | 36 -- ...egion_instance_group_manager.html.markdown | 5 +- website/google.erb | 3 - 10 files changed, 106 insertions(+), 1218 deletions(-) delete mode 100644 google/data_source_google_iam_role.go delete mode 100644 google/data_source_google_iam_role_test.go delete mode 100644 website/docs/d/datasource_google_iam_role.html.markdown diff --git a/google/data_source_google_iam_role.go b/google/data_source_google_iam_role.go deleted file mode 100644 index e96ae5fde07..00000000000 --- a/google/data_source_google_iam_role.go +++ /dev/null @@ -1,48 +0,0 @@ -package google - -import ( - "fmt" - - "github.com/hashicorp/terraform/helper/schema" -) - -func dataSourceGoogleIamRole() *schema.Resource { - return &schema.Resource{ - Read: dataSourceGoogleIamRoleRead, - Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ - Type: schema.TypeString, - Required: true, - }, - "title": { - Type: schema.TypeString, - Computed: true, - }, - "included_permissions": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "stage": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func dataSourceGoogleIamRoleRead(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) - roleName := d.Get("name").(string) - role, err := config.clientIAM.Roles.Get(roleName).Do() - if err != nil { - return handleNotFoundError(err, d, fmt.Sprintf("Error reading IAM Role %s: %s", roleName, err)) - } - - d.SetId(role.Name) - d.Set("title", role.Title) - d.Set("stage", role.Stage) - d.Set("included_permissions", role.IncludedPermissions) - - return nil -} diff --git a/google/data_source_google_iam_role_test.go b/google/data_source_google_iam_role_test.go deleted file mode 100644 index cb58323a5df..00000000000 --- a/google/data_source_google_iam_role_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package google - -import ( - "errors" - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestAccDataSourceIAMRole(t *testing.T) { - name := "roles/viewer" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckGoogleIamRoleConfig(name), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleIAMRoleCheck("data.google_iam_role.role"), - ), - }, - }, - }) -} - -func testAccCheckGoogleIAMRoleCheck(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ds, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Can't find iam role data source: %s", n) - } - - _, ok = ds.Primary.Attributes["included_permissions.#"] - if !ok { - return errors.New("can't find 'included_permissions' attribute") - } - - return nil - } -} - -func testAccCheckGoogleIamRoleConfig(name string) string { - return fmt.Sprintf(` -data "google_iam_role" "role" { - name = "%s" -} -`, name) -} diff --git a/google/provider.go b/google/provider.go index 0514436dc51..0a599f80776 100644 --- a/google/provider.go +++ b/google/provider.go @@ -87,7 +87,6 @@ func Provider() terraform.ResourceProvider { "google_container_registry_repository": dataSourceGoogleContainerRepo(), "google_container_registry_image": dataSourceGoogleContainerImage(), "google_iam_policy": dataSourceGoogleIamPolicy(), - "google_iam_role": dataSourceGoogleIamRole(), "google_kms_secret": dataSourceGoogleKmsSecret(), "google_folder": dataSourceGoogleFolder(), "google_netblock_ip_ranges": dataSourceGoogleNetblockIpRanges(), diff --git a/google/resource_compute_instance_group_manager.go b/google/resource_compute_instance_group_manager.go index 224ab4a9514..1ef3079d541 100644 --- a/google/resource_compute_instance_group_manager.go +++ b/google/resource_compute_instance_group_manager.go @@ -44,37 +44,42 @@ func resourceComputeInstanceGroupManager() *schema.Resource { }, "version": &schema.Schema{ - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", - Type: schema.TypeList, - Optional: true, - Computed: true, + Type: schema.TypeList, + Optional: true, + Computed: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "instance_template": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", DiffSuppressFunc: compareSelfLinkRelativePaths, }, "target_size": &schema.Schema{ Type: schema.TypeList, Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "fixed": &schema.Schema{ Type: schema.TypeInt, Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "percent": &schema.Schema{ Type: schema.TypeInt, Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.IntBetween(0, 100), }, }, @@ -114,7 +119,7 @@ func resourceComputeInstanceGroupManager() *schema.Resource { }, "named_port": &schema.Schema{ - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -175,21 +180,23 @@ func resourceComputeInstanceGroupManager() *schema.Resource { }, "auto_healing_policies": &schema.Schema{ - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", - Type: schema.TypeList, - Optional: true, - MaxItems: 1, + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "health_check": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", DiffSuppressFunc: compareSelfLinkRelativePaths, }, "initial_delay_sec": &schema.Schema{ Type: schema.TypeInt, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.IntBetween(0, 3600), }, }, @@ -197,54 +204,57 @@ func resourceComputeInstanceGroupManager() *schema.Resource { }, "rolling_update_policy": &schema.Schema{ - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", - Type: schema.TypeList, - Optional: true, - MaxItems: 1, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + Computed: true, + Type: schema.TypeList, + Optional: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "minimal_action": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.StringInSlice([]string{"RESTART", "REPLACE"}, false), }, "type": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.StringInSlice([]string{"OPPORTUNISTIC", "PROACTIVE"}, false), }, "max_surge_fixed": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 1, - ConflictsWith: []string{"rolling_update_policy.0.max_surge_percent"}, + Type: schema.TypeInt, + Optional: true, + Computed: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "max_surge_percent": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - ConflictsWith: []string{"rolling_update_policy.0.max_surge_fixed"}, - ValidateFunc: validation.IntBetween(0, 100), + Type: schema.TypeInt, + Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + ValidateFunc: validation.IntBetween(0, 100), }, "max_unavailable_fixed": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 1, - ConflictsWith: []string{"rolling_update_policy.0.max_unavailable_percent"}, + Type: schema.TypeInt, + Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "max_unavailable_percent": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - ConflictsWith: []string{"rolling_update_policy.0.max_unavailable_fixed"}, - ValidateFunc: validation.IntBetween(0, 100), + Type: schema.TypeInt, + Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + ValidateFunc: validation.IntBetween(0, 100), }, "min_ready_sec": &schema.Schema{ Type: schema.TypeInt, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Optional: true, ValidateFunc: validation.IntBetween(0, 3600), }, @@ -300,21 +310,15 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte return err } - if _, ok := d.GetOk("rolling_update_policy"); d.Get("update_strategy") == "ROLLING_UPDATE" && !ok { - return fmt.Errorf("[rolling_update_policy] must be set when 'update_strategy' is set to 'ROLLING_UPDATE'") - } - // Build the parameter manager := &computeBeta.InstanceGroupManager{ - Name: d.Get("name").(string), - Description: d.Get("description").(string), - BaseInstanceName: d.Get("base_instance_name").(string), - InstanceTemplate: d.Get("instance_template").(string), - TargetSize: int64(d.Get("target_size").(int)), - NamedPorts: getNamedPortsBeta(d.Get("named_port").([]interface{})), - TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)), - AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})), - Versions: expandVersions(d.Get("version").([]interface{})), + Name: d.Get("name").(string), + Description: d.Get("description").(string), + BaseInstanceName: d.Get("base_instance_name").(string), + InstanceTemplate: d.Get("instance_template").(string), + TargetSize: int64(d.Get("target_size").(int)), + NamedPorts: getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()), + TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)), // Force send TargetSize to allow a value of 0. ForceSendFields: []string{"TargetSize"}, } @@ -449,9 +453,6 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf d.Set("base_instance_name", manager.BaseInstanceName) d.Set("instance_template", ConvertSelfLinkToV1(manager.InstanceTemplate)) - if err := d.Set("version", flattenVersions(manager.Versions)); err != nil { - return err - } d.Set("name", manager.Name) d.Set("zone", GetResourceNameFromSelfLink(manager.Zone)) d.Set("description", manager.Description) @@ -472,9 +473,9 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf update_strategy = "REPLACE" } d.Set("update_strategy", update_strategy.(string)) - if err = d.Set("auto_healing_policies", flattenAutoHealingPolicies(manager.AutoHealingPolicies)); err != nil { - return fmt.Errorf("Error setting auto_healing_policies in state: %s", err.Error()) - } + + // When we make a list Removed, we see a permadiff from `0 => ` (nil). Set to nil in Read so we see no diff. + d.Set("version", nil) if d.Get("wait_for_instances").(bool) { conf := resource.StateChangeConf{ @@ -495,7 +496,7 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf // Updates an instance group manager by applying the update strategy (REPLACE, RESTART) // and rolling update policy (PROACTIVE, OPPORTUNISTIC). Updates performed by API // are OPPORTUNISTIC by default. -func performZoneUpdate(config *Config, id string, updateStrategy string, rollingUpdatePolicy *computeBeta.InstanceGroupManagerUpdatePolicy, versions []*computeBeta.InstanceGroupManagerVersion, project string, zone string) error { +func performZoneUpdate(config *Config, id string, updateStrategy string, project string, zone string) error { if updateStrategy == "RESTART" || updateStrategy == "REPLACE" { managedInstances, err := config.clientComputeBeta.InstanceGroupManagers.ListManagedInstances(project, zone, id).Do() if err != nil { @@ -524,28 +525,6 @@ func performZoneUpdate(config *Config, id string, updateStrategy string, rolling } } - if updateStrategy == "ROLLING_UPDATE" { - // UpdatePolicy is set for InstanceGroupManager on update only, because it is only relevant for `Patch` calls. - // Other tools(gcloud and UI) capable of executing the same `ROLLING UPDATE` call - // expect those values to be provided by user as part of the call - // or provide their own defaults without respecting what was previously set on UpdateManager. - // To follow the same logic, we provide policy values on relevant update change only. - manager := &computeBeta.InstanceGroupManager{ - UpdatePolicy: rollingUpdatePolicy, - Versions: versions, - } - - op, err := config.clientComputeBeta.InstanceGroupManagers.Patch(project, zone, id, manager).Do() - if err != nil { - return fmt.Errorf("Error updating managed group instances: %s", err) - } - - err = computeSharedOperationWait(config.clientCompute, op, project, "Updating managed group instances") - if err != nil { - return err - } - } - return nil } @@ -571,10 +550,6 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte d.Partial(true) - if _, ok := d.GetOk("rolling_update_policy"); d.Get("update_strategy") == "ROLLING_UPDATE" && !ok { - return fmt.Errorf("[rolling_update_policy] must be set when 'update_strategy' is set to 'ROLLING_UPDATE'") - } - // If target_pools changes then update if d.HasChange("target_pools") { targetPools := convertStringSet(d.Get("target_pools").(*schema.Set)) @@ -605,7 +580,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte if d.HasChange("named_port") { // Build the parameters for a "SetNamedPorts" request: - namedPorts := getNamedPortsBeta(d.Get("named_port").([]interface{})) + namedPorts := getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()) setNamedPorts := &computeBeta.InstanceGroupsSetNamedPortsRequest{ NamedPorts: namedPorts, } @@ -645,29 +620,6 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte d.SetPartial("target_size") } - // We will always be in v0beta inside this conditional - if d.HasChange("auto_healing_policies") { - setAutoHealingPoliciesRequest := &computeBeta.InstanceGroupManagersSetAutoHealingRequest{} - if v, ok := d.GetOk("auto_healing_policies"); ok { - setAutoHealingPoliciesRequest.AutoHealingPolicies = expandAutoHealingPolicies(v.([]interface{})) - } - - op, err := config.clientComputeBeta.InstanceGroupManagers.SetAutoHealingPolicies( - zonalID.Project, zonalID.Zone, zonalID.Name, setAutoHealingPoliciesRequest).Do() - - if err != nil { - return fmt.Errorf("Error updating AutoHealingPolicies: %s", err) - } - - // Wait for the operation to complete - err = computeSharedOperationWait(config.clientCompute, op, zonalID.Project, "Updating AutoHealingPolicies") - if err != nil { - return err - } - - d.SetPartial("auto_healing_policies") - } - // If instance_template changes then update if d.HasChange("instance_template") { // Build the parameter @@ -688,24 +640,10 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte } updateStrategy := d.Get("update_strategy").(string) - rollingUpdatePolicy := expandUpdatePolicy(d.Get("rolling_update_policy").([]interface{})) - err = performZoneUpdate(config, zonalID.Name, updateStrategy, rollingUpdatePolicy, nil, zonalID.Project, zonalID.Zone) + err = performZoneUpdate(config, zonalID.Name, updateStrategy, zonalID.Project, zonalID.Zone) d.SetPartial("instance_template") } - // If version changes then update - if d.HasChange("version") { - updateStrategy := d.Get("update_strategy").(string) - rollingUpdatePolicy := expandUpdatePolicy(d.Get("rolling_update_policy").([]interface{})) - versions := expandVersions(d.Get("version").([]interface{})) - err = performZoneUpdate(config, zonalID.Name, updateStrategy, rollingUpdatePolicy, versions, zonalID.Project, zonalID.Zone) - if err != nil { - return err - } - - d.SetPartial("version") - } - d.Partial(false) return resourceComputeInstanceGroupManagerRead(d, meta) @@ -776,106 +714,6 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte return nil } -func expandAutoHealingPolicies(configured []interface{}) []*computeBeta.InstanceGroupManagerAutoHealingPolicy { - autoHealingPolicies := make([]*computeBeta.InstanceGroupManagerAutoHealingPolicy, 0, len(configured)) - for _, raw := range configured { - data := raw.(map[string]interface{}) - autoHealingPolicy := computeBeta.InstanceGroupManagerAutoHealingPolicy{ - HealthCheck: data["health_check"].(string), - InitialDelaySec: int64(data["initial_delay_sec"].(int)), - } - - autoHealingPolicies = append(autoHealingPolicies, &autoHealingPolicy) - } - return autoHealingPolicies -} - -func expandVersions(configured []interface{}) []*computeBeta.InstanceGroupManagerVersion { - versions := make([]*computeBeta.InstanceGroupManagerVersion, 0, len(configured)) - for _, raw := range configured { - data := raw.(map[string]interface{}) - - version := computeBeta.InstanceGroupManagerVersion{ - Name: data["name"].(string), - InstanceTemplate: data["instance_template"].(string), - TargetSize: expandFixedOrPercent(data["target_size"].([]interface{})), - } - - versions = append(versions, &version) - } - return versions -} - -func expandFixedOrPercent(configured []interface{}) *computeBeta.FixedOrPercent { - fixedOrPercent := &computeBeta.FixedOrPercent{} - - for _, raw := range configured { - data := raw.(map[string]interface{}) - if percent := data["percent"]; percent.(int) > 0 { - fixedOrPercent.Percent = int64(percent.(int)) - } else { - fixedOrPercent.Fixed = int64(data["fixed"].(int)) - fixedOrPercent.ForceSendFields = []string{"Fixed"} - } - } - return fixedOrPercent -} - -func expandUpdatePolicy(configured []interface{}) *computeBeta.InstanceGroupManagerUpdatePolicy { - updatePolicy := &computeBeta.InstanceGroupManagerUpdatePolicy{} - - for _, raw := range configured { - data := raw.(map[string]interface{}) - - updatePolicy.MinimalAction = data["minimal_action"].(string) - updatePolicy.Type = data["type"].(string) - - // percent and fixed values are conflicting - // when the percent values are set, the fixed values will be ignored - if v := data["max_surge_percent"]; v.(int) > 0 { - updatePolicy.MaxSurge = &computeBeta.FixedOrPercent{ - Percent: int64(v.(int)), - } - } else { - updatePolicy.MaxSurge = &computeBeta.FixedOrPercent{ - Fixed: int64(data["max_surge_fixed"].(int)), - // allow setting this value to 0 - ForceSendFields: []string{"Fixed"}, - } - } - - if v := data["max_unavailable_percent"]; v.(int) > 0 { - updatePolicy.MaxUnavailable = &computeBeta.FixedOrPercent{ - Percent: int64(v.(int)), - } - } else { - updatePolicy.MaxUnavailable = &computeBeta.FixedOrPercent{ - Fixed: int64(data["max_unavailable_fixed"].(int)), - // allow setting this value to 0 - ForceSendFields: []string{"Fixed"}, - } - } - - if v, ok := data["min_ready_sec"]; ok { - updatePolicy.MinReadySec = int64(v.(int)) - } - } - return updatePolicy -} - -func flattenAutoHealingPolicies(autoHealingPolicies []*computeBeta.InstanceGroupManagerAutoHealingPolicy) []map[string]interface{} { - autoHealingPoliciesSchema := make([]map[string]interface{}, 0, len(autoHealingPolicies)) - for _, autoHealingPolicy := range autoHealingPolicies { - data := map[string]interface{}{ - "health_check": autoHealingPolicy.HealthCheck, - "initial_delay_sec": autoHealingPolicy.InitialDelaySec, - } - - autoHealingPoliciesSchema = append(autoHealingPoliciesSchema, data) - } - return autoHealingPoliciesSchema -} - func resourceInstanceGroupManagerStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { d.Set("wait_for_instances", false) zonalID, err := parseInstanceGroupManagerId(d.Id()) diff --git a/google/resource_compute_instance_group_manager_test.go b/google/resource_compute_instance_group_manager_test.go index 0ca686b583e..fe77618eb5e 100644 --- a/google/resource_compute_instance_group_manager_test.go +++ b/google/resource_compute_instance_group_manager_test.go @@ -150,28 +150,6 @@ func TestAccInstanceGroupManager_updateStrategy(t *testing.T) { }) } -func TestAccInstanceGroupManager_rollingUpdatePolicy(t *testing.T) { - t.Parallel() - - igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckInstanceGroupManagerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccInstanceGroupManager_rollingUpdatePolicy(igm), - }, - // No import step because rolling updates are broken and the field will be removed in 2.0.0. - // TODO(danawillow): Remove this test once we've removed the field. - { - Config: testAccInstanceGroupManager_rollingUpdatePolicy2(igm), - }, - }, - }) -} - func TestAccInstanceGroupManager_separateRegions(t *testing.T) { t.Parallel() @@ -200,85 +178,6 @@ func TestAccInstanceGroupManager_separateRegions(t *testing.T) { }) } -func TestAccInstanceGroupManager_versions(t *testing.T) { - t.Parallel() - - primaryTemplate := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - canaryTemplate := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckInstanceGroupManagerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccInstanceGroupManager_versions(primaryTemplate, canaryTemplate, igm), - }, - { - ResourceName: "google_compute_instance_group_manager.igm-basic", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccInstanceGroupManager_autoHealingPolicies(t *testing.T) { - t.Parallel() - - template := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - target := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - hck := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckInstanceGroupManagerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccInstanceGroupManager_autoHealingPolicies(template, target, igm, hck), - }, - { - ResourceName: "google_compute_instance_group_manager.igm-basic", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -// This test is to make sure that a single version resource can link to a versioned resource -// without perpetual diffs because the self links mismatch. -// Once auto_healing_policies is no longer beta, we will need to use a new field or resource -// with Beta fields. -func TestAccInstanceGroupManager_selfLinkStability(t *testing.T) { - t.Parallel() - - template := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - target := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - hck := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - autoscaler := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckInstanceGroupManagerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccInstanceGroupManager_selfLinkStability(template, target, igm, hck, autoscaler), - }, - { - ResourceName: "google_compute_instance_group_manager.igm-basic", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - func testAccCheckInstanceGroupManagerDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) @@ -643,108 +542,6 @@ func testAccInstanceGroupManager_updateStrategy(igm string) string { }`, igm) } -func testAccInstanceGroupManager_rollingUpdatePolicy(igm string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-rolling-update-policy" { - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["terraform-testing"] - - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - - network_interface { - network = "default" - } - - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } - - lifecycle { - create_before_destroy = true - } -} - -resource "google_compute_instance_group_manager" "igm-rolling-update-policy" { - description = "Terraform test instance group manager" - name = "%s" - instance_template = "${google_compute_instance_template.igm-rolling-update-policy.self_link}" - base_instance_name = "igm-rolling-update-policy" - zone = "us-central1-c" - target_size = 3 - update_strategy = "ROLLING_UPDATE" - rolling_update_policy { - type = "PROACTIVE" - minimal_action = "REPLACE" - max_surge_percent = 50 - max_unavailable_percent = 50 - min_ready_sec = 20 - } - named_port { - name = "customhttp" - port = 8080 - } -}`, igm) -} - -func testAccInstanceGroupManager_rollingUpdatePolicy2(igm string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-rolling-update-policy" { - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["terraform-testing"] - - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - - network_interface { - network = "default" - } - - lifecycle { - create_before_destroy = true - } -} - -resource "google_compute_instance_group_manager" "igm-rolling-update-policy" { - description = "Terraform test instance group manager" - name = "%s" - instance_template = "${google_compute_instance_template.igm-rolling-update-policy.self_link}" - base_instance_name = "igm-rolling-update-policy" - zone = "us-central1-c" - target_size = 3 - update_strategy = "ROLLING_UPDATE" - rolling_update_policy { - type = "PROACTIVE" - minimal_action = "REPLACE" - max_surge_fixed = 2 - max_unavailable_fixed = 2 - min_ready_sec = 20 - } - named_port { - name = "customhttp" - port = 8080 - } -}`, igm) -} - func testAccInstanceGroupManager_separateRegions(igm1, igm2 string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { @@ -795,207 +592,3 @@ func testAccInstanceGroupManager_separateRegions(igm1, igm2 string) string { } `, igm1, igm2) } - -func testAccInstanceGroupManager_autoHealingPolicies(template, target, igm, hck string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-basic" { - name = "%s" - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["foo", "bar"] - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - network_interface { - network = "default" - } - metadata { - foo = "bar" - } - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } -} - -resource "google_compute_target_pool" "igm-basic" { - description = "Resource created for Terraform acceptance testing" - name = "%s" - session_affinity = "CLIENT_IP_PROTO" -} - -resource "google_compute_instance_group_manager" "igm-basic" { - description = "Terraform test instance group manager" - name = "%s" - instance_template = "${google_compute_instance_template.igm-basic.self_link}" - target_pools = ["${google_compute_target_pool.igm-basic.self_link}"] - base_instance_name = "igm-basic" - zone = "us-central1-c" - target_size = 2 - auto_healing_policies { - health_check = "${google_compute_http_health_check.zero.self_link}" - initial_delay_sec = "10" - } -} - -resource "google_compute_http_health_check" "zero" { - name = "%s" - request_path = "/" - check_interval_sec = 1 - timeout_sec = 1 -} - `, template, target, igm, hck) -} - -func testAccInstanceGroupManager_versions(primaryTemplate string, canaryTemplate string, igm string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-primary" { - name = "%s" - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["foo", "bar"] - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - network_interface { - network = "default" - } - metadata { - foo = "bar" - } - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } -} - -resource "google_compute_instance_template" "igm-canary" { - name = "%s" - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["foo", "bar"] - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - network_interface { - network = "default" - } - metadata { - foo = "bar" - } - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } -} - -resource "google_compute_instance_group_manager" "igm-basic" { - description = "Terraform test instance group manager" - name = "%s" - base_instance_name = "igm-basic" - zone = "us-central1-c" - target_size = 2 - - version { - name = "primary" - instance_template = "${google_compute_instance_template.igm-primary.self_link}" - } - - version { - name = "canary" - instance_template = "${google_compute_instance_template.igm-canary.self_link}" - target_size { - fixed = 1 - } - } -} - `, primaryTemplate, canaryTemplate, igm) -} - -// This test is to make sure that a single version resource can link to a versioned resource -// without perpetual diffs because the self links mismatch. -// Once auto_healing_policies is no longer beta, we will need to use a new field or resource -// with Beta fields. -func testAccInstanceGroupManager_selfLinkStability(template, target, igm, hck, autoscaler string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-basic" { - name = "%s" - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["foo", "bar"] - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - network_interface { - network = "default" - } - metadata { - foo = "bar" - } - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } -} - -resource "google_compute_target_pool" "igm-basic" { - description = "Resource created for Terraform acceptance testing" - name = "%s" - session_affinity = "CLIENT_IP_PROTO" -} - -resource "google_compute_instance_group_manager" "igm-basic" { - description = "Terraform test instance group manager" - name = "%s" - instance_template = "${google_compute_instance_template.igm-basic.self_link}" - target_pools = ["${google_compute_target_pool.igm-basic.self_link}"] - base_instance_name = "igm-basic" - zone = "us-central1-c" - target_size = 2 - auto_healing_policies { - health_check = "${google_compute_http_health_check.zero.self_link}" - initial_delay_sec = "10" - } -} - -resource "google_compute_http_health_check" "zero" { - name = "%s" - request_path = "/" - check_interval_sec = 1 - timeout_sec = 1 -} - -resource "google_compute_autoscaler" "foobar" { - name = "%s" - zone = "us-central1-c" - target = "${google_compute_instance_group_manager.igm-basic.self_link}" - autoscaling_policy = { - max_replicas = 10 - min_replicas = 1 - cooldown_period = 60 - cpu_utilization = { - target = 0.5 - } - } -} -`, template, target, igm, hck, autoscaler) -} diff --git a/google/resource_compute_region_instance_group_manager.go b/google/resource_compute_region_instance_group_manager.go index 8b33afa9615..9f5f1d14ac7 100644 --- a/google/resource_compute_region_instance_group_manager.go +++ b/google/resource_compute_region_instance_group_manager.go @@ -49,37 +49,42 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource { }, "version": &schema.Schema{ - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + Type: schema.TypeList, + Optional: true, + Computed: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "instance_template": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", DiffSuppressFunc: compareSelfLinkRelativePaths, }, "target_size": &schema.Schema{ Type: schema.TypeList, Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "fixed": &schema.Schema{ Type: schema.TypeInt, Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "percent": &schema.Schema{ Type: schema.TypeInt, Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.IntBetween(0, 100), }, }, @@ -118,7 +123,7 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource { }, "named_port": &schema.Schema{ - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -178,21 +183,23 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource { }, "auto_healing_policies": &schema.Schema{ - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "health_check": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", DiffSuppressFunc: compareSelfLinkRelativePaths, }, "initial_delay_sec": &schema.Schema{ Type: schema.TypeInt, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.IntBetween(0, 3600), }, }, @@ -212,54 +219,57 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource { }, "rolling_update_policy": &schema.Schema{ - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", - Type: schema.TypeList, - Optional: true, - MaxItems: 1, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + Computed: true, + Type: schema.TypeList, + Optional: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "minimal_action": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.StringInSlice([]string{"RESTART", "REPLACE"}, false), }, "type": &schema.Schema{ Type: schema.TypeString, Required: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", ValidateFunc: validation.StringInSlice([]string{"OPPORTUNISTIC", "PROACTIVE"}, false), }, "max_surge_fixed": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 0, - ConflictsWith: []string{"rolling_update_policy.0.max_surge_percent"}, + Type: schema.TypeInt, + Optional: true, + Computed: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "max_surge_percent": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - ConflictsWith: []string{"rolling_update_policy.0.max_surge_fixed"}, - ValidateFunc: validation.IntBetween(0, 100), + Type: schema.TypeInt, + Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + ValidateFunc: validation.IntBetween(0, 100), }, "max_unavailable_fixed": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 0, - ConflictsWith: []string{"rolling_update_policy.0.max_unavailable_percent"}, + Type: schema.TypeInt, + Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", }, "max_unavailable_percent": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - ConflictsWith: []string{"rolling_update_policy.0.max_unavailable_fixed"}, - ValidateFunc: validation.IntBetween(0, 100), + Type: schema.TypeInt, + Optional: true, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + ValidateFunc: validation.IntBetween(0, 100), }, "min_ready_sec": &schema.Schema{ Type: schema.TypeInt, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Optional: true, ValidateFunc: validation.IntBetween(0, 3600), }, @@ -283,21 +293,15 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met return err } - if _, ok := d.GetOk("rolling_update_policy"); d.Get("update_strategy") == "ROLLING_UPDATE" && !ok { - return fmt.Errorf("[rolling_update_policy] must be set when 'update_strategy' is set to 'ROLLING_UPDATE'") - } - manager := &computeBeta.InstanceGroupManager{ - Name: d.Get("name").(string), - Description: d.Get("description").(string), - BaseInstanceName: d.Get("base_instance_name").(string), - InstanceTemplate: d.Get("instance_template").(string), - TargetSize: int64(d.Get("target_size").(int)), - NamedPorts: getNamedPortsBeta(d.Get("named_port").([]interface{})), - TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)), - AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})), - Versions: expandVersions(d.Get("version").([]interface{})), - DistributionPolicy: expandDistributionPolicy(d.Get("distribution_policy_zones").(*schema.Set)), + Name: d.Get("name").(string), + Description: d.Get("description").(string), + BaseInstanceName: d.Get("base_instance_name").(string), + InstanceTemplate: d.Get("instance_template").(string), + TargetSize: int64(d.Get("target_size").(int)), + NamedPorts: getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()), + TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)), + DistributionPolicy: expandDistributionPolicy(d.Get("distribution_policy_zones").(*schema.Set)), // Force send TargetSize to allow size of 0. ForceSendFields: []string{"TargetSize"}, } @@ -390,9 +394,7 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta d.Set("base_instance_name", manager.BaseInstanceName) d.Set("instance_template", ConvertSelfLinkToV1(manager.InstanceTemplate)) - if err := d.Set("version", flattenVersions(manager.Versions)); err != nil { - return err - } + d.Set("name", manager.Name) d.Set("region", GetResourceNameFromSelfLink(manager.Region)) d.Set("description", manager.Description) @@ -406,9 +408,6 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta } d.Set("fingerprint", manager.Fingerprint) d.Set("instance_group", ConvertSelfLinkToV1(manager.InstanceGroup)) - if err := d.Set("auto_healing_policies", flattenAutoHealingPolicies(manager.AutoHealingPolicies)); err != nil { - return fmt.Errorf("Error setting auto_healing_policies in state: %s", err.Error()) - } if err := d.Set("distribution_policy_zones", flattenDistributionPolicy(manager.DistributionPolicy)); err != nil { return err } @@ -419,6 +418,9 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta } d.Set("update_strategy", update_strategy.(string)) + // When we make a list Removed, we see a permadiff from `0 => ` (nil). Set to nil in Read so we see no diff. + d.Set("version", nil) + if d.Get("wait_for_instances").(bool) { conf := resource.StateChangeConf{ Pending: []string{"creating", "error"}, @@ -435,63 +437,6 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta return nil } -// Updates an instance group manager by applying the update strategy (REPLACE, RESTART) -// and rolling update policy (PROACTIVE, OPPORTUNISTIC). Updates performed by API -// are OPPORTUNISTIC by default. -func performRegionUpdate(config *Config, id string, updateStrategy string, rollingUpdatePolicy *computeBeta.InstanceGroupManagerUpdatePolicy, versions []*computeBeta.InstanceGroupManagerVersion, project string, region string) error { - if updateStrategy == "RESTART" { - managedInstances, err := config.clientComputeBeta.RegionInstanceGroupManagers.ListManagedInstances(project, region, id).Do() - if err != nil { - return fmt.Errorf("Error getting region instance group managers instances: %s", err) - } - - managedInstanceCount := len(managedInstances.ManagedInstances) - instances := make([]string, managedInstanceCount) - for i, v := range managedInstances.ManagedInstances { - instances[i] = v.Instance - } - - recreateInstances := &computeBeta.RegionInstanceGroupManagersRecreateRequest{ - Instances: instances, - } - - op, err := config.clientComputeBeta.RegionInstanceGroupManagers.RecreateInstances(project, region, id, recreateInstances).Do() - if err != nil { - return fmt.Errorf("Error restarting region instance group managers instances: %s", err) - } - - // Wait for the operation to complete - err = computeSharedOperationWaitTime(config.clientCompute, op, project, managedInstanceCount*4, "Restarting RegionInstanceGroupManagers instances") - if err != nil { - return err - } - } - - if updateStrategy == "ROLLING_UPDATE" { - // UpdatePolicy is set for InstanceGroupManager on update only, because it is only relevant for `Patch` calls. - // Other tools(gcloud and UI) capable of executing the same `ROLLING UPDATE` call - // expect those values to be provided by user as part of the call - // or provide their own defaults without respecting what was previously set on UpdateManager. - // To follow the same logic, we provide policy values on relevant update change only. - manager := &computeBeta.InstanceGroupManager{ - UpdatePolicy: rollingUpdatePolicy, - Versions: versions, - } - - op, err := config.clientComputeBeta.RegionInstanceGroupManagers.Patch(project, region, id, manager).Do() - if err != nil { - return fmt.Errorf("Error updating region managed group instances: %s", err) - } - - err = computeSharedOperationWait(config.clientCompute, op, project, "Updating region managed group instances") - if err != nil { - return err - } - } - - return nil -} - func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) @@ -507,10 +452,6 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met d.Partial(true) - if _, ok := d.GetOk("rolling_update_policy"); d.Get("update_strategy") == "ROLLING_UPDATE" && !ok { - return fmt.Errorf("[rolling_update_policy] must be set when 'update_strategy' is set to 'ROLLING_UPDATE'") - } - if d.HasChange("target_pools") { targetPools := convertStringSet(d.Get("target_pools").(*schema.Set)) @@ -555,28 +496,12 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met return err } - updateStrategy := d.Get("update_strategy").(string) - rollingUpdatePolicy := expandUpdatePolicy(d.Get("rolling_update_policy").([]interface{})) - err = performRegionUpdate(config, d.Id(), updateStrategy, rollingUpdatePolicy, nil, project, region) d.SetPartial("instance_template") } - // If version changes then update - if d.HasChange("version") { - updateStrategy := d.Get("update_strategy").(string) - rollingUpdatePolicy := expandUpdatePolicy(d.Get("rolling_update_policy").([]interface{})) - versions := expandVersions(d.Get("version").([]interface{})) - err = performRegionUpdate(config, d.Get("name").(string), updateStrategy, rollingUpdatePolicy, versions, project, region) - if err != nil { - return err - } - - d.SetPartial("version") - } - if d.HasChange("named_port") { // Build the parameters for a "SetNamedPorts" request: - namedPorts := getNamedPortsBeta(d.Get("named_port").([]interface{})) + namedPorts := getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()) setNamedPorts := &computeBeta.RegionInstanceGroupsSetNamedPortsRequest{ NamedPorts: namedPorts, } @@ -616,28 +541,6 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met d.SetPartial("target_size") } - if d.HasChange("auto_healing_policies") { - setAutoHealingPoliciesRequest := &computeBeta.RegionInstanceGroupManagersSetAutoHealingRequest{} - if v, ok := d.GetOk("auto_healing_policies"); ok { - setAutoHealingPoliciesRequest.AutoHealingPolicies = expandAutoHealingPolicies(v.([]interface{})) - } - - op, err := config.clientComputeBeta.RegionInstanceGroupManagers.SetAutoHealingPolicies( - project, region, d.Get("name").(string), setAutoHealingPoliciesRequest).Do() - - if err != nil { - return fmt.Errorf("Error updating AutoHealingPolicies: %s", err) - } - - // Wait for the operation to complete - err = computeSharedOperationWait(config.clientCompute, op, project, "Updating AutoHealingPolicies") - if err != nil { - return err - } - - d.SetPartial("auto_healing_policies") - } - d.Partial(false) return resourceComputeRegionInstanceGroupManagerRead(d, meta) diff --git a/google/resource_compute_region_instance_group_manager_test.go b/google/resource_compute_region_instance_group_manager_test.go index 2aaa0cf0362..e6fe33245b8 100644 --- a/google/resource_compute_region_instance_group_manager_test.go +++ b/google/resource_compute_region_instance_group_manager_test.go @@ -151,27 +151,6 @@ func TestAccRegionInstanceGroupManager_updateStrategy(t *testing.T) { }) } -func TestAccRegionInstanceGroupManager_rollingUpdatePolicy(t *testing.T) { - t.Parallel() - - igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckInstanceGroupManagerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRegionInstanceGroupManager_rollingUpdatePolicy(igm), - }, - // No import step because rolling updates are broken and the field will be removed in 2.0.0. - // TODO(danawillow): Remove this test once we've removed the field. - { - Config: testAccRegionInstanceGroupManager_rollingUpdatePolicy2(igm), - }, - }, - }) -} func TestAccRegionInstanceGroupManager_separateRegions(t *testing.T) { t.Parallel() @@ -200,55 +179,6 @@ func TestAccRegionInstanceGroupManager_separateRegions(t *testing.T) { }) } -func TestAccRegionInstanceGroupManager_versions(t *testing.T) { - t.Parallel() - - primaryTemplate := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - canaryTemplate := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRegionInstanceGroupManagerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRegionInstanceGroupManager_versions(primaryTemplate, canaryTemplate, igm), - }, - { - ResourceName: "google_compute_region_instance_group_manager.igm-basic", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccRegionInstanceGroupManager_autoHealingPolicies(t *testing.T) { - t.Parallel() - - template := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - target := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - hck := fmt.Sprintf("igm-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRegionInstanceGroupManagerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRegionInstanceGroupManager_autoHealingPolicies(template, target, igm, hck), - }, - { - ResourceName: "google_compute_region_instance_group_manager.igm-basic", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - func TestAccRegionInstanceGroupManager_distributionPolicy(t *testing.T) { t.Parallel() @@ -642,135 +572,6 @@ func testAccRegionInstanceGroupManager_separateRegions(igm1, igm2 string) string `, igm1, igm2) } -func testAccRegionInstanceGroupManager_autoHealingPolicies(template, target, igm, hck string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-basic" { - name = "%s" - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["foo", "bar"] - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - network_interface { - network = "default" - } - metadata { - foo = "bar" - } - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } -} - -resource "google_compute_target_pool" "igm-basic" { - description = "Resource created for Terraform acceptance testing" - name = "%s" - session_affinity = "CLIENT_IP_PROTO" -} - -resource "google_compute_region_instance_group_manager" "igm-basic" { - description = "Terraform test instance group manager" - name = "%s" - instance_template = "${google_compute_instance_template.igm-basic.self_link}" - target_pools = ["${google_compute_target_pool.igm-basic.self_link}"] - base_instance_name = "igm-basic" - region = "us-central1" - target_size = 2 - auto_healing_policies { - health_check = "${google_compute_http_health_check.zero.self_link}" - initial_delay_sec = "10" - } -} - -resource "google_compute_http_health_check" "zero" { - name = "%s" - request_path = "/" - check_interval_sec = 1 - timeout_sec = 1 -} - `, template, target, igm, hck) -} - -func testAccRegionInstanceGroupManager_versions(primaryTemplate string, canaryTemplate string, igm string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-primary" { - name = "%s" - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["foo", "bar"] - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - network_interface { - network = "default" - } - metadata { - foo = "bar" - } - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } -} - -resource "google_compute_instance_template" "igm-canary" { - name = "%s" - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["foo", "bar"] - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - network_interface { - network = "default" - } - metadata { - foo = "bar" - } - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } -} - -resource "google_compute_region_instance_group_manager" "igm-basic" { - description = "Terraform test region instance group manager" - name = "%s" - base_instance_name = "igm-basic" - region = "us-central1" - target_size = 2 - - version { - name = "primary" - instance_template = "${google_compute_instance_template.igm-primary.self_link}" - } - - version { - name = "canary" - instance_template = "${google_compute_instance_template.igm-canary.self_link}" - target_size { - fixed = 1 - } - } -} - `, primaryTemplate, canaryTemplate, igm) -} - func testAccRegionInstanceGroupManager_distributionPolicy(template, igm string, zones []string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { @@ -853,110 +654,3 @@ resource "google_compute_region_instance_group_manager" "igm-update-strategy" { } }`, igm) } - -func testAccRegionInstanceGroupManager_rollingUpdatePolicy(igm string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-rolling-update-policy" { - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["terraform-testing"] - - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - - network_interface { - network = "default" - } - - service_account { - scopes = ["userinfo-email", "compute-ro", "storage-ro"] - } - - lifecycle { - create_before_destroy = true - } -} - -resource "google_compute_region_instance_group_manager" "igm-rolling-update-policy" { - description = "Terraform test instance group manager" - name = "%s" - instance_template = "${google_compute_instance_template.igm-rolling-update-policy.self_link}" - base_instance_name = "igm-rolling-update-policy" - region = "us-central1" - target_size = 4 - distribution_policy_zones = ["us-central1-a", "us-central1-f"] - update_strategy = "ROLLING_UPDATE" - - rolling_update_policy { - type = "PROACTIVE" - minimal_action = "REPLACE" - max_surge_fixed = 2 - max_unavailable_fixed = 2 - min_ready_sec = 20 - } - - named_port { - name = "customhttp" - port = 8080 - } -}`, igm) -} - -func testAccRegionInstanceGroupManager_rollingUpdatePolicy2(igm string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_instance_template" "igm-rolling-update-policy" { - machine_type = "n1-standard-1" - can_ip_forward = false - tags = ["terraform-testing"] - - disk { - source_image = "${data.google_compute_image.my_image.self_link}" - auto_delete = true - boot = true - } - - network_interface { - network = "default" - } - - lifecycle { - create_before_destroy = true - } -} - -resource "google_compute_region_instance_group_manager" "igm-rolling-update-policy" { - description = "Terraform test instance group manager" - name = "%s" - instance_template = "${google_compute_instance_template.igm-rolling-update-policy.self_link}" - base_instance_name = "igm-rolling-update-policy" - region = "us-central1" - distribution_policy_zones = ["us-central1-a", "us-central1-f"] - target_size = 3 - update_strategy = "ROLLING_UPDATE" - - rolling_update_policy { - type = "PROACTIVE" - minimal_action = "REPLACE" - max_surge_fixed = 2 - max_unavailable_fixed = 0 - min_ready_sec = 10 - } - named_port { - name = "customhttp" - port = 8080 - } -}`, igm) -} diff --git a/website/docs/d/datasource_google_iam_role.html.markdown b/website/docs/d/datasource_google_iam_role.html.markdown deleted file mode 100644 index 77aebf4b89e..00000000000 --- a/website/docs/d/datasource_google_iam_role.html.markdown +++ /dev/null @@ -1,36 +0,0 @@ ---- -layout: "google" -page_title: "Google: google_iam_role" -sidebar_current: "docs-google-datasource-iam-role" -description: |- - Get information about a Google IAM Role. ---- - -# google\_iam\_role - -Use this data source to get information about a Google IAM Role. - -```hcl -data "google_iam_role" "roleinfo" { - name = "roles/compute.viewer" -} - -output "the_role_permissions" { - value = "${data.google_iam_role.roleinfo.included_permissions}" -} - -``` - -## Argument Reference - -The following arguments are supported: - -* `name` (Required) - The name of the Role to lookup in the form `roles/{ROLE_NAME}`, `organizations/{ORGANIZATION_ID}/roles/{ROLE_NAME}` or `projects/{PROJECT_ID}/roles/{ROLE_NAME}` - -## Attributes Reference - -The following attributes are exported: - -* `title` - is a friendly title for the role, such as "Role Viewer" -* `included_permissions` - specifies the list of one or more permissions to include in the custom role, such as - `iam.roles.get` -* `stage` - indicates the stage of a role in the launch lifecycle, such as `GA`, `BETA` or `ALPHA`. 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 a064979db9a..2a020af372a 100644 --- a/website/docs/r/compute_region_instance_group_manager.html.markdown +++ b/website/docs/r/compute_region_instance_group_manager.html.markdown @@ -116,10 +116,9 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `update_strategy` - (Optional, Default `"REPLACE"`) If the `instance_template` +* `update_strategy` - (Optional, Default `"NONE"`) If the `instance_template` resource is modified, a value of `"NONE"` will prevent any of the managed - instances from being restarted by Terraform. A value of `"REPLACE"` will - restart all of the instances at once. This field is only present in the + instances from being restarted by Terraform. This field is only present in the `google` provider. * `target_size` - (Optional) The target number of running instances for this managed diff --git a/website/google.erb b/website/google.erb index 94797446b12..67a5fff93fb 100644 --- a/website/google.erb +++ b/website/google.erb @@ -114,9 +114,6 @@ > google_iam_policy - > - google_iam_role - > google_kms_secret