Skip to content

Commit

Permalink
Promote (R)IGM.AllInstancesConfig to V1 (GoogleCloudPlatform#9964)
Browse files Browse the repository at this point in the history
  • Loading branch information
askubis authored Feb 26, 2024
1 parent b361a7b commit 14a4129
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
},
},

<% unless version == "ga" -%>
"all_instances_config": {
Type: schema.TypeList,
Optional: true,
Expand All @@ -341,7 +340,6 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
},
},
},
<% end -%>
"wait_for_instances": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -353,12 +351,7 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
Optional: true,
Default: "STABLE",
ValidateFunc: validation.StringInSlice([]string{"STABLE", "UPDATED"}, false),

<% if version == "ga" -%>
Description: `When used with wait_for_instances specifies the status to wait for. When STABLE is specified this resource will wait until the instances are stable before returning. When UPDATED is set, it will wait for the version target to be reached and any per instance configs to be effective as well as all instances to be stable before returning.`,
<% else -%>
Description: `When used with wait_for_instances specifies the status to wait for. When STABLE is specified this resource will wait until the instances are stable before returning. When UPDATED is set, it will wait for the version target to be reached and any per instance configs to be effective and all instances configs to be effective as well as all instances to be stable before returning.`,
<% end -%>
},
"stateful_internal_ip": {
Type: schema.TypeList,
Expand Down Expand Up @@ -454,7 +447,6 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
},
},
},
<% unless version == "ga" -%>
"all_instances_config": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -469,7 +461,6 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
},
},
},
<% end -%>
"stateful": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -589,9 +580,7 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandUpdatePolicy(d.Get("update_policy").([]interface{})),
InstanceLifecyclePolicy: expandInstanceLifecyclePolicy(d.Get("instance_lifecycle_policy").([]interface{})),
<% unless version == "ga" -%>
AllInstancesConfig: expandAllInstancesConfig(nil, d.Get("all_instances_config").([]interface{})),
<% end -%>
StatefulPolicy: expandStatefulPolicy(d),

// Force send TargetSize to allow a value of 0.
Expand Down Expand Up @@ -815,13 +804,11 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
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())
}
<% unless version == "ga" -%>
if manager.AllInstancesConfig != nil {
if err = d.Set("all_instances_config", flattenAllInstancesConfig(manager.AllInstancesConfig)); err != nil {
return fmt.Errorf("Error setting all_instances_config in state: %s", err.Error())
}
}
<% end -%>
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 @@ -892,7 +879,6 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte
change = true
}

<% unless version == "ga" -%>
if d.HasChange("all_instances_config") {
oldAic, newAic := d.GetChange("all_instances_config")
if newAic == nil || len(newAic.([]interface{})) == 0 {
Expand All @@ -902,7 +888,6 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte
}
change = true
}
<% end -%>

if d.HasChange("stateful_internal_ip") || d.HasChange("stateful_external_ip") || d.HasChange("stateful_disk") {
updatedManager.StatefulPolicy = expandStatefulPolicy(d)
Expand Down Expand Up @@ -1045,11 +1030,7 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte
func computeIGMWaitForInstanceStatus(d *schema.ResourceData, meta interface{}) error {
waitForUpdates := d.Get("wait_for_instances_status").(string) == "UPDATED"
conf := resource.StateChangeConf{
<% if version == "ga" -%>
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target"},
<% else -%>
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target", "updating all instances config"},
<% end -%>
Target: []string{"created"},
Refresh: waitForInstancesRefreshFunc(getManager, waitForUpdates, d, meta),
Timeout: d.Timeout(schema.TimeoutCreate),
Expand Down Expand Up @@ -1400,7 +1381,6 @@ func flattenInstanceLifecyclePolicy(instanceLifecyclePolicy *compute.InstanceGro
return results
}

<% unless version == "ga" -%>
func expandAllInstancesConfig(old []interface{}, new []interface{}) *compute.InstanceGroupManagerAllInstancesConfig {
var properties *compute.InstancePropertiesPatch
for _, raw := range new {
Expand Down Expand Up @@ -1456,7 +1436,6 @@ func flattenAllInstancesConfig(allInstancesConfig *compute.InstanceGroupManagerA
results = append(results, props)
return results
}
<% end -%>

func flattenStatus(status *compute.InstanceGroupManagerStatus) []map[string]interface{} {
results := []map[string]interface{}{}
Expand All @@ -1465,11 +1444,9 @@ func flattenStatus(status *compute.InstanceGroupManagerStatus) []map[string]inte
"stateful": flattenStatusStateful(status.Stateful),
"version_target": flattenStatusVersionTarget(status.VersionTarget),
}
<% unless version == "ga" -%>
if status.AllInstancesConfig != nil {
data["all_instances_config"] = flattenStatusAllInstancesConfig(status.AllInstancesConfig)
}
<% end -%>
results = append(results, data)
return results
}
Expand Down Expand Up @@ -1502,7 +1479,6 @@ func flattenStatusVersionTarget(versionTarget *compute.InstanceGroupManagerStatu
return results
}

<% unless version == "ga" -%>
func flattenStatusAllInstancesConfig(allInstancesConfig *compute.InstanceGroupManagerStatusAllInstancesConfig) []map[string]interface{} {
results := []map[string]interface{}{}
data := map[string]interface{}{
Expand All @@ -1511,7 +1487,6 @@ func flattenStatusAllInstancesConfig(allInstancesConfig *compute.InstanceGroupMa
results = append(results, data)
return results
}
<% end -%>

func resourceInstanceGroupManagerStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
if err := d.Set("wait_for_instances", false); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ resource "google_compute_instance_group_manager" "igm-update" {
name = "customhttp"
port = 8080
}
<% unless version == "ga" -%>
all_instances_config {
metadata = {
foo = "bar"
Expand All @@ -669,7 +668,6 @@ resource "google_compute_instance_group_manager" "igm-update" {
doo = "dad"
}
}
<% end -%>

instance_lifecycle_policy {
force_update_on_repair = "YES"
Expand Down Expand Up @@ -766,7 +764,6 @@ resource "google_compute_instance_group_manager" "igm-update" {
port = 8443
}

<% unless version == "ga" -%>
all_instances_config {
metadata = {
doo = "dad"
Expand All @@ -775,7 +772,6 @@ resource "google_compute_instance_group_manager" "igm-update" {
foo = "bar"
}
}
<% end -%>

instance_lifecycle_policy {
force_update_on_repair = "NO"
Expand Down Expand Up @@ -1780,7 +1776,6 @@ resource "google_compute_instance_group_manager" "igm-basic" {
max_surge_fixed = 0
max_unavailable_percent = 50
}
<% unless version == "ga" -%>
all_instances_config {
metadata = {
doo = "dad"
Expand All @@ -1789,7 +1784,6 @@ resource "google_compute_instance_group_manager" "igm-basic" {
foo = "bar"
}
}
<% end -%>
instance_lifecycle_policy {
force_update_on_repair = "YES"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,7 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
Optional: true,
Default: "STABLE",
ValidateFunc: validation.StringInSlice([]string{"STABLE", "UPDATED"}, false),

<% if version == "ga" -%>
Description: `When used with wait_for_instances specifies the status to wait for. When STABLE is specified this resource will wait until the instances are stable before returning. When UPDATED is set, it will wait for the version target to be reached and any per instance configs to be effective as well as all instances to be stable before returning.`,
<% else -%>
Description: `When used with wait_for_instances specifies the status to wait for. When STABLE is specified this resource will wait until the instances are stable before returning. When UPDATED is set, it will wait for the version target to be reached and any per instance configs to be effective and all instances configs to be effective as well as all instances to be stable before returning.`,
<% end -%>
},

"auto_healing_policies": {
Expand Down Expand Up @@ -365,7 +360,6 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
},
},
},
<% unless version == "ga" -%>
"all_instances_config": {
Type: schema.TypeList,
Optional: true,
Expand All @@ -390,7 +384,6 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
},
},
},
<% end -%>
"stateful_internal_ip": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -481,7 +474,6 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
},
},
},
<% unless version == "ga" -%>
"all_instances_config": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -496,7 +488,6 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
},
},
},
<% end -%>
"stateful": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -562,9 +553,7 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandRegionUpdatePolicy(d.Get("update_policy").([]interface{})),
InstanceLifecyclePolicy: expandInstanceLifecyclePolicy(d.Get("instance_lifecycle_policy").([]interface{})),
<% unless version == "ga" -%>
AllInstancesConfig: expandAllInstancesConfig(nil, d.Get("all_instances_config").([]interface{})),
<% end -%>
DistributionPolicy: expandDistributionPolicy(d),
StatefulPolicy: expandStatefulPolicy(d),
// Force send TargetSize to allow size of 0.
Expand Down Expand Up @@ -602,11 +591,7 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met
func computeRIGMWaitForInstanceStatus(d *schema.ResourceData, meta interface{}) error {
waitForUpdates := d.Get("wait_for_instances_status").(string) == "UPDATED"
conf := resource.StateChangeConf{
<% if version == "ga" -%>
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target"},
<% else -%>
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target", "updating all instances config"},
<% end -%>
Target: []string{"created"},
Refresh: waitForInstancesRefreshFunc(getRegionalManager, waitForUpdates, d, meta),
Timeout: d.Timeout(schema.TimeoutCreate),
Expand Down Expand Up @@ -674,11 +659,9 @@ func waitForInstancesRefreshFunc(f getInstanceManagerFunc, waitForUpdates bool,
if !m.Status.VersionTarget.IsReached {
return false, "reaching version target", nil
}
<% unless version == "ga" -%>
if !m.Status.AllInstancesConfig.Effective {
return false, "updating all instances config", nil
}
<% end -%>
}
return true, "created", nil
} else {
Expand Down Expand Up @@ -763,13 +746,11 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta
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())
}
<% unless version == "ga" -%>
if manager.AllInstancesConfig != nil {
if err = d.Set("all_instances_config", flattenAllInstancesConfig(manager.AllInstancesConfig)); err != nil {
return fmt.Errorf("Error setting all_instances_config in state: %s", err.Error())
}
}
<% end -%>
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 @@ -852,7 +833,6 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met
change = true
}

<% unless version == "ga" -%>
if d.HasChange("all_instances_config") {
oldAic, newAic := d.GetChange("all_instances_config")
if newAic == nil || len(newAic.([]interface{})) == 0 {
Expand All @@ -862,7 +842,6 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met
}
change = true
}
<% end -%>

if d.HasChange("list_managed_instances_results") {
updatedManager.ListManagedInstancesResults = d.Get("list_managed_instances_results").(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
port = 8080
}

<% unless version == "ga" -%>
all_instances_config {
metadata = {
foo = "bar"
Expand All @@ -571,7 +570,6 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
doo = "dad"
}
}
<% end -%>

instance_lifecycle_policy {
force_update_on_repair = "YES"
Expand Down Expand Up @@ -668,7 +666,6 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
port = 8443
}

<% unless version == "ga" -%>
all_instances_config {
metadata = {
doo = "dad"
Expand All @@ -677,7 +674,6 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
foo = "bar"
}
}
<% end -%>

instance_lifecycle_policy {
force_update_on_repair = "NO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ The following arguments are supported:
* `auto_healing_policies` - (Optional) The autohealing policies for this managed instance
group. You can specify only one value. Structure is [documented below](#nested_auto_healing_policies). For more information, see the [official documentation](https://cloud.google.com/compute/docs/instance-groups/creating-groups-of-managed-instances#monitoring_groups).

* `all_instances_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
* `all_instances_config` - (Optional)
Properties to set on all instances in the group. After setting
allInstancesConfig on the group, you must update the group's instances to
apply the configuration.
Expand Down Expand Up @@ -226,9 +226,9 @@ all_instances_config {
}
```

* `metadata` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), The metadata key-value pairs that you want to patch onto the instance. For more information, see [Project and instance metadata](https://cloud.google.com/compute/docs/metadata#project_and_instance_metadata).
* `metadata` - (Optional), The metadata key-value pairs that you want to patch onto the instance. For more information, see [Project and instance metadata](https://cloud.google.com/compute/docs/metadata#project_and_instance_metadata).

* `labels` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), The label key-value pairs that you want to patch onto the instance.
* `labels` - (Optional), The label key-value pairs that you want to patch onto the instance.

- - -

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ The following arguments are supported:
* `auto_healing_policies` - (Optional) The autohealing policies for this managed instance
group. You can specify only one value. Structure is documented below. For more information, see the [official documentation](https://cloud.google.com/compute/docs/instance-groups/creating-groups-of-managed-instances#monitoring_groups).

* `all_instances_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
* `all_instances_config` - (Optional)
Properties to set on all instances in the group. After setting
allInstancesConfig on the group, you must update the group's instances to
apply the configuration.
Expand Down Expand Up @@ -235,9 +235,9 @@ all_instances_config {
}
```

* `metadata` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), The metadata key-value pairs that you want to patch onto the instance. For more information, see [Project and instance metadata](https://cloud.google.com/compute/docs/metadata#project_and_instance_metadata).
* `metadata` - (Optional), The metadata key-value pairs that you want to patch onto the instance. For more information, see [Project and instance metadata](https://cloud.google.com/compute/docs/metadata#project_and_instance_metadata).

* `labels` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), The label key-value pairs that you want to patch onto the instance.
* `labels` - (Optional), The label key-value pairs that you want to patch onto the instance.

- - -

Expand Down

0 comments on commit 14a4129

Please sign in to comment.