terraform-provider-google/google/resource_compute_instance_group_manager_test.go

1002 lines
25 KiB
Go
Raw Normal View History

2015-02-16 16:06:23 +00:00
package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
2015-02-16 16:06:23 +00:00
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccInstanceGroupManager_basic(t *testing.T) {
t.Parallel()
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 16:06:23 +00:00
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupManager_basic(template, target, igm1, igm2),
2015-02-16 16:06:23 +00:00
},
{
ResourceName: "google_compute_instance_group_manager.igm-basic",
ImportState: true,
ImportStateVerify: true,
},
{
ResourceName: "google_compute_instance_group_manager.igm-no-tp",
ImportState: true,
ImportStateVerify: true,
},
2015-02-16 16:06:23 +00:00
},
})
}
func TestAccInstanceGroupManager_targetSizeZero(t *testing.T) {
t.Parallel()
2017-06-16 22:39:44 +00:00
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: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
{
2017-06-16 22:39:44 +00:00
Config: testAccInstanceGroupManager_targetSizeZero(templateName, igmName),
},
{
ResourceName: "google_compute_instance_group_manager.igm-basic",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
2015-02-16 16:06:23 +00:00
func TestAccInstanceGroupManager_update(t *testing.T) {
t.Parallel()
template1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
2017-09-14 00:06:07 +00:00
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))
2015-02-16 16:06:23 +00:00
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
{
2017-09-14 00:06:07 +00:00
Config: testAccInstanceGroupManager_update(template1, target1, igm),
2015-02-16 16:06:23 +00:00
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
ImportState: true,
ImportStateVerify: true,
},
{
2017-09-14 00:06:07 +00:00
Config: testAccInstanceGroupManager_update2(template1, target1, target2, template2, igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
ImportState: true,
ImportStateVerify: true,
2015-02-16 16:06:23 +00:00
},
},
})
}
func TestAccInstanceGroupManager_updateLifecycle(t *testing.T) {
t.Parallel()
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{
{
Config: testAccInstanceGroupManager_updateLifecycle(tag1, igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccInstanceGroupManager_updateLifecycle(tag2, igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccInstanceGroupManager_updateStrategy(t *testing.T) {
t.Parallel()
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: testAccInstanceGroupManager_updateStrategy(igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update-strategy",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccInstanceGroupManager_rollingUpdatePolicy(t *testing.T) {
t.Parallel()
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: testAccInstanceGroupManager_rollingUpdatePolicy(igm),
},
// No import step because rolling updates are broken and the field will be removed in 2.0.0.
// TODO(danawillow): Remove this test once we've removed the field.
{
Config: testAccInstanceGroupManager_rollingUpdatePolicy2(igm),
},
},
})
}
func TestAccInstanceGroupManager_separateRegions(t *testing.T) {
t.Parallel()
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: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupManager_separateRegions(igm1, igm2),
},
{
ResourceName: "google_compute_instance_group_manager.igm-basic",
ImportState: true,
ImportStateVerify: true,
},
{
ResourceName: "google_compute_instance_group_manager.igm-basic-2",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Implement multiple version in instance group manager (#1499) Hi there, Here is an attempt to implement canary releases ( #1252 ). This is the first time I write golang and make a terraform contribution, I opened the PR to obtain feedback and advices so please let me know how I can improve this code! In addition I used `make fmt` to format the code but left some lines bigger than 80 characters, do I need to split them ? I tested the feature against a project with the following configuration: ``` resource "google_compute_health_check" "mikael-hackathon-healthcheck" { name = "mikael-hackathon-healthcheck" check_interval_sec = 1 timeout_sec = 1 healthy_threshold = 2 unhealthy_threshold = 10 http_health_check { request_path = "/" port = "80" } } resource "google_compute_instance_template" "mikael-hackaton-template" { name_prefix = "mikael-hackaton-" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am stable version at $(hostname) > /var/www/html/index.html" } resource "google_compute_instance_template" "mikael-hackaton-template-canary" { name_prefix = "mikael-hackaton-canary" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am a canary at $(hostname) > /var/www/html/index.html" } resource "google_compute_target_pool" "mikael-hackaton-target-pool" { name = "mikael-hackaton-target-pool" } resource "google_compute_instance_group_manager" "mikael-hackaton-manager" { name = "mikael-hackaton-manager" base_instance_name = "mikael-hackaton" #instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" update_strategy = "ROLLING_UPDATE" zone = "${var.zone}" target_pools = ["${google_compute_target_pool.mikael-hackaton-target-pool.self_link}"] target_size = 5 version { name = "primary" instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" } version { name = "canary" instance_template = "${google_compute_instance_template.mikael-hackaton-template-canary.self_link}" target_size_fixed = 1 } named_port { name = "http" port = 80 } auto_healing_policies { health_check = "${google_compute_health_check.mikael-hackathon-healthcheck.self_link}" initial_delay_sec = 10 } rolling_update_policy { type = "PROACTIVE" minimal_action = "REPLACE" max_surge_percent = 100 max_unavailable_percent = 50 min_ready_sec = 5 } } ```
2018-06-04 22:34:48 +00:00
func TestAccInstanceGroupManager_versions(t *testing.T) {
t.Parallel()
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: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
{
Implement multiple version in instance group manager (#1499) Hi there, Here is an attempt to implement canary releases ( #1252 ). This is the first time I write golang and make a terraform contribution, I opened the PR to obtain feedback and advices so please let me know how I can improve this code! In addition I used `make fmt` to format the code but left some lines bigger than 80 characters, do I need to split them ? I tested the feature against a project with the following configuration: ``` resource "google_compute_health_check" "mikael-hackathon-healthcheck" { name = "mikael-hackathon-healthcheck" check_interval_sec = 1 timeout_sec = 1 healthy_threshold = 2 unhealthy_threshold = 10 http_health_check { request_path = "/" port = "80" } } resource "google_compute_instance_template" "mikael-hackaton-template" { name_prefix = "mikael-hackaton-" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am stable version at $(hostname) > /var/www/html/index.html" } resource "google_compute_instance_template" "mikael-hackaton-template-canary" { name_prefix = "mikael-hackaton-canary" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am a canary at $(hostname) > /var/www/html/index.html" } resource "google_compute_target_pool" "mikael-hackaton-target-pool" { name = "mikael-hackaton-target-pool" } resource "google_compute_instance_group_manager" "mikael-hackaton-manager" { name = "mikael-hackaton-manager" base_instance_name = "mikael-hackaton" #instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" update_strategy = "ROLLING_UPDATE" zone = "${var.zone}" target_pools = ["${google_compute_target_pool.mikael-hackaton-target-pool.self_link}"] target_size = 5 version { name = "primary" instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" } version { name = "canary" instance_template = "${google_compute_instance_template.mikael-hackaton-template-canary.self_link}" target_size_fixed = 1 } named_port { name = "http" port = 80 } auto_healing_policies { health_check = "${google_compute_health_check.mikael-hackathon-healthcheck.self_link}" initial_delay_sec = 10 } rolling_update_policy { type = "PROACTIVE" minimal_action = "REPLACE" max_surge_percent = 100 max_unavailable_percent = 50 min_ready_sec = 5 } } ```
2018-06-04 22:34:48 +00:00
Config: testAccInstanceGroupManager_versions(primaryTemplate, canaryTemplate, igm),
},
{
Implement multiple version in instance group manager (#1499) Hi there, Here is an attempt to implement canary releases ( #1252 ). This is the first time I write golang and make a terraform contribution, I opened the PR to obtain feedback and advices so please let me know how I can improve this code! In addition I used `make fmt` to format the code but left some lines bigger than 80 characters, do I need to split them ? I tested the feature against a project with the following configuration: ``` resource "google_compute_health_check" "mikael-hackathon-healthcheck" { name = "mikael-hackathon-healthcheck" check_interval_sec = 1 timeout_sec = 1 healthy_threshold = 2 unhealthy_threshold = 10 http_health_check { request_path = "/" port = "80" } } resource "google_compute_instance_template" "mikael-hackaton-template" { name_prefix = "mikael-hackaton-" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am stable version at $(hostname) > /var/www/html/index.html" } resource "google_compute_instance_template" "mikael-hackaton-template-canary" { name_prefix = "mikael-hackaton-canary" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am a canary at $(hostname) > /var/www/html/index.html" } resource "google_compute_target_pool" "mikael-hackaton-target-pool" { name = "mikael-hackaton-target-pool" } resource "google_compute_instance_group_manager" "mikael-hackaton-manager" { name = "mikael-hackaton-manager" base_instance_name = "mikael-hackaton" #instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" update_strategy = "ROLLING_UPDATE" zone = "${var.zone}" target_pools = ["${google_compute_target_pool.mikael-hackaton-target-pool.self_link}"] target_size = 5 version { name = "primary" instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" } version { name = "canary" instance_template = "${google_compute_instance_template.mikael-hackaton-template-canary.self_link}" target_size_fixed = 1 } named_port { name = "http" port = 80 } auto_healing_policies { health_check = "${google_compute_health_check.mikael-hackathon-healthcheck.self_link}" initial_delay_sec = 10 } rolling_update_policy { type = "PROACTIVE" minimal_action = "REPLACE" max_surge_percent = 100 max_unavailable_percent = 50 min_ready_sec = 5 } } ```
2018-06-04 22:34:48 +00:00
ResourceName: "google_compute_instance_group_manager.igm-basic",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccInstanceGroupManager_autoHealingPolicies(t *testing.T) {
t.Parallel()
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: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupManager_autoHealingPolicies(template, target, igm, hck),
},
{
ResourceName: "google_compute_instance_group_manager.igm-basic",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
// This test is to make sure that a single version resource can link to a versioned resource
// without perpetual diffs because the self links mismatch.
// Once auto_healing_policies is no longer beta, we will need to use a new field or resource
// with Beta fields.
func TestAccInstanceGroupManager_selfLinkStability(t *testing.T) {
t.Parallel()
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))
autoscaler := 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: testAccInstanceGroupManager_selfLinkStability(template, target, igm, hck, autoscaler),
},
{
ResourceName: "google_compute_instance_group_manager.igm-basic",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
2015-02-16 16:06:23 +00:00
func testAccCheckInstanceGroupManagerDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_instance_group_manager" {
2015-02-16 16:06:23 +00:00
continue
}
id, err := parseInstanceGroupManagerId(rs.Primary.ID)
if err != nil {
return err
}
if id.Project == "" {
id.Project = config.Project
}
if id.Zone == "" {
id.Zone = rs.Primary.Attributes["zone"]
}
_, err = config.clientCompute.InstanceGroupManagers.Get(
id.Project, id.Zone, id.Name).Do()
if err == nil {
return fmt.Errorf("InstanceGroupManager still exists")
}
}
return nil
}
func testAccInstanceGroupManager_basic(template, target, igm1, igm2 string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-basic" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
source_image = "${data.google_compute_image.my_image.self_link}"
auto_delete = true
boot = true
}
network_interface {
network = "default"
}
metadata {
foo = "bar"
}
2015-02-16 16:06:23 +00:00
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
2015-02-16 16:06:23 +00: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 16:06:23 +00: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 16:06:23 +00: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 16:06:23 +00:00
}
func testAccInstanceGroupManager_targetSizeZero(template, igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-basic" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
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_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"
zone = "us-central1-c"
}
`, template, igm)
}
func testAccInstanceGroupManager_update(template, target, igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-update" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
source_image = "${data.google_compute_image.my_image.self_link}"
auto_delete = true
boot = true
}
2015-07-30 14:46:16 +00:00
network_interface {
network = "default"
}
2015-02-16 16:06:23 +00:00
metadata {
foo = "bar"
}
2015-02-16 16:06:23 +00:00
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
2015-02-16 16:06:23 +00: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 16:06:23 +00: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
named_port {
name = "customhttp"
port = 8080
}
}`, template, target, igm)
2015-02-16 16:06:23 +00:00
}
// Change IGM's instance template and target size
2017-09-14 00:06:07 +00:00
func testAccInstanceGroupManager_update2(template1, target1, target2, template2, igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-update" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
source_image = "${data.google_compute_image.my_image.self_link}"
auto_delete = true
boot = true
}
2015-02-16 16:06:23 +00:00
network_interface {
network = "default"
}
metadata {
foo = "bar"
}
2015-02-16 16:06:23 +00:00
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
2015-02-16 16:06:23 +00: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 16:06:23 +00:00
}
2017-09-14 00:06:07 +00:00
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 {
2018-08-13 23:20:33 +00:00
source_image = "${data.google_compute_image.my_image.self_link}"
auto_delete = true
boot = true
}
2015-02-16 16:06:23 +00:00
network_interface {
network = "default"
}
2015-02-16 16:06:23 +00:00
metadata {
foo = "bar"
}
2015-02-16 16:06:23 +00:00
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
2015-02-16 16:06:23 +00: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}"
2017-09-14 00:06:07 +00:00
target_pools = [
"${google_compute_target_pool.igm-update.self_link}",
"${google_compute_target_pool.igm-update2.self_link}",
]
base_instance_name = "igm-update"
zone = "us-central1-c"
target_size = 3
named_port {
name = "customhttp"
port = 8080
}
named_port {
name = "customhttps"
port = 8443
}
2017-09-14 00:06:07 +00:00
}`, template1, target1, target2, template2, igm)
2015-02-16 16:06:23 +00:00
}
func testAccInstanceGroupManager_updateLifecycle(tag, igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-update" {
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["%s"]
disk {
2018-08-13 23:20:33 +00:00
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_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 testAccInstanceGroupManager_updateStrategy(igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-update-strategy" {
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["terraform-testing"]
disk {
2018-08-13 23:20:33 +00:00
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_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 = "igm-update-strategy"
zone = "us-central1-c"
target_size = 2
update_strategy = "REPLACE"
named_port {
name = "customhttp"
port = 8080
}
}`, igm)
}
func testAccInstanceGroupManager_rollingUpdatePolicy(igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-rolling-update-policy" {
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["terraform-testing"]
disk {
2018-08-13 23:20:33 +00:00
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_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"
zone = "us-central1-c"
target_size = 3
update_strategy = "ROLLING_UPDATE"
rolling_update_policy {
type = "PROACTIVE"
minimal_action = "REPLACE"
max_surge_percent = 50
max_unavailable_percent = 50
min_ready_sec = 20
}
named_port {
name = "customhttp"
port = 8080
}
}`, igm)
}
func testAccInstanceGroupManager_rollingUpdatePolicy2(igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-rolling-update-policy" {
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["terraform-testing"]
disk {
2018-08-13 23:20:33 +00:00
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_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"
zone = "us-central1-c"
target_size = 3
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 testAccInstanceGroupManager_separateRegions(igm1, igm2 string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-basic" {
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
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_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"
zone = "us-central1-c"
target_size = 2
}
resource "google_compute_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"
zone = "us-west1-b"
target_size = 2
}
`, igm1, igm2)
}
func testAccInstanceGroupManager_autoHealingPolicies(template, target, igm, hck string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-basic" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
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_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
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)
}
Implement multiple version in instance group manager (#1499) Hi there, Here is an attempt to implement canary releases ( #1252 ). This is the first time I write golang and make a terraform contribution, I opened the PR to obtain feedback and advices so please let me know how I can improve this code! In addition I used `make fmt` to format the code but left some lines bigger than 80 characters, do I need to split them ? I tested the feature against a project with the following configuration: ``` resource "google_compute_health_check" "mikael-hackathon-healthcheck" { name = "mikael-hackathon-healthcheck" check_interval_sec = 1 timeout_sec = 1 healthy_threshold = 2 unhealthy_threshold = 10 http_health_check { request_path = "/" port = "80" } } resource "google_compute_instance_template" "mikael-hackaton-template" { name_prefix = "mikael-hackaton-" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am stable version at $(hostname) > /var/www/html/index.html" } resource "google_compute_instance_template" "mikael-hackaton-template-canary" { name_prefix = "mikael-hackaton-canary" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am a canary at $(hostname) > /var/www/html/index.html" } resource "google_compute_target_pool" "mikael-hackaton-target-pool" { name = "mikael-hackaton-target-pool" } resource "google_compute_instance_group_manager" "mikael-hackaton-manager" { name = "mikael-hackaton-manager" base_instance_name = "mikael-hackaton" #instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" update_strategy = "ROLLING_UPDATE" zone = "${var.zone}" target_pools = ["${google_compute_target_pool.mikael-hackaton-target-pool.self_link}"] target_size = 5 version { name = "primary" instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" } version { name = "canary" instance_template = "${google_compute_instance_template.mikael-hackaton-template-canary.self_link}" target_size_fixed = 1 } named_port { name = "http" port = 80 } auto_healing_policies { health_check = "${google_compute_health_check.mikael-hackathon-healthcheck.self_link}" initial_delay_sec = 10 } rolling_update_policy { type = "PROACTIVE" minimal_action = "REPLACE" max_surge_percent = 100 max_unavailable_percent = 50 min_ready_sec = 5 } } ```
2018-06-04 22:34:48 +00:00
func testAccInstanceGroupManager_versions(primaryTemplate string, canaryTemplate string, igm string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
Implement multiple version in instance group manager (#1499) Hi there, Here is an attempt to implement canary releases ( #1252 ). This is the first time I write golang and make a terraform contribution, I opened the PR to obtain feedback and advices so please let me know how I can improve this code! In addition I used `make fmt` to format the code but left some lines bigger than 80 characters, do I need to split them ? I tested the feature against a project with the following configuration: ``` resource "google_compute_health_check" "mikael-hackathon-healthcheck" { name = "mikael-hackathon-healthcheck" check_interval_sec = 1 timeout_sec = 1 healthy_threshold = 2 unhealthy_threshold = 10 http_health_check { request_path = "/" port = "80" } } resource "google_compute_instance_template" "mikael-hackaton-template" { name_prefix = "mikael-hackaton-" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am stable version at $(hostname) > /var/www/html/index.html" } resource "google_compute_instance_template" "mikael-hackaton-template-canary" { name_prefix = "mikael-hackaton-canary" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am a canary at $(hostname) > /var/www/html/index.html" } resource "google_compute_target_pool" "mikael-hackaton-target-pool" { name = "mikael-hackaton-target-pool" } resource "google_compute_instance_group_manager" "mikael-hackaton-manager" { name = "mikael-hackaton-manager" base_instance_name = "mikael-hackaton" #instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" update_strategy = "ROLLING_UPDATE" zone = "${var.zone}" target_pools = ["${google_compute_target_pool.mikael-hackaton-target-pool.self_link}"] target_size = 5 version { name = "primary" instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" } version { name = "canary" instance_template = "${google_compute_instance_template.mikael-hackaton-template-canary.self_link}" target_size_fixed = 1 } named_port { name = "http" port = 80 } auto_healing_policies { health_check = "${google_compute_health_check.mikael-hackathon-healthcheck.self_link}" initial_delay_sec = 10 } rolling_update_policy { type = "PROACTIVE" minimal_action = "REPLACE" max_surge_percent = 100 max_unavailable_percent = 50 min_ready_sec = 5 } } ```
2018-06-04 22:34:48 +00:00
resource "google_compute_instance_template" "igm-primary" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
source_image = "${data.google_compute_image.my_image.self_link}"
Implement multiple version in instance group manager (#1499) Hi there, Here is an attempt to implement canary releases ( #1252 ). This is the first time I write golang and make a terraform contribution, I opened the PR to obtain feedback and advices so please let me know how I can improve this code! In addition I used `make fmt` to format the code but left some lines bigger than 80 characters, do I need to split them ? I tested the feature against a project with the following configuration: ``` resource "google_compute_health_check" "mikael-hackathon-healthcheck" { name = "mikael-hackathon-healthcheck" check_interval_sec = 1 timeout_sec = 1 healthy_threshold = 2 unhealthy_threshold = 10 http_health_check { request_path = "/" port = "80" } } resource "google_compute_instance_template" "mikael-hackaton-template" { name_prefix = "mikael-hackaton-" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am stable version at $(hostname) > /var/www/html/index.html" } resource "google_compute_instance_template" "mikael-hackaton-template-canary" { name_prefix = "mikael-hackaton-canary" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am a canary at $(hostname) > /var/www/html/index.html" } resource "google_compute_target_pool" "mikael-hackaton-target-pool" { name = "mikael-hackaton-target-pool" } resource "google_compute_instance_group_manager" "mikael-hackaton-manager" { name = "mikael-hackaton-manager" base_instance_name = "mikael-hackaton" #instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" update_strategy = "ROLLING_UPDATE" zone = "${var.zone}" target_pools = ["${google_compute_target_pool.mikael-hackaton-target-pool.self_link}"] target_size = 5 version { name = "primary" instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" } version { name = "canary" instance_template = "${google_compute_instance_template.mikael-hackaton-template-canary.self_link}" target_size_fixed = 1 } named_port { name = "http" port = 80 } auto_healing_policies { health_check = "${google_compute_health_check.mikael-hackathon-healthcheck.self_link}" initial_delay_sec = 10 } rolling_update_policy { type = "PROACTIVE" minimal_action = "REPLACE" max_surge_percent = 100 max_unavailable_percent = 50 min_ready_sec = 5 } } ```
2018-06-04 22:34:48 +00:00
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 {
2018-08-13 23:20:33 +00:00
source_image = "${data.google_compute_image.my_image.self_link}"
Implement multiple version in instance group manager (#1499) Hi there, Here is an attempt to implement canary releases ( #1252 ). This is the first time I write golang and make a terraform contribution, I opened the PR to obtain feedback and advices so please let me know how I can improve this code! In addition I used `make fmt` to format the code but left some lines bigger than 80 characters, do I need to split them ? I tested the feature against a project with the following configuration: ``` resource "google_compute_health_check" "mikael-hackathon-healthcheck" { name = "mikael-hackathon-healthcheck" check_interval_sec = 1 timeout_sec = 1 healthy_threshold = 2 unhealthy_threshold = 10 http_health_check { request_path = "/" port = "80" } } resource "google_compute_instance_template" "mikael-hackaton-template" { name_prefix = "mikael-hackaton-" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am stable version at $(hostname) > /var/www/html/index.html" } resource "google_compute_instance_template" "mikael-hackaton-template-canary" { name_prefix = "mikael-hackaton-canary" description = "This template is used to create app server instances." tags = ["loadbalanced", "internal-web", "hackaton"] labels = { environment = "hackaton" } instance_description = "Hackaton demo rolling upgrade" machine_type = "n1-standard-1" can_ip_forward = false scheduling { automatic_restart = true on_host_maintenance = "MIGRATE" } disk { source_image = "debian-cloud/debian-9" disk_type = "pd-standard" disk_size_gb = 20 auto_delete = true boot = true } network_interface { network = "default" access_config = {} } service_account { email = "${google_service_account.mikael-hackaton.email}" scopes = ["cloud-platform"] } lifecycle { create_before_destroy = true } metadata_startup_script = "apt-get update && apt-get install -y apache2 && echo I am a canary at $(hostname) > /var/www/html/index.html" } resource "google_compute_target_pool" "mikael-hackaton-target-pool" { name = "mikael-hackaton-target-pool" } resource "google_compute_instance_group_manager" "mikael-hackaton-manager" { name = "mikael-hackaton-manager" base_instance_name = "mikael-hackaton" #instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" update_strategy = "ROLLING_UPDATE" zone = "${var.zone}" target_pools = ["${google_compute_target_pool.mikael-hackaton-target-pool.self_link}"] target_size = 5 version { name = "primary" instance_template = "${google_compute_instance_template.mikael-hackaton-template.self_link}" } version { name = "canary" instance_template = "${google_compute_instance_template.mikael-hackaton-template-canary.self_link}" target_size_fixed = 1 } named_port { name = "http" port = 80 } auto_healing_policies { health_check = "${google_compute_health_check.mikael-hackathon-healthcheck.self_link}" initial_delay_sec = 10 } rolling_update_policy { type = "PROACTIVE" minimal_action = "REPLACE" max_surge_percent = 100 max_unavailable_percent = 50 min_ready_sec = 5 } } ```
2018-06-04 22:34:48 +00:00
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_group_manager" "igm-basic" {
description = "Terraform test instance group manager"
name = "%s"
base_instance_name = "igm-basic"
zone = "us-central1-c"
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)
}
// This test is to make sure that a single version resource can link to a versioned resource
// without perpetual diffs because the self links mismatch.
// Once auto_healing_policies is no longer beta, we will need to use a new field or resource
// with Beta fields.
func testAccInstanceGroupManager_selfLinkStability(template, target, igm, hck, autoscaler string) string {
return fmt.Sprintf(`
2018-08-13 23:20:33 +00:00
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
2018-08-13 23:20:33 +00:00
}
resource "google_compute_instance_template" "igm-basic" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
2018-08-13 23:20:33 +00:00
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_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
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
}
resource "google_compute_autoscaler" "foobar" {
name = "%s"
zone = "us-central1-c"
target = "${google_compute_instance_group_manager.igm-basic.self_link}"
autoscaling_policy = {
max_replicas = 10
min_replicas = 1
cooldown_period = 60
cpu_utilization = {
target = 0.5
}
}
}
`, template, target, igm, hck, autoscaler)
}