Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate lifecyclePolicy.updateOnRepair to GA #15322

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8412.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: enhancement
compute: added field `instance_lifecycle_policy` to `google_compute_instance_group_manager` and `google_compute_region_instance_group_manager` (ga)
```
9 changes: 9 additions & 0 deletions google/resource_compute_instance_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ resource "google_compute_instance_group_manager" "igm-update" {
port = 8080
}

instance_lifecycle_policy {
force_update_on_repair = "YES"
}
}
`, template, target, description, igm)
}
Expand Down Expand Up @@ -755,6 +758,9 @@ resource "google_compute_instance_group_manager" "igm-update" {
}


instance_lifecycle_policy {
force_update_on_repair = "NO"
}
}
`, template1, target1, target2, template2, description, igm)
}
Expand Down Expand Up @@ -1733,6 +1739,9 @@ resource "google_compute_instance_group_manager" "igm-basic" {
max_surge_fixed = 0
max_unavailable_percent = 50
}
instance_lifecycle_policy {
force_update_on_repair = "YES"
}
wait_for_instances = true
wait_for_instances_status = "UPDATED"
}
Expand Down
6 changes: 6 additions & 0 deletions google/resource_compute_region_instance_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
}


instance_lifecycle_policy {
force_update_on_repair = "YES"
}
}
`, template, target, igm)
}
Expand Down Expand Up @@ -631,6 +634,9 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
}


instance_lifecycle_policy {
force_update_on_repair = "NO"
}
}
`, template1, target1, target2, template2, igm)
}
Expand Down
48 changes: 48 additions & 0 deletions google/services/compute/resource_compute_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,25 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
},
},

"instance_lifecycle_policy": {
Computed: true,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `The instance lifecycle policy for this managed instance group.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"force_update_on_repair": {
Type: schema.TypeString,
Default: "NO",
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"YES", "NO"}, true),
Description: `Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: YES, NO. If YES and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If NO (default), then updates are applied in accordance with the group's update policy type.`,
},
},
},
},

"wait_for_instances": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -459,6 +478,7 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte
AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})),
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandUpdatePolicy(d.Get("update_policy").([]interface{})),
InstanceLifecyclePolicy: expandInstanceLifecyclePolicy(d.Get("instance_lifecycle_policy").([]interface{})),
StatefulPolicy: expandStatefulPolicy(d),

// Force send TargetSize to allow a value of 0.
Expand Down Expand Up @@ -670,6 +690,9 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
if err = d.Set("update_policy", flattenUpdatePolicy(manager.UpdatePolicy)); err != nil {
return fmt.Errorf("Error setting update_policy in state: %s", err.Error())
}
if err = d.Set("instance_lifecycle_policy", flattenInstanceLifecyclePolicy(manager.InstanceLifecyclePolicy)); err != nil {
return fmt.Errorf("Error setting instance lifecycle policy in state: %s", err.Error())
}
if err = d.Set("status", flattenStatus(manager.Status)); err != nil {
return fmt.Errorf("Error setting status in state: %s", err.Error())
}
Expand Down Expand Up @@ -735,6 +758,11 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte
change = true
}

if d.HasChange("instance_lifecycle_policy") {
updatedManager.InstanceLifecyclePolicy = expandInstanceLifecyclePolicy(d.Get("instance_lifecycle_policy").([]interface{}))
change = true
}

if d.HasChange("stateful_disk") {
updatedManager.StatefulPolicy = expandStatefulPolicy(d)
change = true
Expand Down Expand Up @@ -1002,6 +1030,16 @@ func expandFixedOrPercent(configured []interface{}) *compute.FixedOrPercent {
return fixedOrPercent
}

func expandInstanceLifecyclePolicy(configured []interface{}) *compute.InstanceGroupManagerInstanceLifecyclePolicy {
instanceLifecyclePolicy := &compute.InstanceGroupManagerInstanceLifecyclePolicy{}

for _, raw := range configured {
data := raw.(map[string]interface{})
instanceLifecyclePolicy.ForceUpdateOnRepair = data["force_update_on_repair"].(string)
}
return instanceLifecyclePolicy
}

func expandUpdatePolicy(configured []interface{}) *compute.InstanceGroupManagerUpdatePolicy {
updatePolicy := &compute.InstanceGroupManagerUpdatePolicy{}

Expand Down Expand Up @@ -1106,6 +1144,16 @@ func flattenUpdatePolicy(updatePolicy *compute.InstanceGroupManagerUpdatePolicy)
return results
}

func flattenInstanceLifecyclePolicy(instanceLifecyclePolicy *compute.InstanceGroupManagerInstanceLifecyclePolicy) []map[string]interface{} {
results := []map[string]interface{}{}
if instanceLifecyclePolicy != nil {
ilp := map[string]interface{}{}
ilp["force_update_on_repair"] = instanceLifecyclePolicy.ForceUpdateOnRepair
results = append(results, ilp)
}
return results
}

func flattenStatus(status *compute.InstanceGroupManagerStatus) []map[string]interface{} {
results := []map[string]interface{}{}
data := map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
Description: `The shape to which the group converges either proactively or on resize events (depending on the value set in updatePolicy.instanceRedistributionType).`,
},

"instance_lifecycle_policy": {
Computed: true,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `The instance lifecycle policy for this managed instance group.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"force_update_on_repair": {
Type: schema.TypeString,
Default: "NO",
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"YES", "NO"}, false),
Description: `Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: YES, NO. If YES and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If NO (default), then updates are applied in accordance with the group's update policy type.`,
},
},
},
},

"update_policy": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -433,6 +452,7 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met
AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})),
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandRegionUpdatePolicy(d.Get("update_policy").([]interface{})),
InstanceLifecyclePolicy: expandInstanceLifecyclePolicy(d.Get("instance_lifecycle_policy").([]interface{})),
DistributionPolicy: expandDistributionPolicy(d),
StatefulPolicy: expandStatefulPolicy(d),
// Force send TargetSize to allow size of 0.
Expand Down Expand Up @@ -616,6 +636,9 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta
if err := d.Set("update_policy", flattenRegionUpdatePolicy(manager.UpdatePolicy)); err != nil {
return fmt.Errorf("Error setting update_policy in state: %s", err.Error())
}
if err = d.Set("instance_lifecycle_policy", flattenInstanceLifecyclePolicy(manager.InstanceLifecyclePolicy)); err != nil {
return fmt.Errorf("Error setting instance lifecycle policy in state: %s", err.Error())
}
if err = d.Set("stateful_disk", flattenStatefulPolicy(manager.StatefulPolicy)); err != nil {
return fmt.Errorf("Error setting stateful_disk in state: %s", err.Error())
}
Expand Down Expand Up @@ -677,6 +700,11 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met
change = true
}

if d.HasChange("instance_lifecycle_policy") {
updatedManager.InstanceLifecyclePolicy = expandInstanceLifecyclePolicy(d.Get("instance_lifecycle_policy").([]interface{}))
change = true
}

if d.HasChange("stateful_disk") {
updatedManager.StatefulPolicy = expandStatefulPolicy(d)
change = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ instance_lifecycle_policy {
}
```

* `force_update_on_repair` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: `YES`, `NO`. If `YES` and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If `NO` (default), then updates are applied in accordance with the group's update policy type.
* `force_update_on_repair` - (Optional, (https://terraform.io/docs/providers/google/guides/provider_versions.html)), Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: `YES`, `NO`. If `YES` and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If `NO` (default), then updates are applied in accordance with the group's update policy type.

- - -

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ instance_lifecycle_policy {
}
```

* `force_update_on_repair` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: YES, NO. If YES and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If NO (default), then updates are applied in accordance with the group's update policy type.
* `force_update_on_repair` - (Optional, (https://terraform.io/docs/providers/google/guides/provider_versions.html)), Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: YES, NO. If YES and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If NO (default), then updates are applied in accordance with the group's update policy type.
- - -

<a name="nested_all_instances_config"></a>The `all_instances_config` block supports:
Expand Down