mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
1321 lines
38 KiB
Go
1321 lines
38 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
computeBeta "google.golang.org/api/compute/v0.beta"
|
|
"google.golang.org/api/compute/v1"
|
|
|
|
"sort"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccRegionInstanceGroupManager_basic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager compute.InstanceGroupManager
|
|
|
|
template := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
target := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
igm1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
igm2 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckRegionInstanceGroupManagerDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_basic(template, target, igm1, igm2),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-basic", &manager),
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-no-tp", &manager),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_targetSizeZero(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager compute.InstanceGroupManager
|
|
|
|
templateName := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
igmName := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckRegionInstanceGroupManagerDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_targetSizeZero(templateName, igmName),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-basic", &manager),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
|
|
if manager.TargetSize != 0 {
|
|
t.Errorf("Expected target_size to be 0, got %d", manager.TargetSize)
|
|
}
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_update(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager compute.InstanceGroupManager
|
|
|
|
template1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
target1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
target2 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
template2 := 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{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_update(template1, target1, igm),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-update", &manager),
|
|
testAccCheckRegionInstanceGroupManagerNamedPorts(
|
|
"google_compute_region_instance_group_manager.igm-update",
|
|
map[string]int64{"customhttp": 8080},
|
|
&manager),
|
|
),
|
|
},
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_update2(template1, target1, target2, template2, igm),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-update", &manager),
|
|
testAccCheckRegionInstanceGroupManagerUpdated(
|
|
"google_compute_region_instance_group_manager.igm-update", 3,
|
|
[]string{target1, target2}, template2),
|
|
testAccCheckRegionInstanceGroupManagerNamedPorts(
|
|
"google_compute_region_instance_group_manager.igm-update",
|
|
map[string]int64{"customhttp": 8080, "customhttps": 8443},
|
|
&manager),
|
|
),
|
|
},
|
|
resource.TestStep{
|
|
ResourceName: "google_compute_region_instance_group_manager.igm-update",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
ImportStateVerifyIgnore: []string{"update_strategy"},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_updateLifecycle(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager compute.InstanceGroupManager
|
|
|
|
tag1 := "tag1"
|
|
tag2 := "tag2"
|
|
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{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_updateLifecycle(tag1, igm),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-update", &manager),
|
|
),
|
|
},
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_updateLifecycle(tag2, igm),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-update", &manager),
|
|
testAccCheckRegionInstanceGroupManagerTemplateTags(
|
|
"google_compute_region_instance_group_manager.igm-update", []string{tag2}),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_updateStrategy(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager compute.InstanceGroupManager
|
|
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{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_updateStrategy(igm),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-update-strategy", &manager),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-update-strategy", "update_strategy", "NONE"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_rollingUpdatePolicy(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager computeBeta.InstanceGroupManager
|
|
|
|
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),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerBetaExists(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", &manager),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "update_strategy", "ROLLING_UPDATE"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.type", "PROACTIVE"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.minimal_action", "REPLACE"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.max_surge_fixed", "2"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.max_unavailable_fixed", "2"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.min_ready_sec", "20"),
|
|
),
|
|
},
|
|
{
|
|
Config: testAccRegionInstanceGroupManager_rollingUpdatePolicy2(igm),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerBetaExists(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", &manager),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "update_strategy", "ROLLING_UPDATE"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.type", "PROACTIVE"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.minimal_action", "REPLACE"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.max_surge_fixed", "2"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.max_unavailable_fixed", "0"),
|
|
resource.TestCheckResourceAttr(
|
|
"google_compute_region_instance_group_manager.igm-rolling-update-policy", "rolling_update_policy.0.min_ready_sec", "10"),
|
|
testAccCheckInstanceGroupManagerRollingUpdatePolicy(
|
|
&manager, "google_compute_region_instance_group_manager.igm-rolling-update-policy"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_separateRegions(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager compute.InstanceGroupManager
|
|
|
|
igm1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
igm2 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckRegionInstanceGroupManagerDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_separateRegions(igm1, igm2),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-basic", &manager),
|
|
testAccCheckRegionInstanceGroupManagerExists(
|
|
"google_compute_region_instance_group_manager.igm-basic-2", &manager),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_versions(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager computeBeta.InstanceGroupManager
|
|
|
|
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{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_versions(primaryTemplate, canaryTemplate, igm),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerBetaExists("google_compute_region_instance_group_manager.igm-basic", &manager),
|
|
testAccCheckRegionInstanceGroupManagerVersions("google_compute_region_instance_group_manager.igm-basic", primaryTemplate, canaryTemplate),
|
|
),
|
|
},
|
|
resource.TestStep{
|
|
ResourceName: "google_compute_region_instance_group_manager.igm-basic",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_autoHealingPolicies(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager computeBeta.InstanceGroupManager
|
|
|
|
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{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_autoHealingPolicies(template, target, igm, hck),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerBetaExists(
|
|
"google_compute_region_instance_group_manager.igm-basic", &manager),
|
|
testAccCheckRegionInstanceGroupManagerAutoHealingPolicies("google_compute_region_instance_group_manager.igm-basic", hck, 10),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccRegionInstanceGroupManager_distributionPolicy(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var manager computeBeta.InstanceGroupManager
|
|
|
|
template := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
zones := []string{"us-central1-a", "us-central1-b"}
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckRegionInstanceGroupManagerDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccRegionInstanceGroupManager_distributionPolicy(template, igm, zones),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckRegionInstanceGroupManagerBetaExists(
|
|
"google_compute_region_instance_group_manager.igm-basic", &manager),
|
|
testAccCheckRegionInstanceGroupManagerDistributionPolicy("google_compute_region_instance_group_manager.igm-basic", zones),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerDestroy(s *terraform.State) error {
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "google_compute_region_instance_group_manager" {
|
|
continue
|
|
}
|
|
_, err := config.clientCompute.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err == nil {
|
|
return fmt.Errorf("RegionInstanceGroupManager still exists")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerExists(n string, manager *compute.InstanceGroupManager) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
found, err := config.clientCompute.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if found.Name != rs.Primary.ID {
|
|
return fmt.Errorf("RegionInstanceGroupManager not found")
|
|
}
|
|
|
|
*manager = *found
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerBetaExists(n string, manager *computeBeta.InstanceGroupManager) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
found, err := config.clientComputeBeta.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if found.Name != rs.Primary.ID {
|
|
return fmt.Errorf("RegionInstanceGroupManager not found")
|
|
}
|
|
|
|
*manager = *found
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerUpdated(n string, size int64, targetPools []string, template string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
manager, err := config.clientCompute.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Cannot check the target pool as the instance creation is asynchronous. However, can
|
|
// check the target_size.
|
|
if manager.TargetSize != size {
|
|
return fmt.Errorf("instance count incorrect")
|
|
}
|
|
|
|
tpNames := make([]string, 0, len(manager.TargetPools))
|
|
for _, targetPool := range manager.TargetPools {
|
|
tpNames = append(tpNames, GetResourceNameFromSelfLink(targetPool))
|
|
}
|
|
|
|
sort.Strings(tpNames)
|
|
sort.Strings(targetPools)
|
|
if !reflect.DeepEqual(tpNames, targetPools) {
|
|
return fmt.Errorf("target pools incorrect. Expected %s, got %s", targetPools, tpNames)
|
|
}
|
|
|
|
// check that the instance template updated
|
|
instanceTemplate, err := config.clientCompute.InstanceTemplates.Get(
|
|
config.Project, template).Do()
|
|
if err != nil {
|
|
return fmt.Errorf("Error reading instance template: %s", err)
|
|
}
|
|
|
|
if instanceTemplate.Name != template {
|
|
return fmt.Errorf("instance template not updated")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerNamedPorts(n string, np map[string]int64, instanceGroupManager *compute.InstanceGroupManager) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
manager, err := config.clientCompute.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var found bool
|
|
for _, namedPort := range manager.NamedPorts {
|
|
found = false
|
|
for name, port := range np {
|
|
if namedPort.Name == name && namedPort.Port == port {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
return fmt.Errorf("named port incorrect")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerVersions(n string, primaryTemplate string, canaryTemplate string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
manager, err := config.clientComputeBeta.RegionInstanceGroupManagers.Get(config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(manager.Versions) != 2 {
|
|
return fmt.Errorf("Expected # of versions to be 2, got %d", len(manager.Versions))
|
|
}
|
|
|
|
primaryVersion := manager.Versions[0]
|
|
if !strings.Contains(primaryVersion.InstanceTemplate, primaryTemplate) {
|
|
return fmt.Errorf("Expected string \"%s\" to appear in \"%s\"", primaryTemplate, primaryVersion.InstanceTemplate)
|
|
}
|
|
|
|
canaryVersion := manager.Versions[1]
|
|
if !strings.Contains(canaryVersion.InstanceTemplate, canaryTemplate) {
|
|
return fmt.Errorf("Expected string \"%s\" to appear in \"%s\"", canaryTemplate, canaryVersion.InstanceTemplate)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerAutoHealingPolicies(n, hck string, initialDelaySec int64) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
manager, err := config.clientComputeBeta.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(manager.AutoHealingPolicies) != 1 {
|
|
return fmt.Errorf("Expected # of auto healing policies to be 1, got %d", len(manager.AutoHealingPolicies))
|
|
}
|
|
autoHealingPolicy := manager.AutoHealingPolicies[0]
|
|
|
|
if !strings.Contains(autoHealingPolicy.HealthCheck, hck) {
|
|
return fmt.Errorf("Expected string \"%s\" to appear in \"%s\"", hck, autoHealingPolicy.HealthCheck)
|
|
}
|
|
|
|
if autoHealingPolicy.InitialDelaySec != initialDelaySec {
|
|
return fmt.Errorf("Expected auto healing policy inital delay to be %d, got %d", initialDelaySec, autoHealingPolicy.InitialDelaySec)
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerDistributionPolicy(n string, zones []string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
manager, err := config.clientComputeBeta.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if manager.DistributionPolicy == nil {
|
|
return fmt.Errorf("Expected distribution policy to exist")
|
|
}
|
|
|
|
zoneConfigs := manager.DistributionPolicy.Zones
|
|
if len(zoneConfigs) != len(zones) {
|
|
return fmt.Errorf("Expected number of zones in distribution policy to match; had %d, expected %d", len(zoneConfigs), len(zones))
|
|
}
|
|
|
|
sort.Strings(zones)
|
|
sortedExisting := make([]string, 0)
|
|
for _, zone := range zoneConfigs {
|
|
sortedExisting = append(sortedExisting, zone.Zone)
|
|
}
|
|
sort.Strings(sortedExisting)
|
|
|
|
for i := 0; i < len(zones); i++ {
|
|
if !strings.HasSuffix(sortedExisting[i], zones[i]) {
|
|
return fmt.Errorf("found mismatched zone configuration: expected entry #%d as '%s', got %s", i, zones[i], sortedExisting[i])
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckRegionInstanceGroupManagerTemplateTags(n string, tags []string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
manager, err := config.clientCompute.RegionInstanceGroupManagers.Get(
|
|
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// check that the instance template updated
|
|
instanceTemplate, err := config.clientCompute.InstanceTemplates.Get(
|
|
config.Project, GetResourceNameFromSelfLink(manager.InstanceTemplate)).Do()
|
|
if err != nil {
|
|
return fmt.Errorf("Error reading instance template: %s", err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(instanceTemplate.Properties.Tags.Items, tags) {
|
|
return fmt.Errorf("instance template not updated")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccRegionInstanceGroupManager_basic(template, target, igm1, igm2 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
|
|
}
|
|
|
|
resource "google_compute_region_instance_group_manager" "igm-no-tp" {
|
|
description = "Terraform test instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-basic.self_link}"
|
|
base_instance_name = "igm-no-tp"
|
|
region = "us-central1"
|
|
target_size = 2
|
|
}
|
|
`, template, target, igm1, igm2)
|
|
}
|
|
|
|
func testAccRegionInstanceGroupManager_targetSizeZero(template, igm 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_region_instance_group_manager" "igm-basic" {
|
|
description = "Terraform test instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-basic.self_link}"
|
|
base_instance_name = "igm-basic"
|
|
region = "us-central1"
|
|
}
|
|
`, template, igm)
|
|
}
|
|
|
|
func testAccRegionInstanceGroupManager_update(template, target, igm string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_compute_image" "my_image" {
|
|
family = "debian-9"
|
|
project = "debian-cloud"
|
|
}
|
|
|
|
resource "google_compute_instance_template" "igm-update" {
|
|
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-update" {
|
|
description = "Resource created for Terraform acceptance testing"
|
|
name = "%s"
|
|
session_affinity = "CLIENT_IP_PROTO"
|
|
}
|
|
|
|
resource "google_compute_region_instance_group_manager" "igm-update" {
|
|
description = "Terraform test instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-update.self_link}"
|
|
target_pools = ["${google_compute_target_pool.igm-update.self_link}"]
|
|
base_instance_name = "igm-update"
|
|
region = "us-central1"
|
|
target_size = 2
|
|
named_port {
|
|
name = "customhttp"
|
|
port = 8080
|
|
}
|
|
}`, template, target, igm)
|
|
}
|
|
|
|
// Change IGM's instance template and target size
|
|
func testAccRegionInstanceGroupManager_update2(template1, target1, target2, template2, igm string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_compute_image" "my_image" {
|
|
family = "debian-9"
|
|
project = "debian-cloud"
|
|
}
|
|
|
|
resource "google_compute_instance_template" "igm-update" {
|
|
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-update" {
|
|
description = "Resource created for Terraform acceptance testing"
|
|
name = "%s"
|
|
session_affinity = "CLIENT_IP_PROTO"
|
|
}
|
|
|
|
resource "google_compute_target_pool" "igm-update2" {
|
|
description = "Resource created for Terraform acceptance testing"
|
|
name = "%s"
|
|
session_affinity = "CLIENT_IP_PROTO"
|
|
}
|
|
|
|
resource "google_compute_instance_template" "igm-update2" {
|
|
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-update" {
|
|
description = "Terraform test instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-update2.self_link}"
|
|
target_pools = [
|
|
"${google_compute_target_pool.igm-update.self_link}",
|
|
"${google_compute_target_pool.igm-update2.self_link}",
|
|
]
|
|
base_instance_name = "igm-update"
|
|
region = "us-central1"
|
|
target_size = 3
|
|
named_port {
|
|
name = "customhttp"
|
|
port = 8080
|
|
}
|
|
named_port {
|
|
name = "customhttps"
|
|
port = 8443
|
|
}
|
|
}`, template1, target1, target2, template2, igm)
|
|
}
|
|
|
|
func testAccRegionInstanceGroupManager_updateLifecycle(tag, igm string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_compute_image" "my_image" {
|
|
family = "debian-9"
|
|
project = "debian-cloud"
|
|
}
|
|
|
|
resource "google_compute_instance_template" "igm-update" {
|
|
machine_type = "n1-standard-1"
|
|
can_ip_forward = false
|
|
tags = ["%s"]
|
|
|
|
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-update" {
|
|
description = "Terraform test instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-update.self_link}"
|
|
base_instance_name = "igm-update"
|
|
region = "us-central1"
|
|
target_size = 2
|
|
named_port {
|
|
name = "customhttp"
|
|
port = 8080
|
|
}
|
|
}`, tag, igm)
|
|
}
|
|
|
|
func testAccRegionInstanceGroupManager_separateRegions(igm1, igm2 string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_compute_image" "my_image" {
|
|
family = "debian-9"
|
|
project = "debian-cloud"
|
|
}
|
|
|
|
resource "google_compute_instance_template" "igm-basic" {
|
|
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 instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-basic.self_link}"
|
|
base_instance_name = "igm-basic"
|
|
region = "us-central1"
|
|
target_size = 2
|
|
}
|
|
|
|
resource "google_compute_region_instance_group_manager" "igm-basic-2" {
|
|
description = "Terraform test instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-basic.self_link}"
|
|
base_instance_name = "igm-basic-2"
|
|
region = "us-west1"
|
|
target_size = 2
|
|
}
|
|
`, 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" {
|
|
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"
|
|
}
|
|
}
|
|
|
|
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}"
|
|
base_instance_name = "igm-basic"
|
|
region = "us-central1"
|
|
target_size = 2
|
|
distribution_policy_zones = ["%s"]
|
|
}
|
|
`, template, igm, strings.Join(zones, "\",\""))
|
|
}
|
|
|
|
func testAccRegionInstanceGroupManager_updateStrategy(igm string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_compute_image" "my_image" {
|
|
family = "debian-9"
|
|
project = "debian-cloud"
|
|
}
|
|
|
|
resource "google_compute_instance_template" "igm-update-strategy" {
|
|
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-update-strategy" {
|
|
description = "Terraform test instance group manager"
|
|
name = "%s"
|
|
instance_template = "${google_compute_instance_template.igm-update-strategy.self_link}"
|
|
base_instance_name = "rigm-update-strategy"
|
|
region = "us-central1"
|
|
target_size = 2
|
|
update_strategy = "NONE"
|
|
named_port {
|
|
name = "customhttp"
|
|
port = 8080
|
|
}
|
|
}`, 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)
|
|
}
|