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

Stateful MIG -> GA #4047

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 0 additions & 2 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8579,7 +8579,6 @@ objects:
- !ruby/object:Api::Resource
name: 'PerInstanceConfig'
base_url: 'projects/{{project}}/zones/{{zone}}/instanceGroupManagers/{{instance_group_manager}}'
min_version: beta
description: |
A config defined for a single managed instance that belongs to an instance group manager. It preserves the instance name
across instance group manager operations and can define stateful disks or metadata that are unique to the instance.
Expand Down Expand Up @@ -8699,7 +8698,6 @@ objects:
- !ruby/object:Api::Resource
name: 'RegionPerInstanceConfig'
base_url: 'projects/{{project}}/regions/{{region}}/instanceGroupManagers/{{region_instance_group_manager}}'
min_version: beta
description: |
A config defined for a single managed instance that belongs to an instance group manager. It preserves the instance name
across instance group manager operations and can define stateful disks or metadata that are unique to the instance.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// <% autogen_exception -%>

package google

import (
Expand Down Expand Up @@ -264,7 +262,6 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
Default: false,
Description: `Whether to wait for all instances to be created/updated before returning. Note that if this is set to true and the operation does not succeed, Terraform will continue trying until it times out.`,
},
<% unless version == 'ga' -%>
"stateful_disk": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -287,7 +284,6 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
},
},
},
<% end -%>
"operation": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -350,9 +346,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{})),
<% unless version == 'ga' -%>
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
<% end -%>
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
// Force send TargetSize to allow a value of 0.
ForceSendFields: []string{"TargetSize"},
}
Expand Down Expand Up @@ -470,7 +464,7 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
if err != nil {
return err
}

project, err := getProject(d, config)
if err != nil {
return err
Expand All @@ -490,7 +484,7 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
err = computeOperationWaitTime(config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate))
if err != nil {
// remove from state to allow refresh to finish
log.Printf("[DEBUG] Resumed operation returned an error, removing from state: %s",err)
log.Printf("[DEBUG] Resumed operation returned an error, removing from state: %s", err)
d.SetId("")
return nil
}
Expand Down Expand Up @@ -530,11 +524,9 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
if err = d.Set("named_port", flattenNamedPortsBeta(manager.NamedPorts)); err != nil {
return fmt.Errorf("Error setting named_port in state: %s", err.Error())
}
<% unless version == 'ga' -%>
if err = d.Set("stateful_disk", flattenStatefulPolicy(manager.StatefulPolicy)); err != nil {
return fmt.Errorf("Error setting stateful_disk in state: %s", err.Error())
}
<% end -%>
if err := d.Set("fingerprint", manager.Fingerprint); err != nil {
return fmt.Errorf("Error setting fingerprint: %s", err)
}
Expand Down Expand Up @@ -615,13 +607,11 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte
change = true
}

<% unless version == 'ga' -%>
if d.HasChange("stateful_disk") {
updatedManager.StatefulPolicy = expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List())
change = true
}

<% end -%>
if change {
op, err := config.NewComputeBetaClient(userAgent).InstanceGroupManagers.Patch(project, zone, d.Get("name").(string), updatedManager).Do()
if err != nil {
Expand Down Expand Up @@ -756,7 +746,6 @@ func expandAutoHealingPolicies(configured []interface{}) []*computeBeta.Instance
return autoHealingPolicies
}

<% unless version == 'ga' -%>
func expandStatefulPolicy(configured []interface{}) *computeBeta.StatefulPolicy {
disks := make(map[string]computeBeta.StatefulPolicyPreservedStateDiskDevice)
for _, raw := range configured {
Expand All @@ -772,7 +761,6 @@ func expandStatefulPolicy(configured []interface{}) *computeBeta.StatefulPolicy
return nil
}

<% end -%>
func expandVersions(configured []interface{}) []*computeBeta.InstanceGroupManagerVersion {
versions := make([]*computeBeta.InstanceGroupManagerVersion, 0, len(configured))
for _, raw := range configured {
Expand Down Expand Up @@ -863,7 +851,6 @@ func flattenAutoHealingPolicies(autoHealingPolicies []*computeBeta.InstanceGroup
return autoHealingPoliciesSchema
}

<% unless version == 'ga' -%>
func flattenStatefulPolicy(statefulPolicy *computeBeta.StatefulPolicy) []map[string]interface{} {
if statefulPolicy == nil || statefulPolicy.PreservedState == nil || statefulPolicy.PreservedState.Disks == nil {
return make([]map[string]interface{}, 0, 0)
Expand All @@ -880,7 +867,6 @@ func flattenStatefulPolicy(statefulPolicy *computeBeta.StatefulPolicy) []map[str
return result
}

<% end -%>
func flattenUpdatePolicy(updatePolicy *computeBeta.InstanceGroupManagerUpdatePolicy) []map[string]interface{} {
results := []map[string]interface{}{}
if updatePolicy != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// <% autogen_exception -%>

package google

import (
Expand Down Expand Up @@ -284,7 +282,6 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
},
},
},
<% unless version == 'ga' -%>

"stateful_disk": {
Type: schema.TypeSet,
Expand All @@ -308,7 +305,6 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
},
},
},
<% end -%>
},
}
}
Expand Down Expand Up @@ -341,9 +337,7 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandRegionUpdatePolicy(d.Get("update_policy").([]interface{})),
DistributionPolicy: expandDistributionPolicy(d.Get("distribution_policy_zones").(*schema.Set)),
<% unless version == 'ga' -%>
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
<% end -%>
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
// Force send TargetSize to allow size of 0.
ForceSendFields: []string{"TargetSize"},
}
Expand Down Expand Up @@ -476,12 +470,10 @@ 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())
}
<% unless version == 'ga' -%>
if err = d.Set("stateful_disk", flattenStatefulPolicy(manager.StatefulPolicy)); err != nil {
return fmt.Errorf("Error setting stateful_disk in state: %s", err.Error())
}

<% end -%>
if d.Get("wait_for_instances").(bool) {
conf := resource.StateChangeConf{
Pending: []string{"creating", "error"},
Expand Down Expand Up @@ -542,13 +534,11 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met
change = true
}

<% unless version == 'ga' -%>
if d.HasChange("stateful_disk") {
updatedManager.StatefulPolicy = expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List())
change = true
}

<% end -%>
if change {
op, err := config.NewComputeBetaClient(userAgent).RegionInstanceGroupManagers.Patch(project, region, d.Get("name").(string), updatedManager).Do()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<% autogen_exception -%>
package google

import (
"context"
"fmt"
"log"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -331,7 +332,6 @@ func TestAccInstanceGroupManager_autoHealingPolicies(t *testing.T) {
})
}

<% unless version == 'ga' -%>
func TestAccInstanceGroupManager_stateful(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -365,7 +365,6 @@ func TestAccInstanceGroupManager_stateful(t *testing.T) {
})
}

<% end -%>
func testAccCheckInstanceGroupManagerDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
config := googleProviderConfig(t)
Expand Down Expand Up @@ -1218,7 +1217,6 @@ resource "google_compute_instance_group_manager" "igm-basic" {
`, primaryTemplate, canaryTemplate, igm)
}

<% unless version == 'ga' -%>
func testAccInstanceGroupManager_stateful(template, target, igm, hck string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down Expand Up @@ -1367,4 +1365,3 @@ resource "google_compute_http_health_check" "zero" {
}
`, template, target, igm, hck)
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<% autogen_exception -%>
package google

<% unless version == 'ga' -%>
import (
"fmt"
"testing"
Expand All @@ -18,12 +16,12 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) {
suffix := randString(t, 10)
igmName := fmt.Sprintf("tf-test-igm-%s", suffix)
context := map[string]interface{}{
"igm_name": igmName,
"igm_name": igmName,
"random_suffix": suffix,
"config_name" : fmt.Sprintf("instance-%s", randString(t, 10)),
"config_name2" : fmt.Sprintf("instance-%s", randString(t, 10)),
"config_name3" : fmt.Sprintf("instance-%s", randString(t, 10)),
"config_name4" : fmt.Sprintf("instance-%s", randString(t, 10)),
"config_name": fmt.Sprintf("instance-%s", randString(t, 10)),
"config_name2": fmt.Sprintf("instance-%s", randString(t, 10)),
"config_name3": fmt.Sprintf("instance-%s", randString(t, 10)),
"config_name4": fmt.Sprintf("instance-%s", randString(t, 10)),
}
igmId := fmt.Sprintf("projects/%s/zones/%s/instanceGroupManagers/%s",
getTestProjectFromEnv(), "us-central1-c", igmName)
Expand All @@ -37,9 +35,9 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) {
Config: testAccComputePerInstanceConfig_statefulBasic(context),
},
{
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"},
},
{
Expand All @@ -50,19 +48,19 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) {
),
},
{
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"},
},
{
// Add two new endpoints
Config: testAccComputePerInstanceConfig_statefulAdditional(context),
},
{
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"},
},
{
Expand All @@ -72,9 +70,9 @@ func TestAccComputePerInstanceConfig_statefulBasic(t *testing.T) {
ImportStateVerifyIgnore: []string{"most_disruptive_allowed_action", "minimal_action", "remove_instance_state_on_destroy"},
},
{
ResourceName: "google_compute_per_instance_config.add2",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_compute_per_instance_config.add2",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"},
},
{
Expand All @@ -95,8 +93,8 @@ func TestAccComputePerInstanceConfig_update(t *testing.T) {

context := map[string]interface{}{
"random_suffix": randString(t, 10),
"igm_name": fmt.Sprintf("tf-test-igm-%s", randString(t, 10)),
"config_name" : fmt.Sprintf("instance-%s", randString(t, 10)),
"igm_name": fmt.Sprintf("tf-test-igm-%s", randString(t, 10)),
"config_name": fmt.Sprintf("instance-%s", randString(t, 10)),
}

vcrTest(t, resource.TestCase{
Expand All @@ -108,19 +106,19 @@ func TestAccComputePerInstanceConfig_update(t *testing.T) {
Config: testAccComputePerInstanceConfig_statefulBasic(context),
},
{
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"},
},
{
// Update an existing config
Config: testAccComputePerInstanceConfig_update(context),
},
{
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_compute_per_instance_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_instance_state_on_destroy"},
},
},
Expand Down Expand Up @@ -336,4 +334,3 @@ func testAccComputePerInstanceConfigListNames(t *testing.T, igmId string) (map[s
}
return instanceConfigs, nil
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% autogen_exception -%>

package google

import (
"context"
"fmt"
"log"
"strings"
"testing"

Expand Down Expand Up @@ -343,7 +343,6 @@ func TestAccRegionInstanceGroupManager_distributionPolicy(t *testing.T) {
})
}

<% unless version == 'ga' -%>
func TestAccRegionInstanceGroupManager_stateful(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -375,7 +374,6 @@ func TestAccRegionInstanceGroupManager_stateful(t *testing.T) {
})
}

<% end -%>
func testAccCheckRegionInstanceGroupManagerDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
config := googleProviderConfig(t)
Expand Down Expand Up @@ -1233,7 +1231,6 @@ resource "google_compute_region_instance_group_manager" "igm-rolling-update-poli
`, igm)
}

<% unless version == 'ga' -%>
func testAccRegionInstanceGroupManager_stateful(template, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down Expand Up @@ -1350,4 +1347,3 @@ resource "google_compute_region_instance_group_manager" "igm-basic" {
}
`, template, igm)
}
<% end -%>
Loading