From e914223ab499e75019e1994981a73d9e40255591 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Wed, 1 May 2019 17:51:05 -0700 Subject: [PATCH 01/10] [0.12 compat] Use relative paths for relative modules. This is enforced in Terraform 0.12+. --- group/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/group/main.tf b/group/main.tf index b95cbd8..319d4b6 100644 --- a/group/main.tf +++ b/group/main.tf @@ -53,7 +53,7 @@ data "template_cloudinit_config" "cloud_config" { ## Creates launch configuration & security group module "lc" { - source = "lc" + source = "./lc" ### Resource labels stack_item_fullname = "${var.stack_item_fullname}" @@ -90,7 +90,7 @@ module "lc" { ## Creates auto scaling group module "asg" { - source = "asg" + source = "./asg" ### Resource tags stack_item_label = "${var.stack_item_label}" From 524c5abf765c9b5286101f1f57549bcfe68f7385 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Wed, 1 May 2019 18:35:31 -0700 Subject: [PATCH 02/10] [0.12 compat] 0.12upgrade --- examples/basic/main.tf | 51 ++++++------- examples/basic/variables.tf | 47 ++++++------ examples/basic/versions.tf | 4 + examples/complete/main.tf | 94 +++++++++++++----------- examples/complete/variables.tf | 49 +++++++------ examples/complete/versions.tf | 4 + group/asg/main.tf | 91 +++++++++++------------ group/asg/outputs.tf | 11 ++- group/asg/variables.tf | 51 ++++++------- group/asg/versions.tf | 4 + group/lc/main.tf | 93 ++++++++++++----------- group/lc/outputs.tf | 8 +- group/lc/variables.tf | 53 +++++++------- group/lc/versions.tf | 4 + group/main.tf | 130 +++++++++++++++++---------------- group/outputs.tf | 9 ++- group/variables.tf | 101 ++++++++++++------------- group/versions.tf | 4 + policy/main.tf | 37 +++++----- policy/outputs.tf | 3 +- policy/variables.tf | 35 ++++----- policy/versions.tf | 4 + 22 files changed, 473 insertions(+), 414 deletions(-) create mode 100644 examples/basic/versions.tf create mode 100644 examples/complete/versions.tf create mode 100644 group/asg/versions.tf create mode 100644 group/lc/versions.tf create mode 100644 group/versions.tf create mode 100644 policy/versions.tf diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 32c0e68..cf9b258 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -2,7 +2,7 @@ ## Configures providers provider "aws" { - region = "${var.region}" + region = var.region } ## Adds security group rules @@ -10,7 +10,7 @@ resource "aws_security_group_rule" "sg_asg_egress" { cidr_blocks = ["0.0.0.0/0"] from_port = 0 protocol = -1 - security_group_id = "${module.example.sg_id}" + security_group_id = module.example.sg_id to_port = 0 type = "egress" @@ -23,7 +23,7 @@ resource "aws_security_group_rule" "sg_asg_ssh" { cidr_blocks = ["0.0.0.0/0"] from_port = 22 protocol = "tcp" - security_group_id = "${module.example.sg_id}" + security_group_id = module.example.sg_id to_port = 22 type = "ingress" @@ -39,32 +39,33 @@ module "example" { source = "../../group" # Resource tags - stack_item_fullname = "${var.stack_item_fullname}" - stack_item_label = "${var.stack_item_label}" + stack_item_fullname = var.stack_item_fullname + stack_item_label = var.stack_item_label # VPC parameters - subnets = ["${split(",",var.subnets)}"] - vpc_id = "${var.vpc_id}" + subnets = [split(",", var.subnets)] + vpc_id = var.vpc_id # LC parameters - ami = "${var.ami}" - associate_public_ip_address = "${var.associate_public_ip_address}" - enable_monitoring = "${var.enable_monitoring}" - instance_type = "${var.instance_type}" - key_name = "${var.key_name}" - security_groups = ["${split(",",var.security_groups)}"] - spot_price = "${var.spot_price}" + ami = var.ami + associate_public_ip_address = var.associate_public_ip_address + enable_monitoring = var.enable_monitoring + instance_type = var.instance_type + key_name = var.key_name + security_groups = [split(",", var.security_groups)] + spot_price = var.spot_price # ASG parameters - default_cooldown = "${var.default_cooldown}" - desired_capacity = "${var.desired_capacity}" - enabled_metrics = ["${split(",",var.enabled_metrics)}"] - force_delete = "${var.force_delete}" - hc_grace_period = "${var.hc_grace_period}" - max_size = "${var.max_size}" - min_size = "${var.min_size}" - protect_from_scale_in = "${var.protect_from_scale_in}" - suspended_processes = ["${split(",",var.suspended_processes)}"] - termination_policies = ["${split(",",var.termination_policies)}"] - wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}" + default_cooldown = var.default_cooldown + desired_capacity = var.desired_capacity + enabled_metrics = [split(",", var.enabled_metrics)] + force_delete = var.force_delete + hc_grace_period = var.hc_grace_period + max_size = var.max_size + min_size = var.min_size + protect_from_scale_in = var.protect_from_scale_in + suspended_processes = [split(",", var.suspended_processes)] + termination_policies = [split(",", var.termination_policies)] + wait_for_capacity_timeout = var.wait_for_capacity_timeout } + diff --git a/examples/basic/variables.tf b/examples/basic/variables.tf index c030c39..6a40996 100644 --- a/examples/basic/variables.tf +++ b/examples/basic/variables.tf @@ -2,110 +2,111 @@ ## Resource tags variable "stack_item_fullname" { - type = "string" + type = string } variable "stack_item_label" { - type = "string" + type = string } ## VPC parameters variable "subnets" { - type = "string" + type = string } variable "region" { - type = "string" + type = string } variable "vpc_id" { - type = "string" + type = string } ## LC parameters variable "ami" { - type = "string" + type = string } variable "associate_public_ip_address" { - type = "string" + type = string default = "" } variable "enable_monitoring" { - type = "string" + type = string default = "" } variable "instance_type" { - type = "string" + type = string } variable "key_name" { - type = "string" + type = string default = "" } variable "security_groups" { - type = "string" + type = string default = "" } variable "spot_price" { - type = "string" + type = string default = "" } ## ASG parameters variable "default_cooldown" { - type = "string" + type = string default = "" } variable "desired_capacity" { - type = "string" + type = string default = "" } variable "enabled_metrics" { - type = "string" + type = string default = "" } variable "force_delete" { - type = "string" + type = string default = "" } variable "hc_grace_period" { - type = "string" + type = string default = "" } variable "max_size" { - type = "string" + type = string } variable "min_size" { - type = "string" + type = string } variable "protect_from_scale_in" { - type = "string" + type = string default = "" } variable "suspended_processes" { - type = "string" + type = string default = "" } variable "termination_policies" { - type = "string" + type = string default = "" } variable "wait_for_capacity_timeout" { - type = "string" + type = string default = "" } + diff --git a/examples/basic/versions.tf b/examples/basic/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/examples/basic/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/complete/main.tf b/examples/complete/main.tf index efbd9d6..69dbead 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -2,7 +2,7 @@ ## Configures providers provider "aws" { - region = "${var.region}" + region = var.region } ## Creates IAM role @@ -26,11 +26,12 @@ resource "aws_iam_role" "role" { }] } EOF + } resource "aws_iam_role_policy" "policy_tagging" { name = "tagging" - role = "${aws_iam_role.role.id}" + role = aws_iam_role.role.id policy = < 0 ? var.asg_name_override : var.stack_item_label + propagate_at_launch = var.propagate_name_at_launch }, { key = "managed_by" @@ -22,54 +22,55 @@ locals { } resource "aws_autoscaling_group" "asg" { - count = "${length(var.min_elb_capacity) > 0 || length(var.wait_for_elb_capacity) > 0 ? 0 : 1}" + count = length(var.min_elb_capacity) > 0 || length(var.wait_for_elb_capacity) > 0 ? 0 : 1 - default_cooldown = "${length(var.default_cooldown) > 0 ? var.default_cooldown : "300"}" - desired_capacity = "${length(var.desired_capacity) > 0 ? var.desired_capacity : var.min_size}" - enabled_metrics = ["${compact(var.enabled_metrics)}"] - force_delete = "${var.force_delete}" - health_check_grace_period = "${length(var.hc_grace_period) > 0 ? var.hc_grace_period : "300"}" + default_cooldown = length(var.default_cooldown) > 0 ? var.default_cooldown : "300" + desired_capacity = length(var.desired_capacity) > 0 ? var.desired_capacity : var.min_size + enabled_metrics = compact(var.enabled_metrics) + force_delete = var.force_delete + health_check_grace_period = length(var.hc_grace_period) > 0 ? var.hc_grace_period : "300" health_check_type = "EC2" - launch_configuration = "${var.lc_id}" - max_size = "${var.max_size}" - metrics_granularity = "${var.metrics_granularity}" - min_size = "${var.min_size}" - name = "${length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label}" - placement_group = "${var.placement_group}" - protect_from_scale_in = "${var.protect_from_scale_in}" - suspended_processes = ["${compact(var.suspended_processes)}"] - target_group_arns = ["${compact(var.target_group_arns)}"] - termination_policies = ["${compact(var.termination_policies)}"] - vpc_zone_identifier = ["${compact(var.subnets)}"] - wait_for_capacity_timeout = "${length(var.wait_for_capacity_timeout) > 0 ? var.wait_for_capacity_timeout : "10m"}" + launch_configuration = var.lc_id + max_size = var.max_size + metrics_granularity = var.metrics_granularity + min_size = var.min_size + name = length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label + placement_group = var.placement_group + protect_from_scale_in = var.protect_from_scale_in + suspended_processes = compact(var.suspended_processes) + target_group_arns = compact(var.target_group_arns) + termination_policies = compact(var.termination_policies) + vpc_zone_identifier = compact(var.subnets) + wait_for_capacity_timeout = length(var.wait_for_capacity_timeout) > 0 ? var.wait_for_capacity_timeout : "10m" - tags = "${concat(local.default_asg_tags, var.additional_asg_tags)}" + tags = concat(local.default_asg_tags, var.additional_asg_tags) } resource "aws_autoscaling_group" "asg_elb" { - count = "${length(var.min_elb_capacity) > 0 || length(var.wait_for_elb_capacity) > 0 ? 1 : 0}" + count = length(var.min_elb_capacity) > 0 || length(var.wait_for_elb_capacity) > 0 ? 1 : 0 - default_cooldown = "${length(var.default_cooldown) > 0 ? var.default_cooldown : "300"}" - desired_capacity = "${length(var.desired_capacity) > 0 ? var.desired_capacity : var.min_size}" - enabled_metrics = ["${compact(var.enabled_metrics)}"] - force_delete = "${var.force_delete}" - health_check_grace_period = "${length(var.hc_grace_period) > 0 ? var.hc_grace_period : "300"}" - health_check_type = "${length(var.hc_check_type) > 0 ? var.hc_check_type : "ELB"}" - launch_configuration = "${var.lc_id}" - load_balancers = ["${compact(var.load_balancers)}"] - max_size = "${var.max_size}" - metrics_granularity = "${var.metrics_granularity}" - min_elb_capacity = "${length(var.min_elb_capacity) > 0 ? var.min_elb_capacity : "0"}" - min_size = "${var.min_size}" - name = "${length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label}" - placement_group = "${var.placement_group}" - protect_from_scale_in = "${var.protect_from_scale_in}" - suspended_processes = ["${compact(var.suspended_processes)}"] - target_group_arns = ["${compact(var.target_group_arns)}"] - termination_policies = ["${compact(var.termination_policies)}"] - vpc_zone_identifier = ["${compact(var.subnets)}"] - wait_for_capacity_timeout = "${length(var.wait_for_capacity_timeout) > 0 ? var.wait_for_capacity_timeout : "10m"}" - wait_for_elb_capacity = "${length(var.wait_for_elb_capacity) > 0 ? var.wait_for_elb_capacity : "0"}" + default_cooldown = length(var.default_cooldown) > 0 ? var.default_cooldown : "300" + desired_capacity = length(var.desired_capacity) > 0 ? var.desired_capacity : var.min_size + enabled_metrics = compact(var.enabled_metrics) + force_delete = var.force_delete + health_check_grace_period = length(var.hc_grace_period) > 0 ? var.hc_grace_period : "300" + health_check_type = length(var.hc_check_type) > 0 ? var.hc_check_type : "ELB" + launch_configuration = var.lc_id + load_balancers = compact(var.load_balancers) + max_size = var.max_size + metrics_granularity = var.metrics_granularity + min_elb_capacity = length(var.min_elb_capacity) > 0 ? var.min_elb_capacity : "0" + min_size = var.min_size + name = length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label + placement_group = var.placement_group + protect_from_scale_in = var.protect_from_scale_in + suspended_processes = compact(var.suspended_processes) + target_group_arns = compact(var.target_group_arns) + termination_policies = compact(var.termination_policies) + vpc_zone_identifier = compact(var.subnets) + wait_for_capacity_timeout = length(var.wait_for_capacity_timeout) > 0 ? var.wait_for_capacity_timeout : "10m" + wait_for_elb_capacity = length(var.wait_for_elb_capacity) > 0 ? var.wait_for_elb_capacity : "0" - tags = "${concat(local.default_asg_tags, var.additional_asg_tags)}" + tags = concat(local.default_asg_tags, var.additional_asg_tags) } + diff --git a/group/asg/outputs.tf b/group/asg/outputs.tf index 9a7eef7..35d1c18 100644 --- a/group/asg/outputs.tf +++ b/group/asg/outputs.tf @@ -1,9 +1,16 @@ # Outputs output "asg_id" { - value = "${coalesce(join(",",aws_autoscaling_group.asg.*.id),join(",",aws_autoscaling_group.asg_elb.*.id))}" + value = coalesce( + join(",", aws_autoscaling_group.asg.*.id), + join(",", aws_autoscaling_group.asg_elb.*.id), + ) } output "asg_name" { - value = "${coalesce(join(",",aws_autoscaling_group.asg.*.name),join(",",aws_autoscaling_group.asg_elb.*.name))}" + value = coalesce( + join(",", aws_autoscaling_group.asg.*.name), + join(",", aws_autoscaling_group.asg_elb.*.name), + ) } + diff --git a/group/asg/variables.tf b/group/asg/variables.tf index 0cf21c2..ae80465 100644 --- a/group/asg/variables.tf +++ b/group/asg/variables.tf @@ -2,109 +2,110 @@ ## Resource tags variable "stack_item_fullname" { - type = "string" + type = string } variable "stack_item_label" { - type = "string" + type = string } variable "additional_asg_tags" { - type = "list" + type = list(string) default = [] } ## Allow override of resource naming variable "asg_name_override" { - type = "string" + type = string } variable "propagate_name_at_launch" { - type = "string" + type = string default = "true" } ## VPC parameters variable "subnets" { - type = "list" + type = list(string) } ## LC parameters variable "lc_id" { - type = "string" + type = string } ## ASG parameters variable "default_cooldown" { - type = "string" + type = string } variable "desired_capacity" { - type = "string" + type = string } variable "enabled_metrics" { - type = "list" + type = list(string) } variable "force_delete" { - type = "string" + type = string } variable "hc_check_type" { - type = "string" + type = string } variable "hc_grace_period" { - type = "string" + type = string } variable "max_size" { - type = "string" + type = string } variable "metrics_granularity" { - type = "string" + type = string } variable "min_size" { - type = "string" + type = string } variable "placement_group" { - type = "string" + type = string } variable "protect_from_scale_in" { - type = "string" + type = string } variable "suspended_processes" { - type = "list" + type = list(string) } variable "termination_policies" { - type = "list" + type = list(string) } variable "wait_for_capacity_timeout" { - type = "string" + type = string } ## ELB parameters variable "load_balancers" { - type = "list" + type = list(string) } variable "min_elb_capacity" { - type = "string" + type = string } variable "target_group_arns" { - type = "list" + type = list(string) } variable "wait_for_elb_capacity" { - type = "string" + type = string } + diff --git a/group/asg/versions.tf b/group/asg/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/group/asg/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/group/lc/main.tf b/group/lc/main.tf index d45ac9a..1145264 100644 --- a/group/lc/main.tf +++ b/group/lc/main.tf @@ -3,13 +3,13 @@ ## Creates security group resource "aws_security_group" "sg_asg" { description = "${var.stack_item_fullname} security group" - name_prefix = "${length(var.lc_sg_name_prefix_override) > 0 ? format("%s-", var.lc_sg_name_prefix_override) : format("%s-asg-", var.stack_item_label)}" - vpc_id = "${var.vpc_id}" + name_prefix = length(var.lc_sg_name_prefix_override) > 0 ? format("%s-", var.lc_sg_name_prefix_override) : format("%s-asg-", var.stack_item_label) + vpc_id = var.vpc_id - tags { - application = "${var.stack_item_fullname}" + tags = { + application = var.stack_item_fullname managed_by = "terraform" - Name = "${length(var.lc_sg_name_prefix_override) > 0 ? var.lc_sg_name_prefix_override : format("%s-asg", var.stack_item_label)}" + Name = length(var.lc_sg_name_prefix_override) > 0 ? var.lc_sg_name_prefix_override : format("%s-asg", var.stack_item_label) } lifecycle { @@ -19,26 +19,28 @@ resource "aws_security_group" "sg_asg" { ## Creates launch configuration resource "aws_launch_configuration" "lc" { - count = "${length(var.ebs_vol_device_name) > 0 ? 0 : 1}" + count = length(var.ebs_vol_device_name) > 0 ? 0 : 1 - associate_public_ip_address = "${var.associate_public_ip_address}" - ebs_optimized = "${var.ebs_optimized}" - enable_monitoring = "${var.enable_monitoring}" - iam_instance_profile = "${var.instance_profile}" - image_id = "${var.ami}" - instance_type = "${var.instance_type}" - key_name = "${var.key_name}" + associate_public_ip_address = var.associate_public_ip_address + ebs_optimized = var.ebs_optimized + enable_monitoring = var.enable_monitoring + iam_instance_profile = var.instance_profile + image_id = var.ami + instance_type = var.instance_type + key_name = var.key_name name_prefix = "${var.stack_item_label}-" - placement_tenancy = "${var.placement_tenancy}" - security_groups = ["${distinct(concat(list(aws_security_group.sg_asg.id), compact(var.security_groups)))}"] - spot_price = "${var.spot_price}" - user_data = "${var.user_data}" + placement_tenancy = var.placement_tenancy + security_groups = distinct( + concat([aws_security_group.sg_asg.id], compact(var.security_groups)), + ) + spot_price = var.spot_price + user_data = var.user_data root_block_device { - delete_on_termination = "${var.root_vol_del_on_term}" - iops = "${var.root_vol_type == "io1" ? var.root_vol_iops : "0" }" - volume_size = "${length(var.root_vol_size) > 0 ? var.root_vol_size : "8"}" - volume_type = "${var.root_vol_type}" + delete_on_termination = var.root_vol_del_on_term + iops = var.root_vol_type == "io1" ? var.root_vol_iops : "0" + volume_size = length(var.root_vol_size) > 0 ? var.root_vol_size : "8" + volume_type = var.root_vol_type } lifecycle { @@ -47,39 +49,42 @@ resource "aws_launch_configuration" "lc" { } resource "aws_launch_configuration" "lc_ebs" { - count = "${length(var.ebs_vol_device_name) > 0 ? 1 : 0}" + count = length(var.ebs_vol_device_name) > 0 ? 1 : 0 - associate_public_ip_address = "${var.associate_public_ip_address}" - ebs_optimized = "${var.ebs_optimized}" - enable_monitoring = "${var.enable_monitoring}" - iam_instance_profile = "${var.instance_profile}" - image_id = "${var.ami}" - instance_type = "${var.instance_type}" - key_name = "${var.key_name}" + associate_public_ip_address = var.associate_public_ip_address + ebs_optimized = var.ebs_optimized + enable_monitoring = var.enable_monitoring + iam_instance_profile = var.instance_profile + image_id = var.ami + instance_type = var.instance_type + key_name = var.key_name name_prefix = "${var.stack_item_label}-" - placement_tenancy = "${var.placement_tenancy}" - security_groups = ["${distinct(concat(list(aws_security_group.sg_asg.id), compact(var.security_groups)))}"] - spot_price = "${var.spot_price}" - user_data = "${var.user_data}" + placement_tenancy = var.placement_tenancy + security_groups = distinct( + concat([aws_security_group.sg_asg.id], compact(var.security_groups)), + ) + spot_price = var.spot_price + user_data = var.user_data root_block_device { - delete_on_termination = "${var.root_vol_del_on_term}" - iops = "${var.root_vol_type == "io1" ? var.root_vol_iops : "0" }" - volume_size = "${length(var.root_vol_size) > 0 ? var.root_vol_size : "0"}" - volume_type = "${var.root_vol_type}" + delete_on_termination = var.root_vol_del_on_term + iops = var.root_vol_type == "io1" ? var.root_vol_iops : "0" + volume_size = length(var.root_vol_size) > 0 ? var.root_vol_size : "0" + volume_type = var.root_vol_type } ebs_block_device { - delete_on_termination = "${var.ebs_vol_del_on_term}" - device_name = "${var.ebs_vol_device_name}" - encrypted = "${length(var.ebs_vol_snapshot_id) > 0 ? "" : var.ebs_vol_encrypted}" - iops = "${var.ebs_vol_type == "io1" ? var.ebs_vol_iops : "0" }" - snapshot_id = "${var.ebs_vol_snapshot_id}" - volume_size = "${length(var.ebs_vol_snapshot_id) > 0 ? "0" : var.ebs_vol_size}" - volume_type = "${var.ebs_vol_type}" + delete_on_termination = var.ebs_vol_del_on_term + device_name = var.ebs_vol_device_name + encrypted = length(var.ebs_vol_snapshot_id) > 0 ? "" : var.ebs_vol_encrypted + iops = var.ebs_vol_type == "io1" ? var.ebs_vol_iops : "0" + snapshot_id = var.ebs_vol_snapshot_id + volume_size = length(var.ebs_vol_snapshot_id) > 0 ? "0" : var.ebs_vol_size + volume_type = var.ebs_vol_type } lifecycle { create_before_destroy = true } } + diff --git a/group/lc/outputs.tf b/group/lc/outputs.tf index 71b97af..5271632 100644 --- a/group/lc/outputs.tf +++ b/group/lc/outputs.tf @@ -1,9 +1,13 @@ # Outputs output "lc_id" { - value = "${coalesce(join(",",aws_launch_configuration.lc.*.id),join(",",aws_launch_configuration.lc_ebs.*.id))}" + value = coalesce( + join(",", aws_launch_configuration.lc.*.id), + join(",", aws_launch_configuration.lc_ebs.*.id), + ) } output "sg_id" { - value = "${aws_security_group.sg_asg.id}" + value = aws_security_group.sg_asg.id } + diff --git a/group/lc/variables.tf b/group/lc/variables.tf index 12939b8..5fb4b2b 100644 --- a/group/lc/variables.tf +++ b/group/lc/variables.tf @@ -2,108 +2,109 @@ ## Resource tags variable "stack_item_fullname" { - type = "string" + type = string } variable "stack_item_label" { - type = "string" + type = string } ## Allow override of resource naming variable "lc_sg_name_prefix_override" { - type = "string" + type = string } ## VPC parameters variable "vpc_id" { - type = "string" + type = string } ## LC parameters variable "associate_public_ip_address" { - type = "string" + type = string } variable "ami" { - type = "string" + type = string } variable "ebs_optimized" { - type = "string" + type = string } variable "ebs_vol_del_on_term" { - type = "string" + type = string } variable "ebs_vol_device_name" { - type = "string" + type = string } variable "ebs_vol_encrypted" { - type = "string" + type = string } variable "ebs_vol_snapshot_id" { - type = "string" + type = string } variable "ebs_vol_iops" { - type = "string" + type = string } variable "ebs_vol_size" { - type = "string" + type = string } variable "ebs_vol_type" { - type = "string" + type = string } variable "enable_monitoring" { - type = "string" + type = string } variable "instance_profile" { - type = "string" + type = string } variable "instance_type" { - type = "string" + type = string } variable "key_name" { - type = "string" + type = string } variable "placement_tenancy" { - type = "string" + type = string } variable "root_vol_del_on_term" { - type = "string" + type = string } variable "root_vol_iops" { - type = "string" + type = string } variable "root_vol_size" { - type = "string" + type = string } variable "root_vol_type" { - type = "string" + type = string } variable "security_groups" { - type = "list" + type = list(string) } variable "spot_price" { - type = "string" + type = string } variable "user_data" { - type = "string" + type = string } + diff --git a/group/lc/versions.tf b/group/lc/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/group/lc/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/group/main.tf b/group/main.tf index 319d4b6..a76053b 100644 --- a/group/main.tf +++ b/group/main.tf @@ -6,26 +6,27 @@ terraform { } ## Creates cloudconfig fragments for tagging -data "aws_region" "current" {} +data "aws_region" "current" { +} data "template_file" "name" { - template = "${var.instance_based_naming_enabled == "true" ? file("${path.module}/templates/name.tpl") : ""}" + template = var.instance_based_naming_enabled == "true" ? file("${path.module}/templates/name.tpl") : "" - vars { - name_prefix = "${length(var.instance_name_prefix) > 0 ? var.instance_name_prefix : var.stack_item_label}" - region = "${data.aws_region.current.name}" + vars = { + name_prefix = length(var.instance_name_prefix) > 0 ? var.instance_name_prefix : var.stack_item_label + region = data.aws_region.current.name } } data "template_file" "tags" { - count = "${length(keys(var.instance_tags))}" + count = length(keys(var.instance_tags)) - template = "${element(keys(var.instance_tags),count.index) != "" ? file("${path.module}/templates/tag.tpl") : ""}" + template = element(keys(var.instance_tags), count.index) != "" ? file("${path.module}/templates/tag.tpl") : "" - vars { - key = "${element(keys(var.instance_tags),count.index)}" - region = "${data.aws_region.current.name}" - value = "${lookup(var.instance_tags,element(keys(var.instance_tags),count.index))}" + vars = { + key = element(keys(var.instance_tags), count.index) + region = data.aws_region.current.name + value = var.instance_tags[element(keys(var.instance_tags), count.index)] } } @@ -35,18 +36,18 @@ data "template_cloudinit_config" "cloud_config" { part { content_type = "text/cloud-config" - content = "${var.user_data}" + content = var.user_data } part { content_type = "text/cloud-config" - content = "${data.template_file.name.rendered}" + content = data.template_file.name.rendered merge_type = "list(append)+dict(recurse_array)+str()" } part { content_type = "text/cloud-config" - content = "#cloud-config\nruncmd:\n${join("",data.template_file.tags.*.rendered)}" + content = "#cloud-config\nruncmd:\n${join("", data.template_file.tags.*.rendered)}" merge_type = "list(append)+dict(recurse_array)+str()" } } @@ -56,36 +57,36 @@ module "lc" { source = "./lc" ### Resource labels - stack_item_fullname = "${var.stack_item_fullname}" - stack_item_label = "${var.stack_item_label}" - lc_sg_name_prefix_override = "${var.lc_sg_name_prefix_override}" + stack_item_fullname = var.stack_item_fullname + stack_item_label = var.stack_item_label + lc_sg_name_prefix_override = var.lc_sg_name_prefix_override ### VPC parameters - vpc_id = "${var.vpc_id}" + vpc_id = var.vpc_id ### LC parameters - ami = "${var.ami}" - associate_public_ip_address = "${var.associate_public_ip_address}" - ebs_optimized = "${var.ebs_optimized}" - ebs_vol_del_on_term = "${var.ebs_vol_del_on_term}" - ebs_vol_device_name = "${var.ebs_vol_device_name}" - ebs_vol_encrypted = "${var.ebs_vol_encrypted}" - ebs_vol_iops = "${var.ebs_vol_iops}" - ebs_vol_size = "${var.ebs_vol_size}" - ebs_vol_snapshot_id = "${var.ebs_vol_snapshot_id}" - ebs_vol_type = "${var.ebs_vol_type}" - enable_monitoring = "${var.enable_monitoring}" - instance_profile = "${var.instance_profile}" - instance_type = "${var.instance_type}" - key_name = "${var.key_name}" - placement_tenancy = "${var.placement_tenancy}" - root_vol_del_on_term = "${var.root_vol_del_on_term}" - root_vol_iops = "${var.root_vol_iops}" - root_vol_size = "${var.root_vol_size}" - root_vol_type = "${var.root_vol_type}" - security_groups = ["${var.security_groups}"] - spot_price = "${var.spot_price}" - user_data = "${data.template_cloudinit_config.cloud_config.rendered}" + ami = var.ami + associate_public_ip_address = var.associate_public_ip_address + ebs_optimized = var.ebs_optimized + ebs_vol_del_on_term = var.ebs_vol_del_on_term + ebs_vol_device_name = var.ebs_vol_device_name + ebs_vol_encrypted = var.ebs_vol_encrypted + ebs_vol_iops = var.ebs_vol_iops + ebs_vol_size = var.ebs_vol_size + ebs_vol_snapshot_id = var.ebs_vol_snapshot_id + ebs_vol_type = var.ebs_vol_type + enable_monitoring = var.enable_monitoring + instance_profile = var.instance_profile + instance_type = var.instance_type + key_name = var.key_name + placement_tenancy = var.placement_tenancy + root_vol_del_on_term = var.root_vol_del_on_term + root_vol_iops = var.root_vol_iops + root_vol_size = var.root_vol_size + root_vol_type = var.root_vol_type + security_groups = [var.security_groups] + spot_price = var.spot_price + user_data = data.template_cloudinit_config.cloud_config.rendered } ## Creates auto scaling group @@ -93,37 +94,38 @@ module "asg" { source = "./asg" ### Resource tags - stack_item_label = "${var.stack_item_label}" - stack_item_fullname = "${var.stack_item_fullname}" - asg_name_override = "${var.asg_name_override}" - propagate_name_at_launch = "${var.propagate_name_at_launch}" + stack_item_label = var.stack_item_label + stack_item_fullname = var.stack_item_fullname + asg_name_override = var.asg_name_override + propagate_name_at_launch = var.propagate_name_at_launch ### VPC parameters - subnets = ["${var.subnets}"] + subnets = [var.subnets] ### LC parameters - lc_id = "${module.lc.lc_id}" + lc_id = module.lc.lc_id ### ASG parameters - default_cooldown = "${var.default_cooldown}" - desired_capacity = "${var.desired_capacity}" - enabled_metrics = ["${var.enabled_metrics}"] - force_delete = "${var.force_delete}" - hc_check_type = "${var.hc_check_type}" - hc_grace_period = "${var.hc_grace_period}" - max_size = "${var.max_size}" + default_cooldown = var.default_cooldown + desired_capacity = var.desired_capacity + enabled_metrics = [var.enabled_metrics] + force_delete = var.force_delete + hc_check_type = var.hc_check_type + hc_grace_period = var.hc_grace_period + max_size = var.max_size metrics_granularity = "1Minute" - min_size = "${var.min_size}" - placement_group = "${var.placement_group}" - protect_from_scale_in = "${var.protect_from_scale_in}" - suspended_processes = ["${var.suspended_processes}"] - termination_policies = ["${var.termination_policies}"] - wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}" - additional_asg_tags = "${var.additional_asg_tags}" + min_size = var.min_size + placement_group = var.placement_group + protect_from_scale_in = var.protect_from_scale_in + suspended_processes = [var.suspended_processes] + termination_policies = [var.termination_policies] + wait_for_capacity_timeout = var.wait_for_capacity_timeout + additional_asg_tags = var.additional_asg_tags ### ELB parameters - load_balancers = ["${var.load_balancers}"] - min_elb_capacity = "${var.min_elb_capacity}" - target_group_arns = ["${var.target_group_arns}"] - wait_for_elb_capacity = "${var.wait_for_elb_capacity}" + load_balancers = [var.load_balancers] + min_elb_capacity = var.min_elb_capacity + target_group_arns = [var.target_group_arns] + wait_for_elb_capacity = var.wait_for_elb_capacity } + diff --git a/group/outputs.tf b/group/outputs.tf index 847616b..c4a3c9e 100644 --- a/group/outputs.tf +++ b/group/outputs.tf @@ -1,17 +1,18 @@ # Outputs output "asg_id" { - value = "${module.asg.asg_id}" + value = module.asg.asg_id } output "asg_name" { - value = "${module.asg.asg_name}" + value = module.asg.asg_name } output "lc_id" { - value = "${module.lc.lc_id}" + value = module.lc.lc_id } output "sg_id" { - value = "${module.lc.sg_id}" + value = module.lc.sg_id } + diff --git a/group/variables.tf b/group/variables.tf index 720e288..1be0c9d 100644 --- a/group/variables.tf +++ b/group/variables.tf @@ -2,76 +2,76 @@ ## Resource tags variable "stack_item_fullname" { - type = "string" + type = string description = "Long form descriptive name for this stack item. This value is used to create the 'application' resource tag for resources created by this stack item." } variable "stack_item_label" { - type = "string" + type = string description = "Short form identifier for this stack. This value is used to create the 'Name' resource tag for resources created by this stack item, and also serves as a unique key for re-use." } variable "asg_name_override" { - type = "string" + type = string description = "A string to override the ASG name" default = "" } variable "lc_sg_name_prefix_override" { - type = "string" + type = string description = "A string to override the ASG name" default = "" } variable "propagate_name_at_launch" { - type = "string" + type = string description = "A string to override the ASG name" default = "true" } ## VPC parameters variable "subnets" { - type = "list" + type = list(string) description = "A list of subnet IDs to launch resources in" } variable "vpc_id" { - type = "string" + type = string description = "ID of the target VPC." } ## LC parameters variable "ami" { - type = "string" + type = string description = "Amazon Machine Image (AMI) to associate with the launch configuration." } variable "associate_public_ip_address" { - type = "string" + type = string description = "Flag for associating public IP addresses with instances managed by the auto scaling group." default = "" } variable "ebs_optimized" { - type = "string" + type = string description = "Flag to enable EBS optimization." default = "false" } variable "ebs_vol_del_on_term" { - type = "string" + type = string description = "Whether the volume should be destroyed on instance termination." default = "true" } variable "ebs_vol_device_name" { - type = "string" + type = string description = "The name of the device to mount." default = "" } variable "ebs_vol_encrypted" { - type = "string" + type = string description = "Whether the volume should be encrypted or not. Do not use this option if you are using 'snapshot_id' as the encrypted flag will be determined by the snapshot." default = "" } @@ -81,55 +81,55 @@ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html For the best per-I/O latency experience, we recommend that you provision an IOPS-to-GiB ratio greater than 2:1. For example, a 2,000 IOPS volume should be smaller than 1,000 GiB. */ variable "ebs_vol_iops" { - type = "string" + type = string description = "The amount of provisioned IOPS" default = "2000" } variable "ebs_vol_size" { - type = "string" + type = string description = "The size of the volume in gigabytes." default = "" } variable "ebs_vol_snapshot_id" { - type = "string" + type = string description = "The Snapshot ID to mount." default = "" } variable "ebs_vol_type" { - type = "string" + type = string description = "The type of volume. Valid values are 'standard', 'gp2' and 'io1'." default = "gp2" } variable "enable_monitoring" { - type = "string" + type = string description = "Flag to enable detailed monitoring." default = "" } variable "instance_based_naming_enabled" { - type = "string" + type = string description = "Flag to enable instance-id based name tagging." default = "" } variable "instance_name_prefix" { - type = "string" + type = string description = "Sring to prepend instance-id based name tags with." default = "" } variable "instance_profile" { - type = "string" + type = string description = "IAM instance profile to associate with the launch configuration." default = "" } variable "instance_tags" { - type = "map" + type = map(string) description = "Map of tags to add to isntances." default = { @@ -138,24 +138,24 @@ variable "instance_tags" { } variable "instance_type" { - type = "string" + type = string description = "EC2 instance type to associate with the launch configuration." } variable "key_name" { - type = "string" + type = string description = "SSH key pair to associate with the launch configuration." default = "" } variable "placement_tenancy" { - type = "string" + type = string description = "The tenancy of the instance. Valid values are 'default' or 'dedicated'." default = "default" } variable "root_vol_del_on_term" { - type = "string" + type = string description = "Whether the volume should be destroyed on instance termination." default = "true" } @@ -165,145 +165,146 @@ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html For the best per-I/O latency experience, we recommend that you provision an IOPS-to-GiB ratio greater than 2:1. For example, a 2,000 IOPS volume should be smaller than 1,000 GiB. */ variable "root_vol_iops" { - type = "string" + type = string description = "The amount of provisioned IOPS" default = "2000" } variable "root_vol_size" { - type = "string" + type = string description = "The size of the volume in gigabytes." default = "" } variable "root_vol_type" { - type = "string" + type = string description = "The type of volume. Valid values are 'standard', 'gp2' and 'io1'." default = "gp2" } variable "security_groups" { - type = "list" + type = list(string) description = "A list of associated security group IDs" default = [] } variable "spot_price" { - type = "string" + type = string description = "The price to use for reserving spot instances." default = "" } variable "user_data" { - type = "string" + type = string description = "Instance initialization data to associate with the launch configuration." default = "" } ## ASG parameters variable "additional_asg_tags" { - type = "list" + type = list(string) description = "Additional tags to apply at the ASG level, if any" default = [] } variable "default_cooldown" { - type = "string" + type = string description = "The amount of time, in seconds, after a scaling activity completes before another scaling activity can start." default = "" } variable "desired_capacity" { - type = "string" + type = string description = "The number of Amazon EC2 instances that should be running in the group." default = "" } variable "enabled_metrics" { - type = "list" + type = list(string) description = "A list of metrics to collect. The allowed values are 'GroupMinSize', 'GroupMaxSize', 'GroupDesiredCapacity', 'GroupInServiceInstances', 'GroupPendingInstances', 'GroupStandbyInstances', 'GroupTerminatingInstances', 'GroupTotalInstances'." default = [] } variable "force_delete" { - type = "string" + type = string description = "Flag to allow deletion of the auto scaling group without waiting for all instances in the pool to terminate." default = "false" } variable "hc_check_type" { - type = "string" + type = string description = "Type of health check performed by the auto scaling group. Valid values are 'ELB' or 'EC2'." default = "" } variable "hc_grace_period" { - type = "string" + type = string description = "Time allowed after an instance comes into service before checking health." default = "" } variable "max_size" { - type = "string" + type = string description = "Maximum number of instances allowed by the auto scaling group." } variable "min_size" { - type = "string" + type = string description = "Minimum number of instance to be maintained by the auto scaling group." } variable "placement_group" { - type = "string" + type = string description = "The name of the placement group into which you'll launch your instances, if any." default = "" } variable "protect_from_scale_in" { - type = "string" + type = string description = "Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events." default = "" } variable "suspended_processes" { - type = "list" + type = list(string) description = "A list of processes to suspend for the AutoScaling Group. The allowed values are 'Launch', 'Terminate', 'HealthCheck', 'ReplaceUnhealthy', 'AZRebalance', 'AlarmNotification', 'ScheduledActions', 'AddToLoadBalancer'. Note that if you suspend either the 'Launch' or 'Terminate' process types, it can prevent your autoscaling group from functioning properly." default = [] } variable "termination_policies" { - type = "list" + type = list(string) description = "A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are 'OldestInstance', 'NewestInstance', 'OldestLaunchConfiguration', 'ClosestToNextInstanceHour', 'Default'." default = [] } variable "wait_for_capacity_timeout" { - type = "string" + type = string description = "A maximum duration that Terraform should wait for ASG managed instances to become healthy before timing out." default = "" } ## ELB parameters variable "load_balancers" { - type = "list" + type = list(string) description = "List of load balancer names to associate with the auto scaling group." default = [] } variable "min_elb_capacity" { - type = "string" + type = string description = "Minimum number of healthy instances attached to the ELB that must be maintained during updates." default = "" } variable "target_group_arns" { - type = "list" + type = list(string) description = "A list of 'aws_alb_target_group' ARNs, for use with Application Load Balancing" default = [] } variable "wait_for_elb_capacity" { - type = "string" + type = string description = "Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. (Takes precedence over 'min_elb_capacity' behavior.)" default = "" } + diff --git a/group/versions.tf b/group/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/group/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/policy/main.tf b/policy/main.tf index 194172f..cbdf59a 100644 --- a/policy/main.tf +++ b/policy/main.tf @@ -7,12 +7,12 @@ terraform { ## Creates simple scaling policy resource "aws_autoscaling_policy" "asg_policy_simple" { - adjustment_type = "${var.adjustment_type}" - autoscaling_group_name = "${var.asg_name}" - cooldown = "${var.cooldown}" - name = "${var.stack_item_label}" + adjustment_type = var.adjustment_type + autoscaling_group_name = var.asg_name + cooldown = var.cooldown + name = var.stack_item_label policy_type = "SimpleScaling" - scaling_adjustment = "${var.scaling_adjustment}" + scaling_adjustment = var.scaling_adjustment } ## Creates Simple Notification Service (SNS) topic @@ -23,28 +23,29 @@ resource "aws_sns_topic" "sns_asg" { ## Configures autoscaling notifications resource "aws_autoscaling_notification" "asg_notify" { - group_names = ["${var.asg_name}"] - notifications = ["${var.notifications}"] - topic_arn = "${aws_sns_topic.sns_asg.arn}" + group_names = [var.asg_name] + notifications = var.notifications + topic_arn = aws_sns_topic.sns_asg.arn } ## Creates CloudWatch monitor resource "aws_cloudwatch_metric_alarm" "monitor_asg" { actions_enabled = true - alarm_actions = ["${aws_autoscaling_policy.asg_policy_simple.arn}"] + alarm_actions = [aws_autoscaling_policy.asg_policy_simple.arn] alarm_description = "${var.stack_item_fullname} ASG Monitor" alarm_name = "${var.stack_item_label}-asg" - comparison_operator = "${var.comparison_operator}" + comparison_operator = var.comparison_operator dimensions = { - "AutoScalingGroupName" = "${var.asg_name}" + "AutoScalingGroupName" = var.asg_name } - evaluation_periods = "${var.evaluation_periods}" - metric_name = "${var.metric_name}" - namespace = "${var.name_space}" - period = "${var.period}" - statistic = "${lookup(var.valid_statistics, var.statistic)}" - threshold = "${var.threshold}" - treat_missing_data = "${lookup(var.valid_missing_data, var.treat_missing_data)}" + evaluation_periods = var.evaluation_periods + metric_name = var.metric_name + namespace = var.name_space + period = var.period + statistic = var.valid_statistics[var.statistic] + threshold = var.threshold + treat_missing_data = var.valid_missing_data[var.treat_missing_data] } + diff --git a/policy/outputs.tf b/policy/outputs.tf index eb5abf5..47cba10 100644 --- a/policy/outputs.tf +++ b/policy/outputs.tf @@ -1,5 +1,6 @@ # Outputs output "sns_arn" { - value = "${aws_sns_topic.sns_asg.arn}" + value = aws_sns_topic.sns_asg.arn } + diff --git a/policy/variables.tf b/policy/variables.tf index c3a3b29..8a337f5 100644 --- a/policy/variables.tf +++ b/policy/variables.tf @@ -2,90 +2,90 @@ ## Resource tags variable "stack_item_fullname" { - type = "string" + type = string description = "Long form descriptive name for this stack item. This value is used to create the 'application' resource tag for resources created by this stack item." } variable "stack_item_label" { - type = "string" + type = string description = "Short form identifier for this stack. This value is used to create the 'Name' resource tag for resources created by this stack item, and also serves as a unique key for re-use." } ## ASG parameters variable "asg_name" { - type = "string" + type = string description = "Name of the ASG to associate the alarm with." } ## Notification parameters variable "notifications" { - type = "list" + type = list(string) description = "List of events to associate with the auto scaling notification." default = ["autoscaling:EC2_INSTANCE_LAUNCH", "autoscaling:EC2_INSTANCE_TERMINATE", "autoscaling:EC2_INSTANCE_LAUNCH_ERROR", "autoscaling:EC2_INSTANCE_TERMINATE_ERROR"] } ## Policy parameters variable "adjustment_type" { - type = "string" + type = string description = "Specifies the scaling adjustment. Valid values are 'ChangeInCapacity', 'ExactCapacity' or 'PercentChangeInCapacity'." } variable "cooldown" { - type = "string" + type = string description = "Seconds between auto scaling activities." } variable "scaling_adjustment" { - type = "string" + type = string description = "The number of instances involved in a scaling action." } ## Monitor parameters variable "comparison_operator" { - type = "string" + type = string description = "Arithmetic operation to use when comparing the thresholds. Valid values are 'GreaterThanOrEqualToThreshold', 'GreaterThanThreshold', 'LessThanThreshold' and 'LessThanOrEqualToThreshold'" } variable "evaluation_periods" { - type = "string" + type = string description = "The number of periods over which data is compared to the specified threshold." } variable "metric_name" { - type = "string" + type = string description = "Name for the alarm's associated metric." } variable "name_space" { - type = "string" + type = string description = "The namespace for the alarm's associated metric." default = "AWS/EC2" } variable "period" { - type = "string" + type = string description = "The period in seconds over which the specified statistic is applied." } variable "statistic" { - type = "string" + type = string description = "The statistic to apply to the alarm's associated metric. Valid values are 'SampleCount', 'Average', 'Sum', 'Minimum' and 'Maximum'" default = "Average" } variable "threshold" { - type = "string" + type = string description = "The value against which the specified statistic is compared." } variable "treat_missing_data" { - type = "string" + type = string description = "You can specfy how alarms handle missing data points. Valid values are 'missing': the alarm looks back farther in time to find additional data points, 'notBreaching': treated as a data point that is within the threshold, 'breaching': treated as a data point that is breaching the threshold, 'ignore': the current alarm state is maintained." default = "missing" } variable "valid_missing_data" { - type = "map" + type = map(string) default = { missing = "missing" @@ -96,7 +96,7 @@ variable "valid_missing_data" { } variable "valid_statistics" { - type = "map" + type = map(string) default = { Average = "Average" @@ -106,3 +106,4 @@ variable "valid_statistics" { Sum = "Sum" } } + diff --git a/policy/versions.tf b/policy/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/policy/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} From e61cb6966173a912f473a963d51b0125c10dfb9c Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Thu, 9 May 2019 19:16:59 -0700 Subject: [PATCH 03/10] Fix list coercions --- group/main.tf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/group/main.tf b/group/main.tf index a76053b..144fe90 100644 --- a/group/main.tf +++ b/group/main.tf @@ -84,7 +84,7 @@ module "lc" { root_vol_iops = var.root_vol_iops root_vol_size = var.root_vol_size root_vol_type = var.root_vol_type - security_groups = [var.security_groups] + security_groups = var.security_groups spot_price = var.spot_price user_data = data.template_cloudinit_config.cloud_config.rendered } @@ -100,7 +100,7 @@ module "asg" { propagate_name_at_launch = var.propagate_name_at_launch ### VPC parameters - subnets = [var.subnets] + subnets = var.subnets ### LC parameters lc_id = module.lc.lc_id @@ -108,7 +108,7 @@ module "asg" { ### ASG parameters default_cooldown = var.default_cooldown desired_capacity = var.desired_capacity - enabled_metrics = [var.enabled_metrics] + enabled_metrics = var.enabled_metrics force_delete = var.force_delete hc_check_type = var.hc_check_type hc_grace_period = var.hc_grace_period @@ -117,15 +117,15 @@ module "asg" { min_size = var.min_size placement_group = var.placement_group protect_from_scale_in = var.protect_from_scale_in - suspended_processes = [var.suspended_processes] - termination_policies = [var.termination_policies] + suspended_processes = var.suspended_processes + termination_policies = var.termination_policies wait_for_capacity_timeout = var.wait_for_capacity_timeout additional_asg_tags = var.additional_asg_tags ### ELB parameters - load_balancers = [var.load_balancers] + load_balancers = var.load_balancers min_elb_capacity = var.min_elb_capacity - target_group_arns = [var.target_group_arns] + target_group_arns = var.target_group_arns wait_for_elb_capacity = var.wait_for_elb_capacity } From 4c8b55a8dd68c661d67366689e23cf5aada833a4 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Thu, 9 May 2019 19:39:20 -0700 Subject: [PATCH 04/10] default to false? --- group/lc/variables.tf | 1 + group/variables.tf | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/group/lc/variables.tf b/group/lc/variables.tf index 5fb4b2b..539368e 100644 --- a/group/lc/variables.tf +++ b/group/lc/variables.tf @@ -22,6 +22,7 @@ variable "vpc_id" { ## LC parameters variable "associate_public_ip_address" { type = string + default = "false" } variable "ami" { diff --git a/group/variables.tf b/group/variables.tf index 1be0c9d..8371ee1 100644 --- a/group/variables.tf +++ b/group/variables.tf @@ -49,7 +49,7 @@ variable "ami" { variable "associate_public_ip_address" { type = string description = "Flag for associating public IP addresses with instances managed by the auto scaling group." - default = "" + default = "false" } variable "ebs_optimized" { From 698621cf0369b1c36d3c0895fe082cee6849dc17 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Fri, 10 May 2019 13:58:36 -0700 Subject: [PATCH 05/10] Filling in empty booleans hur durr --- group/asg/variables.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/group/asg/variables.tf b/group/asg/variables.tf index ae80465..a988c8d 100644 --- a/group/asg/variables.tf +++ b/group/asg/variables.tf @@ -78,6 +78,7 @@ variable "placement_group" { variable "protect_from_scale_in" { type = string + default = "false" } variable "suspended_processes" { From 909a42fe36c3abd46c474f9847f75579eb54b4ec Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Fri, 10 May 2019 17:16:32 -0700 Subject: [PATCH 06/10] gtm --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a3d7314..5b44956 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.tfstate* .terraform/ spec/reports/* +/.gtm/ From 9d960e25680e0dc77f5782772cded776e28da2ca Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Fri, 10 May 2019 17:24:29 -0700 Subject: [PATCH 07/10] default to false? --- group/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group/variables.tf b/group/variables.tf index 8371ee1..435355a 100644 --- a/group/variables.tf +++ b/group/variables.tf @@ -262,7 +262,7 @@ variable "placement_group" { variable "protect_from_scale_in" { type = string description = "Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events." - default = "" + default = "false" } variable "suspended_processes" { From 97901b56359ab41a0a2077b689e286b4925c22cb Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 8 Oct 2019 17:25:35 -0700 Subject: [PATCH 08/10] Update Covalence for TF 0.12 * Updated circleci and covalence to use unifiouat account. * Updated values to use default vpc/subnets/sgs from new account. * Updated covalence launcher script. --- .circleci/config.yml | 3 +- .env.covalence | 11 ++ .env.docker | 10 +- README.md | 2 +- bin/.covalence/launcher | 338 ++++++++++++++++++++++++++++++++++ bin/covalence | 322 +------------------------------- data/globals.yaml | 10 +- data/stacks/asg-elb-wait.yaml | 4 +- data/stacks/asg-elb.yaml | 4 +- data/stacks/asg-options.yaml | 6 +- data/stacks/common.yaml | 12 +- data/stacks/defaults.yaml | 4 +- data/stacks/lc-ebs-new.yaml | 4 +- data/stacks/lc-ebs-snap.yaml | 4 +- data/stacks/lc-options.yaml | 6 +- 15 files changed, 391 insertions(+), 349 deletions(-) create mode 100644 .env.covalence create mode 100755 bin/.covalence/launcher diff --git a/.circleci/config.yml b/.circleci/config.yml index 8d22d39..1875cda 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,11 +2,10 @@ common: &common working_directory: ~/repo docker: - - image: unifio/ci:3.0.551-ruby-2.5.1 + - image: unifio/ci:5.0.718-ruby-2.5.5 environment: AWS_REGION: 'us-east-2' - TF_PLUGIN_CACHE_DIR: '/root/.terraform.d/plugin-cache' version: 2 diff --git a/.env.covalence b/.env.covalence new file mode 100644 index 0000000..0cebda9 --- /dev/null +++ b/.env.covalence @@ -0,0 +1,11 @@ +DOCKER_IMAGE_NAME=unifio/ci:5.0.718-ruby-2.5.5 +# Sets the user running inside docker to match current user's uid and gid +# CONTAINER_USER_ID=$(id -u) + +# AWS_CREDENTIAL_PATH is to specify where we look for your AWS credentials file. +# This will be mounted into container so that Terraform can use them. +AWS_CREDENTIAL_PATH=~/.aws + +# DOCKER_HOMEDIR is where we are mounting the AWS_CREDENTIAL_PATH in container +DOCKER_HOMEDIR=/root +#COVALENCE_DEBUG=true diff --git a/.env.docker b/.env.docker index bc7333f..f747f4b 100644 --- a/.env.docker +++ b/.env.docker @@ -1,7 +1,7 @@ -AWS_REGION=us-east-2 -COVALENCE_PACKER_DIR=./ -COVALENCE_TERRAFORM_DIR=./ +AWS_REGION=us-east-1 +CI_REPORTS=reports COVALENCE_TEST_ENVS=basic CHECKPOINT_DISABLE=1 -GODEBUG=netdns=cgo -USER=root +AWS_PROFILE=unifiouat +AWS_DEFAULT_PROFILE=unifiouat +AWS_DEFAULT_REGION=us-east-1 diff --git a/README.md b/README.md index e98c19e..5f59f29 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ module "asg" { instance_based_naming_enabled = true instance_type = "m4.large" key_name = "ops" - security_groups = "sg-c1afc0a8,sg-d4f906bd" + security_groups = "sg-c1afc0a8,sg-7e33f32f" spot price = "0.010" user_data = "${template_file.user_data.rendered}" diff --git a/bin/.covalence/launcher b/bin/.covalence/launcher new file mode 100755 index 0000000..0a86549 --- /dev/null +++ b/bin/.covalence/launcher @@ -0,0 +1,338 @@ +#!/usr/bin/env bash +# Run from the source tree root +cd `dirname $0` +cd ../.. +### Environment Variables +# Variables are used for determining CI settings +# Variable precedence is as follows with the last taking +# the highest precedence +# +# 1. Default values +# 2. Exported environment variables +# 3. .env.covalence loaded values +# 4. bin/covalence argument switches +# +# source local .env.covalence file if present +LOCAL_ENVFILE=${LOCAL_ENVFILE:-".env.covalence"} + +# If set to true will no use old docker-wrapper behavior +# omitting the `rake` command +DOCKER_WRAPPER=${DOCKER_WRAPPER:-} +# The docker environment variable file passed to the container +# Can contain multiple envfiles separated by : env1:env2:env3 +LOAD_ENVFILE=${LOAD_ENVFILE:-".env.docker:.env.secrets"} +# AWS Credentials path to mount (defaults to data/secure/.aws) +AWS_CREDENTIAL_PATH=${AWS_CREDENTIAL_PATH:-"$HOME/.aws"} +# The Container home directory +DOCKER_HOMEDIR=${DOCKER_HOMEDIR:-"/root"} +# The docker DNS can be updated to AWS DNS +DOCKER_DNS=${DOCKER_DNS:-} +# If you want docker to run as specific user +CONTAINER_USER_ID=${CONTAINER_USER_ID:-} +# Alternative Covalence Rakefile can be specified +# will add `-f Rakefile`` +COVALENCE_RAKEFILE=${COVALENCE_RAKEFILE:-} +# Alternative Covalence configuration can be specified +COVALENCE_CONFIG=${COVALENCE_CONFIG:-"covalence.yaml"} +# Environments to be included in CI +COVALENCE_TEST_ENVS=${COVALENCE_TEST_ENVS:-} +# The Container image to use for the ci defaults to unifio/ci latest +DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-"unifio/ci"} +# Enable debugging of script +S_DEBUG=${S_DEBUG:-} +# Dump verbose information about commands without executing them. +DUMP_ENV=${DUMP_ENV:-} +# Causes covalence rake -T +LIST_RAKE_TASKS=${LIST_RAKE_TASKS:-} +# Adds volume to docker container HOST_MNT:CONTAINER_MNT +ADD_VOLUMES=${ADD_VOLUMES:-} +# Can be used to change docker run behavior ie -it vs --rm +DOCKER_RUN_TYPE=${DOCKER_RUN_TYPE:-"--rm"} +# TEST_HOST_LOCAL is used for specifying a domain to overload +# and point to the Docker host IP in the container /etc/host file +# --add-host CONSUL_TEST_IP will be set automatically +TEST_HOST_LOCAL=${TEST_HOST_LOCAL:-} +CONSUL_TEST_IP=${CONSUL_TEST_IP:-} +# Allows specifying --entrypoint= command +ENTRYPOINT=${ENTRYPOINT:-} +# Interactive Shell enabled +INTSHELL=${INTSHELL:-} +# Sets the Docker workspace to mount and set as working directory -w +DOCKER_WORKSPACE=${DOCKER_WORKSPACE:-"/workspace"} +# The project root directory to mount in docker workspace +SRC_ROOT=${SRC_ROOT:-"$(pwd)"} +# Atlas and AWS tokens if needed but defaults to .aws +# For possible future use currently should be set in .env.docker +#ATLAS_TOKEN=${AWS_SECRET_ACCESS_KEY:-} +#AWS_ACCESS_KEY_ID=${AWS_SECRET_ACCESS_KEY:-} +#AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:-} + +# Create initial Docker Base Command +DOCKER_BASE_COMMANDS[0]="docker run" +ARGS=() +# Check for debug statements +if [[ $S_DEBUG ]]; then + set -x +fi + +# Checks if ARGS already contains the given value +has_arg() { + local element + for element in "${@:2}"; do + [ "${element}" == "${1}" ] && return 0 + done + return 1 +} +# Adds the given argument if not specified +add_arg() { + local arg="${1}" + [ $# -ge 1 ] && local val="${2}" + if ! has_arg "${arg}" "${DOCKER_BASE_COMMANDS[@]}"; then + ARGS+=("${arg}") + [ $# -ge 1 ] && ARGS+=("${val}") + fi +} +# Adds the given argument duplicates ok. +add_arg_simple() { + local arg="${1}" + [ $# -ge 1 ] && local val="${2}" + ARGS+=("${arg}") + [ $# -ge 1 ] && ARGS+=("${val}") +} +# get the docker host ip address. and add it to container /etc/host +# for TEST_HOST_LOCAL URL provided. +get_docker_host(){ + if [[ $TEST_HOST_LOCAL ]]; then + GET_DOCKER_HOST_IP=$(docker inspect --format '{{ .NetworkSettings.Gateway }}' $(docker ps -q | grep -m 1 "") 2>/dev/null) + if [[ ${GET_DOCKER_HOST_IP} ]];then + CONSUL_TEST_IP=${GET_DOCKER_HOST_IP} + add_arg_simple "--add-host" "${TEST_HOST_LOCAL}:${CONSUL_TEST_IP}" + fi + fi +} +# add a volume host:docker mount. +add_host_volume(){ + local host_vol="${1%:*}" + local dkr_vol="${1##*:}" + add_arg "-v" "${host_vol}:${dkr_vol}" +} + +# add envfiles for docker if they exist in working directory +add_docker_envfiles(){ + local envfiles="${1}" + IFS=':' read -r -a arrenvs <<< "$envfiles" + for i in "${arrenvs[@]}" + do + if [[ -r "${i}" ]];then + add_arg "--env-file" "$(pwd)/${i}" + fi + done +} +usage () { + echo "" + echo "Usage : $0 [OPTIONS] [COMMANDS|task]" + echo "Options:" + echo " -l List available rake tasks " + echo " -e FILE:FILE Envfiles for docker : separated " + echo " -s FILE Local env file to source " + echo " -d DNS Docker DNS " + echo " -u USER Run Docker as user " + echo " -O Use Wrapper without Covalence " + echo " -T URL URL for Consul overload " + echo " -R Leave intermediary containers " + echo " -v VOL:MNT Add a volume mount to container " + echo " -c AWS_DIR AWS credentials path " + echo " -w DIR Host workspace to mount " + echo " -E ENTRYPOINT Override entrypoint command " + echo " -i DKR_IMG_NAME Docker container Image name " + echo " -h View help. " + echo " -r RAKEFILE Specify separate rakefile " + echo " -D Turn on debug " + echo " -H Environment dump " +} +# require at lest a task or -l to run +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +# Load local env file if provided/available +# That way explicit options will overwrite +# any env vars sourced in .env.covalence +if [[ -r "${LOCAL_ENVFILE}" ]]; then + . ./"${LOCAL_ENVFILE}" +fi + +# Parse arguments and populate ENV vars respectively +# See Environment Variable section or .env.covalence for +# option details. +while getopts ":le:s:d:OIT:Rv:c:w:E:i:hr:DH" opt; do + case $opt in + l) + LIST_RAKE_TASKS=1 + ;; + e) + LOAD_ENVFILE="$OPTARG" + ;; + s) + LOCAL_ENVFILE="$OPTARG" + ;; + d) + DOCKER_DNS="$OPTARG" + ;; + u) + CONTAINER_USER_ID="$OPTARG" + ;; + O) + DOCKER_WRAPPER=1 + ;; + T) + TEST_HOST_LOCAL="$OPTARG" + ;; + R) + DOCKER_RUN_TYPE="--it" + ;; + v) + ADD_VOLUMES="$OPTARG" + ;; + c) + AWS_CREDENTIAL_PATH="$OPTARG" + ;; + w) + DOCKER_WORKSPACE="$OPTARG" + ;; + E) + ENTRYPOINT="$OPTARG" + ;; + i) + DOCKER_IMAGE_NAME="$OPTARG" + ;; + h) + usage + exit 0 + ;; + D) + S_DEBUG=1 + ;; + H) + DUMP_ENV=1 + ;; + I) + INTSHELL=1 + ;; + r) + COVALENCE_RAKEFILE="$OPTARG" + ;; + \?) + set +x + echo "Invalid option: -$OPTARG" >&2 + usage + exit 1 + ;; + :) + set +x + echo "Option -$OPTARG requires an argument." >&2 + usage + exit 1 + ;; + esac +done + +# Get rid of processed options from Array +shift "$((OPTIND-1))" +USER_ARGS=("${@}") + +if [[ "${COVALENCE_CONFIG}" ]]; then + add_arg_simple "-e" "COVALENCE_CONFIG=${COVALENCE_CONFIG}" +fi + +if [[ "${COVALENCE_TEST_ENVS}" ]]; then + add_arg_simple "-e" "COVALENCE_TEST_ENVS=${COVALENCE_TEST_ENVS}" +fi + +# Add the --rm or --it argument to the docker command array. +if [[ "${DOCKER_RUN_TYPE}" ]]; then + DOCKER_BASE_COMMANDS[3]="${DOCKER_RUN_TYPE}" +fi + +if [[ "${DOCKER_DNS}" ]]; then + add_arg "--dns" "${DOCKER_DNS}" +fi + +if [[ "${CONTAINER_USER_ID}" ]]; then + DOCKER_HOMEDIR="" + add_arg_simple "-e" "AWS_CONFIG_FILE=${DOCKER_HOMEDIR}/.aws/config" + add_arg_simple "-e" "AWS_SHARED_CREDENTIALS_FILE=${DOCKER_HOMEDIR}/.aws/credentials" + add_arg_simple "-e" "USER=user" + add_arg_simple "-e" "LOCAL_USER_ID=${CONTAINER_USER_ID}" +else + add_arg_simple "-e" "USER=root" +fi + +get_docker_host "$TEST_HOST_LOCAL" + +if [[ "$ADD_VOLUMES" ]];then + add_host_volume "${ADD_VOLUMES}" +fi + +if [[ -d "$AWS_CREDENTIAL_PATH" ]];then + add_arg_simple "-v" "${AWS_CREDENTIAL_PATH}:${DOCKER_HOMEDIR}/.aws" +fi + +if [[ -d "${SRC_ROOT}" ]];then + add_arg_simple "-v" "${SRC_ROOT}:${DOCKER_WORKSPACE}" + add_arg "-w" "${DOCKER_WORKSPACE}" +fi + +if [[ "${LOAD_ENVFILE}" ]]; then + add_docker_envfiles "${LOAD_ENVFILE}" +fi + +if [[ "${ENTRYPOINT}" ]]; then + ARGS+=("--entrypoint=${ENTRYPOINT}") +fi +if [[ $INTSHELL && ! $ENTRYPOINT ]]; then + ARGS+=("--entrypoint=/bin/sh") +fi +# All options should be completed +# Only image and task remain. + +if [[ $DOCKER_IMAGE_NAME ]];then + if [[ $INTSHELL && $DOCKER_WRAPPER ]]; then + ARGS+=("-it") + fi + ARGS+=("$DOCKER_IMAGE_NAME") +fi + +#Check whether docker wrapper or covalence +if [[ ! $DOCKER_WRAPPER ]]; then + ARGS+=("bundle exec rake") +fi + +if [[ -r "${COVALENCE_RAKEFILE}" && ! $DOCKER_WRAPPER ]];then + add_arg "-f" "${COVALENCE_RAKEFILE}" +fi + +if [[ $LIST_RAKE_TASKS && ! $DOCKER_WRAPPER ]];then + ARGS+=("-T") +fi +# Merged Commands for execution +DOCKER_BASE_COMMANDS=(${DOCKER_BASE_COMMANDS[@]} ${ARGS[@]} ${USER_ARGS[@]}) + +if [[ $DUMP_ENV ]]; then + echo "DOCKER_BASE_COMMANDS that would have been executed without -H" + echo "${DOCKER_BASE_COMMANDS[@]}" + # echo "ARGS array" + # echo "${ARGS[@]}" + # echo "USER_ARGS array" + # echo "${USER_ARGS[@]}" + # echo "" +else + # Execute the commands + # If we are listing, remove the rake as user won't pass that in. + if [[ $LIST_RAKE_TASKS && ! $DOCKER_WRAPPER ]];then + "${DOCKER_BASE_COMMANDS[@]}" | sed -e "s/^rake //" + else + "${DOCKER_BASE_COMMANDS[@]}" + fi +fi diff --git a/bin/covalence b/bin/covalence index 8eca25b..71687a7 100755 --- a/bin/covalence +++ b/bin/covalence @@ -1,321 +1,13 @@ #!/usr/bin/env bash -# Run from the source tree root -cd `dirname $0` -cd .. -### Environment Variables -# Variables are used for determining CI settings -# Variable precedence is as follows with the last taking -# the highest precedence -# -# 1. Default values -# 2. Exported environment variables -# 3. .env.covalence loaded values -# 4. bin/covalence argument switches -# -# source local .env.covalence file if present -LOCAL_ENVFILE=${LOCAL_ENVFILE:-".env.covalence"} - -# If set to true will no use old docker-wrapper behavior -# omitting the `rake` command -DOCKER_WRAPPER=${DOCKER_WRAPPER:-} -# The docker environment variable file passed to the container -# Can contain multiple envfiles separated by : env1:env2:env3 -LOAD_ENVFILE=${LOAD_ENVFILE:-".env.docker:.env.secrets"} -# AWS Credentials path to mount (defaults to data/secure/.aws) -AWS_CREDENTIAL_PATH=${AWS_CREDENTIAL_PATH:-"${HOME}/.aws"} -# The Container home directory -DOCKER_HOMEDIR=${DOCKER_HOMEDIR:-"/root"} -# The docker DNS defaults to Google -DOCKER_DNS=${DOCKER_DNS:-8.8.8.8} -# If you want docker to run as specific user -CONTAINER_USER=${CONTAINER_USER:-} -# Alternative Covalence Rakefile can be specified -# will add `-f Rakefile`` -COVALENCE_RAKEFILE=${COVALENCE_RAKEFILE:-} -# Alternative Covalence configuration can be specified -COVALENCE_CONFIG=${COVALENCE_CONFIG:-"covalence.yaml"} -# Environments to be included in CI -COVALENCE_TEST_ENVS=${COVALENCE_TEST_ENVS:-} -# The Container image to use for the ci defaults to unifio/ci latest -DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-"unifio/ci"} -# Enable debugging of script -S_DEBUG=${S_DEBUG:-} -# Dump verbose information about commands without executing them. -DUMP_ENV=${DUMP_ENV:-} -# Causes covalence rake -T -LIST_RAKE_TASKS=${LIST_RAKE_TASKS:-} -# Adds volume to docker container HOST_MNT:CONTAINER_MNT -ADD_VOLUMES=${ADD_VOLUMES:-} -# Can be used to change docker run behavior ie -it vs --rm -DOCKER_RUN_TYPE=${DOCKER_RUN_TYPE:-"--rm"} -# TEST_HOST_LOCAL is used for specifying a domain to overload -# and point to the Docker host IP in the container /etc/host file -# --add-host CONSUL_TEST_IP will be set automatically -TEST_HOST_LOCAL=${TEST_HOST_LOCAL:-} -CONSUL_TEST_IP=${CONSUL_TEST_IP:-} -# Allows specifying --entrypoint= command -ENTRYPOINT=${ENTRYPOINT:-} -# Sets the Docker workspace to mount and set as working directory -w -DOCKER_WORKSPACE=${DOCKER_WORKSPACE:-"/workspace"} -# The project root directory to mount in docker workspace -SRC_ROOT=${SRC_ROOT:-"$(pwd)"} -# Atlas and AWS tokens if needed but defaults to .aws -# For possible future use currently should be set in .env.docker -#ATLAS_TOKEN=${AWS_SECRET_ACCESS_KEY:-} -#AWS_ACCESS_KEY_ID=${AWS_SECRET_ACCESS_KEY:-} -#AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:-} - -# Create initial Docker Base Command -DOCKER_BASE_COMMANDS[0]="docker run" -ARGS=() -# Check for debug statements -if [[ $S_DEBUG ]]; then - set -x -fi - -# Checks if ARGS already contains the given value -has_arg() { - local element - for element in "${@:2}"; do - [ "${element}" == "${1}" ] && return 0 - done - return 1 -} -# Adds the given argument if not specified -add_arg() { - local arg="${1}" - [ $# -ge 1 ] && local val="${2}" - if ! has_arg "${arg}" "${DOCKER_BASE_COMMANDS[@]}"; then - ARGS+=("${arg}") - [ $# -ge 1 ] && ARGS+=("${val}") - fi -} -# Adds the given argument duplicates ok. -add_arg_simple() { - local arg="${1}" - [ $# -ge 1 ] && local val="${2}" - ARGS+=("${arg}") - [ $# -ge 1 ] && ARGS+=("${val}") -} -# get the docker host ip address. and add it to container /etc/host -# for TEST_HOST_LOCAL URL provided. -get_docker_host(){ - if [[ $TEST_HOST_LOCAL ]]; then - GET_DOCKER_HOST_IP=$(docker inspect --format '{{ .NetworkSettings.Gateway }}' $(docker ps -q | grep -m 1 "") 2>/dev/null) - if [[ ${GET_DOCKER_HOST_IP} ]];then - CONSUL_TEST_IP=${GET_DOCKER_HOST_IP} - add_arg_simple "--add-host" "${TEST_HOST_LOCAL}:${CONSUL_TEST_IP}" - fi - fi -} -# add a volume host:docker mount. -add_host_volume(){ - local host_vol="${1%:*}" - local dkr_vol="${1##*:}" - add_arg "-v" "${host_vol}:${dkr_vol}" -} - -# add envfiles for docker if they exist in working directory -add_docker_envfiles(){ - local envfiles="${1}" - IFS=':' read -r -a arrenvs <<< "$envfiles" - for i in "${arrenvs[@]}" - do - if [[ -r "${i}" ]];then - add_arg "--env-file" "$(pwd)/${i}" - fi - done -} -usage () { - echo "" - echo "Usage : $0 [OPTIONS] [COMMANDS|task]" - echo "Options:" - echo " -l List available rake tasks " - echo " -e FILE:FILE Envfiles for docker : separated " - echo " -s FILE Local env file to source " - echo " -d DNS Docker DNS " - echo " -u USER Run Docker as user " - echo " -O Use Wrapper without Covalence " - echo " -T URL URL for Consul overload " - echo " -R Leave intermediary containers " - echo " -v VOL:MNT Add a volume mount to container " - echo " -c AWS_DIR AWS credentials path " - echo " -w DIR Host workspace to mount " - echo " -E ENTRYPOINT Override entrypoint command " - echo " -i DKR_IMG_NAME Docker container Image name " - echo " -h View help. " - echo " -r RAKEFILE Specify separate rakefile " - echo " -D Turn on debug " - echo " -H Environment dump " -} -# require at lest a task or -l to run -if [ $# -lt 1 ]; then - usage - exit 1 -fi - -# Load local env file if provided/available -# That way explicit options will overwrite -# any env vars sourced in .env.covalence -if [[ -r "${LOCAL_ENVFILE}" ]]; then - . ./"${LOCAL_ENVFILE}" -fi - -# Parse arguments and populate ENV vars respectively -# See Environment Variable section or .env.covalence for -# option details. -while getopts ":le:s:d:OT:Rv:c:w:E:i:hr:DH" opt; do - case $opt in - l) - LIST_RAKE_TASKS=1 - ;; - e) - LOAD_ENVFILE="$OPTARG" - ;; - s) - LOCAL_ENVFILE="$OPTARG" - ;; - d) - DOCKER_DNS="$OPTARG" - ;; - u) - CONTAINER_USER="$OPTARG" - ;; - O) - DOCKER_WRAPPER=1 - ;; - T) - TEST_HOST_LOCAL="$OPTARG" - ;; - R) - DOCKER_RUN_TYPE="--it" - ;; - v) - ADD_VOLUMES="$OPTARG" - ;; - c) - AWS_CREDENTIAL_PATH="$OPTARG" - ;; - w) - DOCKER_WORKSPACE="$OPTARG" - ;; - E) - ENTRYPOINT="$OPTARG" - ;; - i) - DOCKER_IMAGE_NAME="$OPTARG" - ;; - h) - usage - exit 0 - ;; - D) - S_DEBUG=1 - ;; - H) - DUMP_ENV=1 - ;; - r) - COVALENCE_RAKEFILE="$OPTARG" - ;; - \?) - set +x - echo "Invalid option: -$OPTARG" >&2 - usage - exit 1 - ;; - :) - set +x - echo "Option -$OPTARG requires an argument." >&2 - usage - exit 1 - ;; - esac -done - -# Get rid of processed options from Array -shift "$((OPTIND-1))" -USER_ARGS=("${@}") - -if [[ "${COVALENCE_CONFIG}" ]]; then - add_arg_simple "-e" "COVALENCE_CONFIG=${COVALENCE_CONFIG}" -fi - -if [[ "${COVALENCE_TEST_ENVS}" ]]; then - add_arg_simple "-e" "COVALENCE_TEST_ENVS=${COVALENCE_TEST_ENVS}" -fi - -# Add the --rm or --it argument to the docker command array. -if [[ "${DOCKER_RUN_TYPE}" ]]; then - DOCKER_BASE_COMMANDS[3]="${DOCKER_RUN_TYPE}" -fi - -if [[ "${DOCKER_DNS}" ]]; then - add_arg "--dns" "${DOCKER_DNS}" -fi -if [[ "${CONTAINER_USER}" ]]; then - add_arg "--user" "${CONTAINER_USER}" -fi - -get_docker_host "$TEST_HOST_LOCAL" - -if [[ "$ADD_VOLUMES" ]];then - add_host_volume "${ADD_VOLUMES}" -fi - -if [[ -d "$AWS_CREDENTIAL_PATH" ]];then - add_arg_simple "-v" "${AWS_CREDENTIAL_PATH}:${DOCKER_HOMEDIR}/.aws" -fi - -if [[ -d "${SRC_ROOT}" ]];then - add_arg_simple "-v" "${SRC_ROOT}:${DOCKER_WORKSPACE}" - add_arg "-w" "${DOCKER_WORKSPACE}" -fi - -if [[ "${LOAD_ENVFILE}" ]]; then - add_docker_envfiles "${LOAD_ENVFILE}" -fi +COVALENCE_SCRIPT="https://s3.amazonaws.com/unifio-covalence/covalence?versionId=k_MRX2uIWItAsCR1YFrJWZOaDIB9FFAR" -if [[ "${ENTRYPOINT}" ]]; then - ARGS+=("--entrypoint=${ENTRYPOINT}") -fi -# All options should be completed -# Only image and task remain. - -if [[ $DOCKER_IMAGE_NAME ]];then - ARGS+=("$DOCKER_IMAGE_NAME") -fi - -#Check whether docker wrapper or covalence -if [[ ! $DOCKER_WRAPPER ]]; then - ARGS+=("rake") -fi - -if [[ -r "${COVALENCE_RAKEFILE}" && ! $DOCKER_WRAPPER ]];then - add_arg "-f" "${COVALENCE_RAKEFILE}" -fi +cd `dirname $0` -if [[ $LIST_RAKE_TASKS && ! $DOCKER_WRAPPER ]];then - ARGS+=("-T") +if [[ ! -e ./.covalence/launcher ]]; then + mkdir -p .covalence + curl -o .covalence/launcher -s $COVALENCE_SCRIPT + chmod 0755 .covalence/launcher fi -# Merged Commands for execution -DOCKER_BASE_COMMANDS=(${DOCKER_BASE_COMMANDS[@]} ${ARGS[@]} ${USER_ARGS[@]}) -if [[ $DUMP_ENV ]]; then - echo "DOCKER_BASE_COMMANDS that would have been executed without -H" - echo "${DOCKER_BASE_COMMANDS[@]}" - # echo "ARGS array" - # echo "${ARGS[@]}" - # echo "USER_ARGS array" - # echo "${USER_ARGS[@]}" - # echo "" -else - # Execute the commands - # If we are listing, remove the rake as user won't pass that in. - if [[ $LIST_RAKE_TASKS && ! $DOCKER_WRAPPER ]];then - "${DOCKER_BASE_COMMANDS[@]}" | sed -e "s/^rake //" - else - "${DOCKER_BASE_COMMANDS[@]}" - fi -fi +bash .covalence/launcher "$@" diff --git a/data/globals.yaml b/data/globals.yaml index 5ab8578..30f7806 100644 --- a/data/globals.yaml +++ b/data/globals.yaml @@ -2,10 +2,12 @@ # Global variables ## Terraform -tf_state_bucket: 'unifio-terraform-state' -tf_state_region: 'us-east-2' +tf_state_bucket: 'unifio-terrraform-state-us-east-1' +tf_state_region: "us-east-1" ## VPC -vpc_id: 'vpc-0f986c66' +# aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --profile unifiouat | jq '.Vpcs[] | .VpcId' +vpc_id: 'vpc-778aca0d' vpc_region: 'us-east-2' -vpc_subnets: 'subnet-3315e85a,subnet-3bbaaf43,subnet-ec1326a6' +# aws ec2 describe-subnets --filters "Name=vpc-id,Values=vpc-778aca0d" --profile unifiouat | jq '.Subnets[] | .SubnetId' +vpc_subnets: 'subnet-9a78bcd7,subnet-547d4d08,subnet-b7e4d0d0' diff --git a/data/stacks/asg-elb-wait.yaml b/data/stacks/asg-elb-wait.yaml index 6ee324a..6368bad 100644 --- a/data/stacks/asg-elb-wait.yaml +++ b/data/stacks/asg-elb-wait.yaml @@ -7,9 +7,9 @@ asg-elb-wait::module: 'examples/complete' ## State storage asg-elb-wait::state: - s3: - bucket: "%{hiera('tf_state_bucket')}" + bucket: "%{alias('tf_state_bucket')}" name: "terraform-aws-asg/%{environment}" - region: "%{hiera('tf_state_region')}" + region: "%{alias('tf_state_region')}" ## Input variables examples::complete::vars: diff --git a/data/stacks/asg-elb.yaml b/data/stacks/asg-elb.yaml index 7800cea..c19cfb3 100644 --- a/data/stacks/asg-elb.yaml +++ b/data/stacks/asg-elb.yaml @@ -7,9 +7,9 @@ asg-elb::module: 'examples/complete' ## State storage asg-elb::state: - s3: - bucket: "%{hiera('tf_state_bucket')}" + bucket: "%{alias('tf_state_bucket')}" name: "terraform-aws-asg/%{environment}" - region: "%{hiera('tf_state_region')}" + region: "%{alias('tf_state_region')}" ## Input variables examples::complete::vars: diff --git a/data/stacks/asg-options.yaml b/data/stacks/asg-options.yaml index aa73b77..0c558bf 100644 --- a/data/stacks/asg-options.yaml +++ b/data/stacks/asg-options.yaml @@ -7,9 +7,9 @@ asg-options::module: 'examples/basic' ## State storage asg-options::state: - s3: - bucket: "%{hiera('tf_state_bucket')}" + bucket: "%{alias('tf_state_bucket')}" name: "terraform-aws-asg/%{environment}" - region: "%{hiera('tf_state_region')}" + region: "%{alias('tf_state_region')}" ## Input variables examples::basic::vars: @@ -17,7 +17,7 @@ examples::basic::vars: associate_public_ip_address: 'true' enable_monitoring: 'true' key_name: 'unifio_ops_pub' - security_groups: 'sg-d4f906bd' + security_groups: 'sg-7e33f32f' # ASG parameters default_cooldown: '400' diff --git a/data/stacks/common.yaml b/data/stacks/common.yaml index 94aedc9..2d79fea 100644 --- a/data/stacks/common.yaml +++ b/data/stacks/common.yaml @@ -7,11 +7,11 @@ examples::basic::vars: ami: 'ami-c55673a0' instance_type: 't2.nano' min_size: '1' - region: "%{hiera('vpc_region')}" + region: "%{alias('vpc_region')}" stack_item_fullname: 'Basic Examples' stack_item_label: 'bsc' - subnets: "%{hiera('vpc_subnets')}" - vpc_id: "%{hiera('vpc_id')}" + subnets: "%{alias('vpc_subnets')}" + vpc_id: "%{alias('vpc_id')}" ## Advanced example examples::complete::vars: @@ -21,8 +21,8 @@ examples::complete::vars: instance_type: 't2.nano' key_name: 'unifio_ops_pub' min_size: '1' - region: "%{hiera('vpc_region')}" + region: "%{alias('vpc_region')}" stack_item_fullname: 'Complete Examples' stack_item_label: 'cmpl' - subnets: "%{hiera('vpc_subnets')}" - vpc_id: "%{hiera('vpc_id')}" + subnets: "%{alias('vpc_subnets')}" + vpc_id: "%{alias('vpc_id')}" diff --git a/data/stacks/defaults.yaml b/data/stacks/defaults.yaml index 8742e8b..f3ec5af 100644 --- a/data/stacks/defaults.yaml +++ b/data/stacks/defaults.yaml @@ -7,9 +7,9 @@ defaults::module: 'examples/basic' ## State storage defaults::state: - s3: - bucket: "%{hiera('tf_state_bucket')}" + bucket: "%{alias('tf_state_bucket')}" name: "terraform-aws-asg/%{environment}" - region: "%{hiera('tf_state_region')}" + region: "%{alias('tf_state_region')}" ## Input variables examples::basic::vars: diff --git a/data/stacks/lc-ebs-new.yaml b/data/stacks/lc-ebs-new.yaml index c15c2cb..f4a0a4d 100644 --- a/data/stacks/lc-ebs-new.yaml +++ b/data/stacks/lc-ebs-new.yaml @@ -7,9 +7,9 @@ lc-ebs-new::module: 'examples/complete' ## State storage lc-ebs-new::state: - s3: - bucket: "%{hiera('tf_state_bucket')}" + bucket: "%{alias('tf_state_bucket')}" name: "terraform-aws-asg/%{environment}" - region: "%{hiera('tf_state_region')}" + region: "%{alias('tf_state_region')}" ## Input variables examples::complete::vars: diff --git a/data/stacks/lc-ebs-snap.yaml b/data/stacks/lc-ebs-snap.yaml index 3db68c9..4bad3df 100644 --- a/data/stacks/lc-ebs-snap.yaml +++ b/data/stacks/lc-ebs-snap.yaml @@ -7,9 +7,9 @@ lc-ebs-snap::module: 'examples/complete' ## State storage lc-ebs-snap::state: - s3: - bucket: "%{hiera('tf_state_bucket')}" + bucket: "%{alias('tf_state_bucket')}" name: "terraform-aws-asg/%{environment}" - region: "%{hiera('tf_state_region')}" + region: "%{alias('tf_state_region')}" ## Input variables examples::complete::vars: diff --git a/data/stacks/lc-options.yaml b/data/stacks/lc-options.yaml index e41cfb3..ca95f7b 100644 --- a/data/stacks/lc-options.yaml +++ b/data/stacks/lc-options.yaml @@ -7,9 +7,9 @@ lc-options::module: 'examples/basic' ## State storage lc-options::state: - s3: - bucket: "%{hiera('tf_state_bucket')}" + bucket: "%{alias('tf_state_bucket')}" name: "terraform-aws-asg/%{environment}" - region: "%{hiera('tf_state_region')}" + region: "%{alias('tf_state_region')}" ## Input variables examples::basic::vars: @@ -17,7 +17,7 @@ examples::basic::vars: associate_public_ip_address: 'true' enable_monitoring: 'true' key_name: 'unifio_ops_pub' - security_groups: 'sg-d4f906bd' + security_groups: 'sg-7e33f32f' # ASG parameters max_size: '1' From c324d7cd928334ddd4f34cc36b3998588f347f1b Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 8 Oct 2019 17:49:41 -0700 Subject: [PATCH 09/10] Fix CI failures due to Types Bool/Lists * Convert to bool values to support latest provider using local vars. * Remove superfluous terraform version statements in modules. * Add complete stack to covalence test environments for local testing. * Provide nulls instead of empty strings on bool required values. * Upate region specific AMI values for linux AMI in us-east-1 since this was changed. * Create new SSH key and add to unifiouat account. Add AWS cli command to comments for reference. --- .circleci/config.yml | 2 +- .env.docker | 2 +- README.md | 6 +++--- data/globals.yaml | 2 +- data/stacks/asg-elb-wait.yaml | 2 +- data/stacks/asg-elb.yaml | 2 +- data/stacks/asg-options.yaml | 1 + data/stacks/common.yaml | 4 ++-- data/stacks/lc-ebs-snap.yaml | 2 +- examples/basic/main.tf | 10 +++++----- examples/complete/main.tf | 2 +- group/asg/main.tf | 10 ++++++---- group/lc/main.tf | 15 ++++++++++----- group/main.tf | 5 ----- policy/main.tf | 5 ----- 15 files changed, 34 insertions(+), 36 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1875cda..a113142 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ common: &common - image: unifio/ci:5.0.718-ruby-2.5.5 environment: - AWS_REGION: 'us-east-2' + AWS_REGION: 'us-east-1' version: 2 diff --git a/.env.docker b/.env.docker index f747f4b..0cec522 100644 --- a/.env.docker +++ b/.env.docker @@ -1,6 +1,6 @@ AWS_REGION=us-east-1 CI_REPORTS=reports -COVALENCE_TEST_ENVS=basic +COVALENCE_TEST_ENVS=basic,complete CHECKPOINT_DISABLE=1 AWS_PROFILE=unifiouat AWS_DEFAULT_PROFILE=unifiouat diff --git a/README.md b/README.md index 5f59f29..278195a 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ module "asg" { vpc_id = "vpc-0f986c66" # LC parameters - ami = "ami-c55673a0" + ami = "ami-0b33d91d" enable_monitoring = true instance_based_naming_enabled = true instance_type = "m4.large" @@ -210,11 +210,11 @@ module "asg" { vpc_id = "vpc-0f986c66" # LC parameters - ami = "ami-c55673a0" + ami = "ami-0b33d91d" ebs_vol_device_name = "/dev/xvdb" ebs_vol_encrypted = true ebs_vol_size = 2 - ebs_vol_snapshot_id = "snap-08b95a31adefd036f" + ebs_vol_snapshot_id = "snap-62d9d283" enable_monitoring = true instance_based_naming_enabled = true instance_name_prefix = "supercool" diff --git a/data/globals.yaml b/data/globals.yaml index 30f7806..6881f32 100644 --- a/data/globals.yaml +++ b/data/globals.yaml @@ -8,6 +8,6 @@ tf_state_region: "us-east-1" ## VPC # aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --profile unifiouat | jq '.Vpcs[] | .VpcId' vpc_id: 'vpc-778aca0d' -vpc_region: 'us-east-2' +vpc_region: 'us-east-1' # aws ec2 describe-subnets --filters "Name=vpc-id,Values=vpc-778aca0d" --profile unifiouat | jq '.Subnets[] | .SubnetId' vpc_subnets: 'subnet-9a78bcd7,subnet-547d4d08,subnet-b7e4d0d0' diff --git a/data/stacks/asg-elb-wait.yaml b/data/stacks/asg-elb-wait.yaml index 6368bad..84f1d07 100644 --- a/data/stacks/asg-elb-wait.yaml +++ b/data/stacks/asg-elb-wait.yaml @@ -20,7 +20,7 @@ examples::complete::vars: # LC parameters ebs_vol_device_name: '/dev/xvdb' ## amzn-ami-minimal-hvm-2016.03.3.x86_64 - ebs_vol_snapshot_id: 'snap-08b95a31adefd036f' + ebs_vol_snapshot_id: 'snap-62d9d283' instance_based_naming_enabled: 'true' instance_name_prefix: 'example' diff --git a/data/stacks/asg-elb.yaml b/data/stacks/asg-elb.yaml index c19cfb3..43f922e 100644 --- a/data/stacks/asg-elb.yaml +++ b/data/stacks/asg-elb.yaml @@ -20,7 +20,7 @@ examples::complete::vars: # LC parameters ebs_vol_device_name: '/dev/xvdb' ## amzn-ami-minimal-hvm-2016.03.3.x86_64 - ebs_vol_snapshot_id: 'snap-08b95a31adefd036f' + ebs_vol_snapshot_id: 'snap-62d9d283' instance_based_naming_enabled: 'true' instance_name_prefix: 'example' diff --git a/data/stacks/asg-options.yaml b/data/stacks/asg-options.yaml index 0c558bf..704c2d3 100644 --- a/data/stacks/asg-options.yaml +++ b/data/stacks/asg-options.yaml @@ -16,6 +16,7 @@ examples::basic::vars: # LC parameters associate_public_ip_address: 'true' enable_monitoring: 'true' + # aws ec2 create-key-pair --key-name unifio_ops_pub --profile unifiouat key_name: 'unifio_ops_pub' security_groups: 'sg-7e33f32f' diff --git a/data/stacks/common.yaml b/data/stacks/common.yaml index 2d79fea..b420338 100644 --- a/data/stacks/common.yaml +++ b/data/stacks/common.yaml @@ -4,7 +4,7 @@ ## Basic example examples::basic::vars: # Amazon Linux AMI 2016.09.1.20170119 x86_64 HVM GP2 - ami: 'ami-c55673a0' + ami: 'ami-0b33d91d' instance_type: 't2.nano' min_size: '1' region: "%{alias('vpc_region')}" @@ -16,7 +16,7 @@ examples::basic::vars: ## Advanced example examples::complete::vars: # Amazon Linux AMI 2016.09.1.20170119 x86_64 HVM GP2 - ami: 'ami-c55673a0' + ami: 'ami-0b33d91d' enable_monitoring: 'true' instance_type: 't2.nano' key_name: 'unifio_ops_pub' diff --git a/data/stacks/lc-ebs-snap.yaml b/data/stacks/lc-ebs-snap.yaml index 4bad3df..d55682e 100644 --- a/data/stacks/lc-ebs-snap.yaml +++ b/data/stacks/lc-ebs-snap.yaml @@ -16,7 +16,7 @@ examples::complete::vars: # LC parameters ebs_vol_device_name: '/dev/xvdb' ## amzn-ami-minimal-hvm-2016.03.3.x86_64 - ebs_vol_snapshot_id: 'snap-08b95a31adefd036f' + ebs_vol_snapshot_id: 'snap-62d9d283' # ASG parameters max_size: '1' diff --git a/examples/basic/main.tf b/examples/basic/main.tf index cf9b258..9f613ec 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -43,7 +43,7 @@ module "example" { stack_item_label = var.stack_item_label # VPC parameters - subnets = [split(",", var.subnets)] + subnets = split(",", var.subnets) vpc_id = var.vpc_id # LC parameters @@ -52,20 +52,20 @@ module "example" { enable_monitoring = var.enable_monitoring instance_type = var.instance_type key_name = var.key_name - security_groups = [split(",", var.security_groups)] + security_groups = split(",", var.security_groups) spot_price = var.spot_price # ASG parameters default_cooldown = var.default_cooldown desired_capacity = var.desired_capacity - enabled_metrics = [split(",", var.enabled_metrics)] + enabled_metrics = split(",", var.enabled_metrics) force_delete = var.force_delete hc_grace_period = var.hc_grace_period max_size = var.max_size min_size = var.min_size protect_from_scale_in = var.protect_from_scale_in - suspended_processes = [split(",", var.suspended_processes)] - termination_policies = [split(",", var.termination_policies)] + suspended_processes = split(",", var.suspended_processes) + termination_policies = split(",", var.termination_policies) wait_for_capacity_timeout = var.wait_for_capacity_timeout } diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 69dbead..cbdd837 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -165,7 +165,7 @@ module "example" { stack_item_label = var.stack_item_label # VPC parameters - subnets = [split(",", var.subnets)] + subnets = split(",", var.subnets) vpc_id = var.vpc_id # LC parameters diff --git a/group/asg/main.tf b/group/asg/main.tf index 3c2ec2e..2a8f4c4 100644 --- a/group/asg/main.tf +++ b/group/asg/main.tf @@ -19,6 +19,8 @@ locals { propagate_at_launch = true }, ] + force_delete = var.force_delete == "" ? null : tobool(var.force_delete) + protect_from_scale_in = var.protect_from_scale_in == "" ? null : tobool(var.protect_from_scale_in) } resource "aws_autoscaling_group" "asg" { @@ -27,7 +29,7 @@ resource "aws_autoscaling_group" "asg" { default_cooldown = length(var.default_cooldown) > 0 ? var.default_cooldown : "300" desired_capacity = length(var.desired_capacity) > 0 ? var.desired_capacity : var.min_size enabled_metrics = compact(var.enabled_metrics) - force_delete = var.force_delete + force_delete = local.force_delete health_check_grace_period = length(var.hc_grace_period) > 0 ? var.hc_grace_period : "300" health_check_type = "EC2" launch_configuration = var.lc_id @@ -36,7 +38,7 @@ resource "aws_autoscaling_group" "asg" { min_size = var.min_size name = length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label placement_group = var.placement_group - protect_from_scale_in = var.protect_from_scale_in + protect_from_scale_in = local.protect_from_scale_in suspended_processes = compact(var.suspended_processes) target_group_arns = compact(var.target_group_arns) termination_policies = compact(var.termination_policies) @@ -52,7 +54,7 @@ resource "aws_autoscaling_group" "asg_elb" { default_cooldown = length(var.default_cooldown) > 0 ? var.default_cooldown : "300" desired_capacity = length(var.desired_capacity) > 0 ? var.desired_capacity : var.min_size enabled_metrics = compact(var.enabled_metrics) - force_delete = var.force_delete + force_delete = local.force_delete health_check_grace_period = length(var.hc_grace_period) > 0 ? var.hc_grace_period : "300" health_check_type = length(var.hc_check_type) > 0 ? var.hc_check_type : "ELB" launch_configuration = var.lc_id @@ -63,7 +65,7 @@ resource "aws_autoscaling_group" "asg_elb" { min_size = var.min_size name = length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label placement_group = var.placement_group - protect_from_scale_in = var.protect_from_scale_in + protect_from_scale_in = local.protect_from_scale_in suspended_processes = compact(var.suspended_processes) target_group_arns = compact(var.target_group_arns) termination_policies = compact(var.termination_policies) diff --git a/group/lc/main.tf b/group/lc/main.tf index 1145264..868fc9b 100644 --- a/group/lc/main.tf +++ b/group/lc/main.tf @@ -1,4 +1,9 @@ # AWS Launch Configuration +locals { + associate_public_ip_address = var.associate_public_ip_address == "" ? null : tobool(var.associate_public_ip_address) + enable_monitoring = var.enable_monitoring == "" ? null : tobool(var.enable_monitoring) + ebs_vol_encrypted = var.ebs_vol_encrypted == "" ? null : tobool(var.ebs_vol_encrypted) +} ## Creates security group resource "aws_security_group" "sg_asg" { @@ -21,9 +26,9 @@ resource "aws_security_group" "sg_asg" { resource "aws_launch_configuration" "lc" { count = length(var.ebs_vol_device_name) > 0 ? 0 : 1 - associate_public_ip_address = var.associate_public_ip_address + associate_public_ip_address = local.associate_public_ip_address ebs_optimized = var.ebs_optimized - enable_monitoring = var.enable_monitoring + enable_monitoring = local.enable_monitoring iam_instance_profile = var.instance_profile image_id = var.ami instance_type = var.instance_type @@ -51,9 +56,9 @@ resource "aws_launch_configuration" "lc" { resource "aws_launch_configuration" "lc_ebs" { count = length(var.ebs_vol_device_name) > 0 ? 1 : 0 - associate_public_ip_address = var.associate_public_ip_address + associate_public_ip_address = local.associate_public_ip_address ebs_optimized = var.ebs_optimized - enable_monitoring = var.enable_monitoring + enable_monitoring = local.enable_monitoring iam_instance_profile = var.instance_profile image_id = var.ami instance_type = var.instance_type @@ -76,7 +81,7 @@ resource "aws_launch_configuration" "lc_ebs" { ebs_block_device { delete_on_termination = var.ebs_vol_del_on_term device_name = var.ebs_vol_device_name - encrypted = length(var.ebs_vol_snapshot_id) > 0 ? "" : var.ebs_vol_encrypted + encrypted = length(var.ebs_vol_snapshot_id) > 0 ? null : local.ebs_vol_encrypted iops = var.ebs_vol_type == "io1" ? var.ebs_vol_iops : "0" snapshot_id = var.ebs_vol_snapshot_id volume_size = length(var.ebs_vol_snapshot_id) > 0 ? "0" : var.ebs_vol_size diff --git a/group/main.tf b/group/main.tf index 144fe90..3d00e10 100644 --- a/group/main.tf +++ b/group/main.tf @@ -1,10 +1,5 @@ # AWS Auto Scaling Configuration -## Set Terraform version constraint -terraform { - required_version = "> 0.8.0" -} - ## Creates cloudconfig fragments for tagging data "aws_region" "current" { } diff --git a/policy/main.tf b/policy/main.tf index cbdf59a..c4f0e2c 100644 --- a/policy/main.tf +++ b/policy/main.tf @@ -1,10 +1,5 @@ # Simple scaling auto scaling policy -## Set Terraform version constraint -terraform { - required_version = "> 0.8.0" -} - ## Creates simple scaling policy resource "aws_autoscaling_policy" "asg_policy_simple" { adjustment_type = var.adjustment_type From 1497f152d7fadb7be9be298fd4b9204232233e38 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 8 Oct 2019 18:35:44 -0700 Subject: [PATCH 10/10] Update version and Changelog for TF 0.12 updates * Updated to version 0.4.0 in changelog to prepare for Merge. --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67c01ae..04f8148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,14 @@ to a single SNS topic. * Extend multi-part user_data mechanism to support more use cases. +## 0.4.0 (Oct 08, 2019) + +#### IMPROVEMENTS / NEW FEATURES: +* Updated for Terraform v0.12 + +#### BACKWARDS INCOMPATIBILITIES / NOTES: +* Terraform versions earlier than 0.12.0 no longer supported. + ## 0.3.0 (March 24, 2017) #### BACKWARDS INCOMPATIBILITIES / NOTES: