terraform-provider-google/google/resource_compute_instance_group_manager.go

673 lines
21 KiB
Go
Raw Normal View History

2015-02-16 16:06:23 +00:00
package google
import (
"fmt"
"log"
"strings"
"time"
2015-02-16 16:06:23 +00:00
"github.com/hashicorp/terraform/helper/resource"
2015-02-16 16:06:23 +00:00
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
computeBeta "google.golang.org/api/compute/v0.beta"
"google.golang.org/api/compute/v1"
2015-02-16 16:06:23 +00:00
)
func resourceComputeInstanceGroupManager() *schema.Resource {
2015-02-16 16:06:23 +00:00
return &schema.Resource{
Create: resourceComputeInstanceGroupManagerCreate,
Read: resourceComputeInstanceGroupManagerRead,
Update: resourceComputeInstanceGroupManagerUpdate,
Delete: resourceComputeInstanceGroupManagerDelete,
Importer: &schema.ResourceImporter{
State: resourceInstanceGroupManagerStateImporter,
},
2015-02-16 16:06:23 +00:00
Schema: map[string]*schema.Schema{
"base_instance_name": {
2015-02-16 16:06:23 +00:00
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"instance_template": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: compareSelfLinkRelativePaths,
},
"version": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
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
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
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
Type: schema.TypeString,
Required: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
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
},
"instance_template": {
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
Type: schema.TypeString,
Required: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
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
DiffSuppressFunc: compareSelfLinkRelativePaths,
},
"target_size": {
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
Type: schema.TypeList,
Optional: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
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
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"fixed": {
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
Type: schema.TypeInt,
Optional: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
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
},
"percent": {
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
Type: schema.TypeInt,
Optional: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
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
ValidateFunc: validation.IntBetween(0, 100),
},
},
},
},
},
},
},
"name": {
Type: schema.TypeString,
Required: true,
2015-02-16 16:06:23 +00:00
ForceNew: true,
},
"zone": {
2015-02-16 16:06:23 +00:00
Type: schema.TypeString,
Optional: true,
Computed: true,
2015-02-16 16:06:23 +00:00
ForceNew: true,
},
"description": {
2015-02-16 16:06:23 +00:00
Type: schema.TypeString,
Optional: true,
ForceNew: true,
2015-02-16 16:06:23 +00:00
},
"fingerprint": {
2015-02-16 16:06:23 +00:00
Type: schema.TypeString,
Computed: true,
},
"instance_group": {
2015-02-16 16:06:23 +00:00
Type: schema.TypeString,
Computed: true,
2015-02-16 16:06:23 +00:00
},
"named_port": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"port": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
"project": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"self_link": {
Type: schema.TypeString,
Computed: true,
},
"update_strategy": {
2017-09-14 00:06:07 +00:00
Type: schema.TypeString,
Optional: true,
Default: "REPLACE",
ValidateFunc: validation.StringInSlice([]string{"RESTART", "NONE", "ROLLING_UPDATE", "REPLACE"}, false),
DiffSuppressFunc: func(key, old, new string, d *schema.ResourceData) bool {
if old == "REPLACE" && new == "RESTART" {
return true
}
if old == "RESTART" && new == "REPLACE" {
return true
}
return false
},
},
"target_pools": {
2017-09-14 00:06:07 +00:00
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: selfLinkRelativePathHash,
2015-02-16 16:06:23 +00:00
},
"target_size": {
2015-02-16 16:06:23 +00:00
Type: schema.TypeInt,
Computed: true,
Optional: true,
2015-02-16 16:06:23 +00:00
},
"auto_healing_policies": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"health_check": {
Type: schema.TypeString,
Required: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
DiffSuppressFunc: compareSelfLinkRelativePaths,
},
"initial_delay_sec": {
Type: schema.TypeInt,
Required: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
ValidateFunc: validation.IntBetween(0, 3600),
},
},
},
},
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
"rolling_update_policy": {
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
Computed: true,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"minimal_action": {
Type: schema.TypeString,
Required: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
ValidateFunc: validation.StringInSlice([]string{"RESTART", "REPLACE"}, false),
},
"type": {
Type: schema.TypeString,
Required: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
ValidateFunc: validation.StringInSlice([]string{"OPPORTUNISTIC", "PROACTIVE"}, false),
},
"max_surge_fixed": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
},
"max_surge_percent": {
Type: schema.TypeInt,
Optional: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
ValidateFunc: validation.IntBetween(0, 100),
},
"max_unavailable_fixed": {
Type: schema.TypeInt,
Optional: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
},
"max_unavailable_percent": {
Type: schema.TypeInt,
Optional: true,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
ValidateFunc: validation.IntBetween(0, 100),
},
"min_ready_sec": {
Type: schema.TypeInt,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
Optional: true,
ValidateFunc: validation.IntBetween(0, 3600),
},
},
},
},
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
"wait_for_instances": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
2015-02-16 16:06:23 +00:00
},
}
}
func getNamedPorts(nps []interface{}) []*compute.NamedPort {
namedPorts := make([]*compute.NamedPort, 0, len(nps))
for _, v := range nps {
np := v.(map[string]interface{})
namedPorts = append(namedPorts, &compute.NamedPort{
Name: np["name"].(string),
Port: int64(np["port"].(int)),
})
}
return namedPorts
}
func getNamedPortsBeta(nps []interface{}) []*computeBeta.NamedPort {
namedPorts := make([]*computeBeta.NamedPort, 0, len(nps))
for _, v := range nps {
np := v.(map[string]interface{})
namedPorts = append(namedPorts, &computeBeta.NamedPort{
Name: np["name"].(string),
Port: int64(np["port"].(int)),
})
}
return namedPorts
}
func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta interface{}) error {
2015-02-16 16:06:23 +00:00
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
zone, err := getZone(d, config)
if err != nil {
return err
}
2015-02-16 16:06:23 +00:00
// Build the parameter
manager := &computeBeta.InstanceGroupManager{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
BaseInstanceName: d.Get("base_instance_name").(string),
InstanceTemplate: d.Get("instance_template").(string),
TargetSize: int64(d.Get("target_size").(int)),
NamedPorts: getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()),
TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)),
2017-06-16 22:39:44 +00:00
// Force send TargetSize to allow a value of 0.
2017-06-16 22:41:26 +00:00
ForceSendFields: []string{"TargetSize"},
2015-02-16 16:06:23 +00:00
}
log.Printf("[DEBUG] InstanceGroupManager insert request: %#v", manager)
op, err := config.clientComputeBeta.InstanceGroupManagers.Insert(
project, zone, manager).Do()
2015-02-16 16:06:23 +00:00
if err != nil {
return fmt.Errorf("Error creating InstanceGroupManager: %s", err)
}
// It probably maybe worked, so store the ID now
id, err := replaceVars(d, config, "{{project}}/{{zone}}/{{name}}")
if err != nil {
return err
}
d.SetId(id)
2015-02-16 16:06:23 +00:00
// Wait for the operation to complete
err = computeSharedOperationWait(config.clientCompute, op, project, "Creating InstanceGroupManager")
2015-02-16 16:06:23 +00:00
if err != nil {
return err
}
return resourceComputeInstanceGroupManagerRead(d, meta)
2015-02-16 16:06:23 +00:00
}
func flattenNamedPortsBeta(namedPorts []*computeBeta.NamedPort) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(namedPorts))
for _, namedPort := range namedPorts {
namedPortMap := make(map[string]interface{})
namedPortMap["name"] = namedPort.Name
namedPortMap["port"] = namedPort.Port
result = append(result, namedPortMap)
}
return result
}
func getManager(d *schema.ResourceData, meta interface{}) (*computeBeta.InstanceGroupManager, error) {
2015-02-16 16:06:23 +00:00
config := meta.(*Config)
if err := parseImportId([]string{"(?P<project>[^/]+)/(?P<zone>[^/]+)/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config); err != nil {
return nil, err
}
project, err := getProject(d, config)
if err != nil {
return nil, err
}
zone, _ := getZone(d, config)
name := d.Get("name").(string)
2015-02-16 16:06:23 +00:00
manager, err := config.clientComputeBeta.InstanceGroupManagers.Get(project, zone, name).Do()
if err != nil {
return nil, handleNotFoundError(err, d, fmt.Sprintf("Instance Group Manager %q", name))
}
if manager == nil {
log.Printf("[WARN] Removing Instance Group Manager %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil, nil
}
return manager, nil
}
func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
manager, err := getManager(d, meta)
if err != nil {
return err
}
if manager == nil {
log.Printf("[WARN] Instance Group Manager %q not found, removing from state.", d.Id())
d.SetId("")
return nil
}
d.Set("base_instance_name", manager.BaseInstanceName)
d.Set("instance_template", ConvertSelfLinkToV1(manager.InstanceTemplate))
d.Set("name", manager.Name)
2017-09-14 00:06:07 +00:00
d.Set("zone", GetResourceNameFromSelfLink(manager.Zone))
d.Set("description", manager.Description)
d.Set("project", project)
d.Set("target_size", manager.TargetSize)
if err = d.Set("target_pools", mapStringArr(manager.TargetPools, ConvertSelfLinkToV1)); err != nil {
return fmt.Errorf("Error setting target_pools in state: %s", err.Error())
}
if err = d.Set("named_port", flattenNamedPortsBeta(manager.NamedPorts)); err != nil {
return fmt.Errorf("Error setting named_port in state: %s", err.Error())
}
2015-02-16 16:06:23 +00:00
d.Set("fingerprint", manager.Fingerprint)
d.Set("instance_group", ConvertSelfLinkToV1(manager.InstanceGroup))
d.Set("self_link", ConvertSelfLinkToV1(manager.SelfLink))
update_strategy, ok := d.GetOk("update_strategy")
if !ok {
update_strategy = "REPLACE"
}
d.Set("update_strategy", update_strategy.(string))
// When we make a list Removed, we see a permadiff from `field_name.#: "" => "<computed>"`. Set to nil in Read so we see no diff.
d.Set("version", nil)
d.Set("rolling_update_policy", nil)
2015-02-16 16:06:23 +00:00
if d.Get("wait_for_instances").(bool) {
conf := resource.StateChangeConf{
Pending: []string{"creating", "error"},
Target: []string{"created"},
Refresh: waitForInstancesRefreshFunc(getManager, d, meta),
Timeout: d.Timeout(schema.TimeoutCreate),
}
_, err := conf.WaitForState()
if err != nil {
return err
}
}
2015-02-16 16:06:23 +00:00
return nil
}
// Updates an instance group manager by applying the update strategy (REPLACE, RESTART)
// and rolling update policy (PROACTIVE, OPPORTUNISTIC). Updates performed by API
// are OPPORTUNISTIC by default.
func performZoneUpdate(config *Config, id string, updateStrategy string, project string, zone string) error {
if updateStrategy == "RESTART" || updateStrategy == "REPLACE" {
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
managedInstances, err := config.clientComputeBeta.InstanceGroupManagers.ListManagedInstances(project, zone, id).Do()
if err != nil {
return fmt.Errorf("Error getting instance group managers instances: %s", err)
}
managedInstanceCount := len(managedInstances.ManagedInstances)
instances := make([]string, managedInstanceCount)
for i, v := range managedInstances.ManagedInstances {
instances[i] = v.Instance
}
recreateInstances := &computeBeta.InstanceGroupManagersRecreateInstancesRequest{
Instances: instances,
}
op, err := config.clientComputeBeta.InstanceGroupManagers.RecreateInstances(project, zone, id, recreateInstances).Do()
if err != nil {
return fmt.Errorf("Error restarting instance group managers instances: %s", err)
}
// Wait for the operation to complete
err = computeSharedOperationWaitTime(config.clientCompute, op, project, managedInstanceCount*4, "Restarting InstanceGroupManagers instances")
if err != nil {
return err
}
}
return nil
}
func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta interface{}) error {
2015-02-16 16:06:23 +00:00
config := meta.(*Config)
if err := parseImportId([]string{"(?P<project>[^/]+)/(?P<zone>[^/]+)/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config); err != nil {
return err
}
project, err := getProject(d, config)
if err != nil {
return err
}
zone, _ := getZone(d, config)
name := d.Get("name").(string)
2015-02-16 16:06:23 +00:00
d.Partial(true)
// If target_pools changes then update
if d.HasChange("target_pools") {
2017-09-14 00:06:07 +00:00
targetPools := convertStringSet(d.Get("target_pools").(*schema.Set))
2015-02-16 16:06:23 +00:00
// Build the parameter
setTargetPools := &computeBeta.InstanceGroupManagersSetTargetPoolsRequest{
2015-02-16 16:06:23 +00:00
Fingerprint: d.Get("fingerprint").(string),
TargetPools: targetPools,
}
op, err := config.clientComputeBeta.InstanceGroupManagers.SetTargetPools(
project, zone, name, setTargetPools).Do()
2015-02-16 16:06:23 +00:00
if err != nil {
return fmt.Errorf("Error updating InstanceGroupManager: %s", err)
}
// Wait for the operation to complete
err = computeSharedOperationWait(config.clientCompute, op, project, "Updating InstanceGroupManager")
2015-02-16 16:06:23 +00:00
if err != nil {
return err
}
d.SetPartial("target_pools")
}
// If named_port changes then update:
if d.HasChange("named_port") {
// Build the parameters for a "SetNamedPorts" request:
namedPorts := getNamedPortsBeta(d.Get("named_port").(*schema.Set).List())
setNamedPorts := &computeBeta.InstanceGroupsSetNamedPortsRequest{
NamedPorts: namedPorts,
}
// Make the request:
op, err := config.clientComputeBeta.InstanceGroups.SetNamedPorts(
project, zone, name, setNamedPorts).Do()
if err != nil {
return fmt.Errorf("Error updating InstanceGroupManager: %s", err)
}
// Wait for the operation to complete:
err = computeSharedOperationWait(config.clientCompute, op, project, "Updating InstanceGroupManager")
if err != nil {
return err
}
d.SetPartial("named_port")
}
if d.HasChange("target_size") {
2017-06-16 22:39:44 +00:00
targetSize := int64(d.Get("target_size").(int))
op, err := config.clientComputeBeta.InstanceGroupManagers.Resize(
project, zone, name, targetSize).Do()
if err != nil {
return fmt.Errorf("Error updating InstanceGroupManager: %s", err)
}
2015-02-16 16:06:23 +00:00
// Wait for the operation to complete
err = computeSharedOperationWait(config.clientCompute, op, project, "Updating InstanceGroupManager")
if err != nil {
return err
2015-02-16 16:06:23 +00:00
}
d.SetPartial("target_size")
2015-02-16 16:06:23 +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
// If instance_template changes then update
if d.HasChange("instance_template") {
// Build the parameter
setInstanceTemplate := &computeBeta.InstanceGroupManagersSetInstanceTemplateRequest{
InstanceTemplate: d.Get("instance_template").(string),
}
op, err := config.clientComputeBeta.InstanceGroupManagers.SetInstanceTemplate(project, zone, name, setInstanceTemplate).Do()
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
if err != nil {
return fmt.Errorf("Error updating InstanceGroupManager: %s", err)
}
// Wait for the operation to complete
err = computeSharedOperationWait(config.clientCompute, op, project, "Updating InstanceGroupManager")
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
if err != nil {
return err
}
updateStrategy := d.Get("update_strategy").(string)
err = performZoneUpdate(config, name, updateStrategy, project, zone)
if err != nil {
return err
}
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
d.SetPartial("instance_template")
}
2015-02-16 16:06:23 +00:00
d.Partial(false)
return resourceComputeInstanceGroupManagerRead(d, meta)
2015-02-16 16:06:23 +00:00
}
func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta interface{}) error {
2015-02-16 16:06:23 +00:00
config := meta.(*Config)
if err := parseImportId([]string{"(?P<project>[^/]+)/(?P<zone>[^/]+)/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config); err != nil {
return err
}
project, err := getProject(d, config)
if err != nil {
return err
}
zone, _ := getZone(d, config)
name := d.Get("name").(string)
op, err := config.clientComputeBeta.InstanceGroupManagers.Delete(project, zone, name).Do()
attempt := 0
for err != nil && attempt < 20 {
attempt++
time.Sleep(2000 * time.Millisecond)
op, err = config.clientComputeBeta.InstanceGroupManagers.Delete(project, zone, name).Do()
}
2015-02-16 16:06:23 +00:00
if err != nil {
return fmt.Errorf("Error deleting instance group manager: %s", err)
}
currentSize := int64(d.Get("target_size").(int))
2015-02-16 16:06:23 +00:00
// Wait for the operation to complete
err = computeSharedOperationWait(config.clientCompute, op, project, "Deleting InstanceGroupManager")
for err != nil && currentSize > 0 {
if !strings.Contains(err.Error(), "timeout") {
2015-10-29 22:10:44 +00:00
return err
}
instanceGroup, igErr := config.clientComputeBeta.InstanceGroups.Get(
project, zone, name).Do()
if igErr != nil {
return fmt.Errorf("Error getting instance group size: %s", err)
}
instanceGroupSize := instanceGroup.Size
if instanceGroupSize >= currentSize {
return fmt.Errorf("Error, instance group isn't shrinking during delete")
}
log.Printf("[INFO] timeout occurred, but instance group is shrinking (%d < %d)", instanceGroupSize, currentSize)
currentSize = instanceGroupSize
err = computeSharedOperationWait(config.clientCompute, op, project, "Deleting InstanceGroupManager")
2015-02-16 16:06:23 +00:00
}
d.SetId("")
return nil
}
func resourceInstanceGroupManagerStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
d.Set("wait_for_instances", false)
config := meta.(*Config)
if err := parseImportId([]string{"(?P<project>[^/]+)/(?P<zone>[^/]+)/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config); err != nil {
return nil, err
}
// Replace import id for the resource id
id, err := replaceVars(d, config, "{{project}}/{{zone}}/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
return []*schema.ResourceData{d}, nil
}