2015-02-16 17:06:23 +01:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-05-11 23:54:47 +02:00
|
|
|
"reflect"
|
|
|
|
"strings"
|
2015-02-16 17:06:23 +01:00
|
|
|
"testing"
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
"google.golang.org/api/compute/v1"
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-02-16 17:06:23 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccInstanceGroupManager_basic(t *testing.T) {
|
2015-07-28 02:47:10 +02:00
|
|
|
var manager compute.InstanceGroupManager
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
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))
|
|
|
|
|
2015-02-16 17:06:23 +01:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccInstanceGroupManager_basic(template, target, igm1, igm2),
|
2015-02-16 17:06:23 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckInstanceGroupManagerExists(
|
2015-07-28 20:09:29 +02:00
|
|
|
"google_compute_instance_group_manager.igm-basic", &manager),
|
2015-07-30 16:46:16 +02:00
|
|
|
testAccCheckInstanceGroupManagerExists(
|
|
|
|
"google_compute_instance_group_manager.igm-no-tp", &manager),
|
2015-02-16 17:06:23 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccInstanceGroupManager_update(t *testing.T) {
|
2015-07-28 02:47:10 +02:00
|
|
|
var manager compute.InstanceGroupManager
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
template1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
|
|
|
target := 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))
|
|
|
|
|
2015-02-16 17:06:23 +01:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccInstanceGroupManager_update(template1, target, igm),
|
2015-02-16 17:06:23 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckInstanceGroupManagerExists(
|
2015-07-28 20:09:29 +02:00
|
|
|
"google_compute_instance_group_manager.igm-update", &manager),
|
2016-01-10 15:09:05 +01:00
|
|
|
testAccCheckInstanceGroupManagerNamedPorts(
|
|
|
|
"google_compute_instance_group_manager.igm-update",
|
|
|
|
map[string]int64{"customhttp": 8080},
|
|
|
|
&manager),
|
2015-02-16 17:06:23 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccInstanceGroupManager_update2(template1, target, template2, igm),
|
2015-02-16 17:06:23 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckInstanceGroupManagerExists(
|
2015-07-28 20:09:29 +02:00
|
|
|
"google_compute_instance_group_manager.igm-update", &manager),
|
2015-02-16 17:06:23 +01:00
|
|
|
testAccCheckInstanceGroupManagerUpdated(
|
2015-07-28 20:09:29 +02:00
|
|
|
"google_compute_instance_group_manager.igm-update", 3,
|
2016-01-06 01:49:06 +01:00
|
|
|
"google_compute_target_pool.igm-update", template2),
|
2016-01-10 15:09:05 +01:00
|
|
|
testAccCheckInstanceGroupManagerNamedPorts(
|
|
|
|
"google_compute_instance_group_manager.igm-update",
|
|
|
|
map[string]int64{"customhttp": 8080, "customhttps": 8443},
|
|
|
|
&manager),
|
2015-02-16 17:06:23 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-11 23:54:47 +02:00
|
|
|
func TestAccInstanceGroupManager_updateLifecycle(t *testing.T) {
|
|
|
|
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: testAccCheckInstanceGroupManagerDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccInstanceGroupManager_updateLifecycle(tag1, igm),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckInstanceGroupManagerExists(
|
|
|
|
"google_compute_instance_group_manager.igm-update", &manager),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccInstanceGroupManager_updateLifecycle(tag2, igm),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckInstanceGroupManagerExists(
|
|
|
|
"google_compute_instance_group_manager.igm-update", &manager),
|
|
|
|
testAccCheckInstanceGroupManagerTemplateTags(
|
|
|
|
"google_compute_instance_group_manager.igm-update", []string{tag2}),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
func testAccCheckInstanceGroupManagerDestroy(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
2015-07-28 02:47:10 +02:00
|
|
|
if rs.Type != "google_compute_instance_group_manager" {
|
2015-02-16 17:06:23 +01:00
|
|
|
continue
|
|
|
|
}
|
2015-07-28 02:47:10 +02:00
|
|
|
_, err := config.clientCompute.InstanceGroupManagers.Get(
|
2015-02-16 17:06:23 +01:00
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
2016-01-04 23:29:31 +01:00
|
|
|
if err == nil {
|
2015-02-16 17:06:23 +01:00
|
|
|
return fmt.Errorf("InstanceGroupManager still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
func testAccCheckInstanceGroupManagerExists(n string, manager *compute.InstanceGroupManager) resource.TestCheckFunc {
|
2015-02-16 17:06:23 +01:00
|
|
|
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)
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
found, err := config.clientCompute.InstanceGroupManagers.Get(
|
2015-02-16 17:06:23 +01:00
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if found.Name != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("InstanceGroupManager not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*manager = *found
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckInstanceGroupManagerUpdated(n string, size int64, targetPool 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)
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
manager, err := config.clientCompute.InstanceGroupManagers.Get(
|
2015-02-16 17:06:23 +01:00
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
// Cannot check the target pool as the instance creation is asynchronous. However, can
|
|
|
|
// check the target_size.
|
|
|
|
if manager.TargetSize != size {
|
2015-02-16 17:06:23 +01:00
|
|
|
return fmt.Errorf("instance count incorrect")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 15:09:05 +01:00
|
|
|
func testAccCheckInstanceGroupManagerNamedPorts(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.InstanceGroupManagers.Get(
|
|
|
|
config.Project, rs.Primary.Attributes["zone"], 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 23:54:47 +02:00
|
|
|
func testAccCheckInstanceGroupManagerTemplateTags(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.InstanceGroupManagers.Get(
|
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that the instance template updated
|
|
|
|
instanceTemplate, err := config.clientCompute.InstanceTemplates.Get(
|
|
|
|
config.Project, resourceSplitter(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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccInstanceGroupManager_basic(template, target, igm1, igm2 string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "igm-basic" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-03-26 17:52:30 +01:00
|
|
|
source_image = "debian-cloud/debian-7-wheezy-v20160301"
|
2016-01-06 01:49:06 +01:00
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_target_pool" "igm-basic" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
name = "%s"
|
|
|
|
session_affinity = "CLIENT_IP_PROTO"
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
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
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_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"
|
|
|
|
zone = "us-central1-c"
|
|
|
|
target_size = 2
|
|
|
|
}
|
|
|
|
`, template, target, igm1, igm2)
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccInstanceGroupManager_update(template, target, igm string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "igm-update" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-03-26 17:52:30 +01:00
|
|
|
source_image = "debian-cloud/debian-7-wheezy-v20160301"
|
2016-01-06 01:49:06 +01:00
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
}
|
2015-07-30 16:46:16 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_target_pool" "igm-update" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
name = "%s"
|
|
|
|
session_affinity = "CLIENT_IP_PROTO"
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_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"
|
|
|
|
zone = "us-central1-c"
|
|
|
|
target_size = 2
|
2016-01-10 15:09:05 +01:00
|
|
|
named_port {
|
|
|
|
name = "customhttp"
|
|
|
|
port = 8080
|
|
|
|
}
|
2016-01-06 01:49:06 +01:00
|
|
|
}`, template, target, igm)
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2015-07-28 20:09:29 +02:00
|
|
|
// Change IGM's instance template and target size
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccInstanceGroupManager_update2(template1, target, template2, igm string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "igm-update" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-03-26 17:52:30 +01:00
|
|
|
source_image = "debian-cloud/debian-7-wheezy-v20160301"
|
2016-01-06 01:49:06 +01:00
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_target_pool" "igm-update" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
name = "%s"
|
|
|
|
session_affinity = "CLIENT_IP_PROTO"
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_instance_template" "igm-update2" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
2015-07-28 20:09:29 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
2016-03-26 17:52:30 +01:00
|
|
|
source_image = "debian-cloud/debian-7-wheezy-v20160301"
|
2016-01-06 01:49:06 +01:00
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_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}"]
|
|
|
|
base_instance_name = "igm-update"
|
|
|
|
zone = "us-central1-c"
|
|
|
|
target_size = 3
|
2016-01-10 15:09:05 +01:00
|
|
|
named_port {
|
|
|
|
name = "customhttp"
|
|
|
|
port = 8080
|
|
|
|
}
|
|
|
|
named_port {
|
|
|
|
name = "customhttps"
|
|
|
|
port = 8443
|
|
|
|
}
|
2016-01-06 01:49:06 +01:00
|
|
|
}`, template1, target, template2, igm)
|
2015-02-16 17:06:23 +01:00
|
|
|
}
|
2016-05-11 23:54:47 +02:00
|
|
|
|
|
|
|
func testAccInstanceGroupManager_updateLifecycle(tag, igm string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "igm-update" {
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["%s"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "debian-cloud/debian-7-wheezy-v20160301"
|
|
|
|
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-update" {
|
|
|
|
description = "Terraform test instance group manager"
|
|
|
|
name = "%s"
|
|
|
|
instance_template = "${google_compute_instance_template.igm-update.self_link}"
|
|
|
|
base_instance_name = "igm-update"
|
|
|
|
zone = "us-central1-c"
|
|
|
|
target_size = 2
|
|
|
|
named_port {
|
|
|
|
name = "customhttp"
|
|
|
|
port = 8080
|
|
|
|
}
|
|
|
|
}`, tag, igm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceSplitter(resource string) string {
|
|
|
|
splits := strings.Split(resource, "/")
|
|
|
|
|
|
|
|
return splits[len(splits)-1]
|
|
|
|
}
|