From 56c336a5a7663bfd2f39782a8c37812875b1e838 Mon Sep 17 00:00:00 2001 From: Rohit Verma Date: Fri, 21 Jun 2019 14:55:18 +0530 Subject: [PATCH 1/7] upgraded-tf --- examples/simple/main.tf | 4 +- main.tf | 140 ++++++++++++++++++++++------------------ output.tf | 15 +++-- variables.tf | 25 +++---- 4 files changed, 102 insertions(+), 82 deletions(-) diff --git a/examples/simple/main.tf b/examples/simple/main.tf index 0b2bffa..2c51460 100644 --- a/examples/simple/main.tf +++ b/examples/simple/main.tf @@ -27,14 +27,14 @@ variable "availability_zones" { variable "zone_id" {} module "vpc" { - source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.3.3" + source = "git::https://github.com/rverma-nikiai/terraform-aws-vpc.git?ref=master" namespace = "${var.namespace}" stage = "${var.stage}" name = "${var.name}" } module "subnets" { - source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.3.5" + source = "git::https://github.com/rverma-nikiai/terraform-aws-dynamic-subnets.git?ref=master" namespace = "${var.namespace}" stage = "${var.stage}" name = "${var.name}" diff --git a/main.tf b/main.tf index 3af87a5..f7917dc 100644 --- a/main.tf +++ b/main.tf @@ -1,28 +1,28 @@ # Define composite variables for resources module "label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.5.3" - enabled = "${var.enabled}" - namespace = "${var.namespace}" - name = "${var.name}" - stage = "${var.stage}" - delimiter = "${var.delimiter}" - attributes = "${var.attributes}" - tags = "${var.tags}" + source = "git::https://github.com/rverma-nikiai/terraform-null-label.git?ref=master" + enabled = var.enabled + namespace = var.namespace + name = var.name + stage = var.stage + delimiter = var.delimiter + attributes = var.attributes + tags = var.tags } # # Security Group Resources # resource "aws_security_group" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - vpc_id = "${var.vpc_id}" - name = "${module.label.id}" + count = var.enabled == "true" ? 1 : 0 + vpc_id = var.vpc_id + name = module.label.id ingress { - from_port = "${var.port}" # Redis - to_port = "${var.port}" + from_port = var.port # Redis + to_port = var.port protocol = "tcp" - security_groups = ["${var.security_groups}"] + security_groups = var.security_groups } egress { @@ -32,54 +32,65 @@ resource "aws_security_group" "default" { cidr_blocks = ["0.0.0.0/0"] } - tags = "${module.label.tags}" + tags = module.label.tags } locals { - elasticache_subnet_group_name = "${var.elasticache_subnet_group_name != "" ? var.elasticache_subnet_group_name : join("", aws_elasticache_subnet_group.default.*.name) }" + elasticache_subnet_group_name = var.elasticache_subnet_group_name != "" ? var.elasticache_subnet_group_name : join("", aws_elasticache_subnet_group.default.*.name) } resource "aws_elasticache_subnet_group" "default" { - count = "${var.enabled == "true" && var.elasticache_subnet_group_name == "" && length(var.subnets) > 0 ? 1 : 0}" - name = "${module.label.id}" - subnet_ids = ["${var.subnets}"] + count = var.enabled == "true" && var.elasticache_subnet_group_name == "" && length(var.subnets) > 0 ? 1 : 0 + name = module.label.id + subnet_ids = var.subnets } resource "aws_elasticache_parameter_group" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - name = "${module.label.id}" - family = "${var.family}" - parameter = "${var.parameter}" + count = var.enabled == "true" ? 1 : 0 + name = module.label.id + family = var.family + dynamic "parameter" { + for_each = var.parameter + content { + # TF-UPGRADE-TODO: The automatic upgrade tool can't predict + # which keys might be set in maps assigned here, so it has + # produced a comprehensive set here. Consider simplifying + # this after confirming which keys can be set in practice. + + name = parameter.value.name + value = parameter.value.value + } + } } resource "aws_elasticache_replication_group" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - - auth_token = "${var.auth_token}" - replication_group_id = "${var.replication_group_id == "" ? module.label.id : var.replication_group_id}" - replication_group_description = "${module.label.id}" - node_type = "${var.instance_type}" - number_cache_clusters = "${var.cluster_size}" - port = "${var.port}" - parameter_group_name = "${aws_elasticache_parameter_group.default.name}" - availability_zones = ["${slice(var.availability_zones, 0, var.cluster_size)}"] - automatic_failover_enabled = "${var.automatic_failover}" - subnet_group_name = "${local.elasticache_subnet_group_name}" - security_group_ids = ["${aws_security_group.default.id}"] - maintenance_window = "${var.maintenance_window}" - notification_topic_arn = "${var.notification_topic_arn}" - engine_version = "${var.engine_version}" - at_rest_encryption_enabled = "${var.at_rest_encryption_enabled}" - transit_encryption_enabled = "${var.transit_encryption_enabled}" - - tags = "${module.label.tags}" + count = var.enabled == "true" ? 1 : 0 + + auth_token = var.auth_token + replication_group_id = var.replication_group_id == "" ? module.label.id : var.replication_group_id + replication_group_description = module.label.id + node_type = var.instance_type + number_cache_clusters = var.cluster_size + port = var.port + parameter_group_name = aws_elasticache_parameter_group.default[0].name + availability_zones = slice(var.availability_zones, 0, var.cluster_size) + automatic_failover_enabled = var.automatic_failover + subnet_group_name = local.elasticache_subnet_group_name + security_group_ids = [aws_security_group.default[0].id] + maintenance_window = var.maintenance_window + notification_topic_arn = var.notification_topic_arn + engine_version = var.engine_version + at_rest_encryption_enabled = var.at_rest_encryption_enabled + transit_encryption_enabled = var.transit_encryption_enabled + + tags = module.label.tags } # # CloudWatch Resources # resource "aws_cloudwatch_metric_alarm" "cache_cpu" { - count = "${var.enabled == "true" ? 1 : 0}" + count = var.enabled == "true" ? 1 : 0 alarm_name = "${module.label.id}-cpu-utilization" alarm_description = "Redis cluster CPU utilization" comparison_operator = "GreaterThanThreshold" @@ -89,19 +100,19 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" { period = "300" statistic = "Average" - threshold = "${var.alarm_cpu_threshold_percent}" + threshold = var.alarm_cpu_threshold_percent - dimensions { - CacheClusterId = "${module.label.id}" + dimensions = { + CacheClusterId = module.label.id } - alarm_actions = ["${var.alarm_actions}"] - ok_actions = ["${var.ok_actions}"] - depends_on = ["aws_elasticache_replication_group.default"] + alarm_actions = var.alarm_actions + ok_actions = var.ok_actions + depends_on = [aws_elasticache_replication_group.default] } resource "aws_cloudwatch_metric_alarm" "cache_memory" { - count = "${var.enabled == "true" ? 1 : 0}" + count = var.enabled == "true" ? 1 : 0 alarm_name = "${module.label.id}-freeable-memory" alarm_description = "Redis cluster freeable memory" comparison_operator = "LessThanThreshold" @@ -111,24 +122,25 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" { period = "60" statistic = "Average" - threshold = "${var.alarm_memory_threshold_bytes}" + threshold = var.alarm_memory_threshold_bytes - dimensions { - CacheClusterId = "${module.label.id}" + dimensions = { + CacheClusterId = module.label.id } - alarm_actions = ["${var.alarm_actions}"] - ok_actions = ["${var.ok_actions}"] - depends_on = ["aws_elasticache_replication_group.default"] + alarm_actions = var.alarm_actions + ok_actions = var.ok_actions + depends_on = [aws_elasticache_replication_group.default] } module "dns" { - source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.6" - enabled = "${var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false"}" - namespace = "${var.namespace}" - name = "${var.name}" - stage = "${var.stage}" + source = "git::https://github.com/rverma-nikiai/terraform-aws-route53-cluster-hostname.git?ref=master" + enabled = var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false" + namespace = var.namespace + name = var.name + stage = var.stage ttl = 60 - zone_id = "${var.zone_id}" - records = ["${aws_elasticache_replication_group.default.*.primary_endpoint_address}"] + zone_id = var.zone_id + records = [aws_elasticache_replication_group.default.*.primary_endpoint_address] } + diff --git a/output.tf b/output.tf index f2d2cc8..7400d68 100644 --- a/output.tf +++ b/output.tf @@ -1,19 +1,26 @@ output "id" { - value = "${join("", aws_elasticache_replication_group.default.*.id)}" + value = join("", aws_elasticache_replication_group.default.*.id) description = "Redis cluster ID" } output "security_group_id" { - value = "${join("", aws_security_group.default.*.id)}" + value = join("", aws_security_group.default.*.id) description = "Security group ID" } output "port" { - value = "${var.port}" + value = var.port description = "Redis port" } output "host" { - value = "${coalesce(module.dns.hostname, join("", aws_elasticache_replication_group.default.*.primary_endpoint_address))}" + value = coalesce( + module.dns.hostname, + join( + "", + aws_elasticache_replication_group.default.*.primary_endpoint_address, + ), + ) description = "Redis host" } + diff --git a/variables.tf b/variables.tf index b4fd9d7..558760a 100644 --- a/variables.tf +++ b/variables.tf @@ -19,7 +19,7 @@ variable "name" { } variable "security_groups" { - type = "list" + type = list(string) default = [] description = "AWS security group ids" } @@ -29,13 +29,13 @@ variable "vpc_id" { } variable "subnets" { - type = "list" + type = list(string) description = "AWS subnet IDs" default = [] } variable "elasticache_subnet_group_name" { - type = "string" + type = string description = "Subnet group name for the ElastiCache instance" default = "" } @@ -66,7 +66,7 @@ variable "family" { } variable "parameter" { - type = "list" + type = list(string) default = [] description = "A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another" } @@ -103,13 +103,13 @@ variable "alarm_memory_threshold_bytes" { } variable "alarm_actions" { - type = "list" + type = list(string) description = "Alarm action list" default = [] } variable "ok_actions" { - type = "list" + type = list(string) description = "The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN)" default = [] } @@ -125,7 +125,7 @@ variable "automatic_failover" { } variable "availability_zones" { - type = "list" + type = list(string) description = "Availability zone ids" default = [] } @@ -136,31 +136,32 @@ variable "zone_id" { } variable "delimiter" { - type = "string" + type = string default = "-" description = "Delimiter between `name`, `namespace`, `stage` and `attributes`" } variable "attributes" { - type = "list" + type = list(string) description = "Additional attributes (_e.g._ \"1\")" default = [] } variable "tags" { - type = "map" + type = map(string) description = "Additional tags (_e.g._ map(\"BusinessUnit\",\"ABC\")" default = {} } variable "auth_token" { - type = "string" + type = string description = "Auth token for password protecting redis, transit_encryption_enabled must be set to 'true'! Password must be longer than 16 chars" default = "" } variable "replication_group_id" { - type = "string" + type = string description = "Replication group ID with the following constraints: \nA name must contain from 1 to 20 alphanumeric characters or hyphens. \n The first character must be a letter. \n A name cannot end with a hyphen or contain two consecutive hyphens." default = "" } + From 9abd27c824302d1edaa08da8675a4c555f476fd2 Mon Sep 17 00:00:00 2001 From: rverma-nikiai Date: Fri, 21 Jun 2019 15:55:50 +0530 Subject: [PATCH 2/7] upgraded-tf --- versions.tf | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 versions.tf diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} From 2ab3ee7f47a1758424ddbedfeb47469ba9add5bc Mon Sep 17 00:00:00 2001 From: rverma-nikiai Date: Fri, 21 Jun 2019 19:31:30 +0530 Subject: [PATCH 3/7] moving back pointer to cloudposse --- examples/simple/main.tf | 4 ++-- main.tf | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/simple/main.tf b/examples/simple/main.tf index 2c51460..5ae0ce5 100644 --- a/examples/simple/main.tf +++ b/examples/simple/main.tf @@ -27,14 +27,14 @@ variable "availability_zones" { variable "zone_id" {} module "vpc" { - source = "git::https://github.com/rverma-nikiai/terraform-aws-vpc.git?ref=master" + source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=master" namespace = "${var.namespace}" stage = "${var.stage}" name = "${var.name}" } module "subnets" { - source = "git::https://github.com/rverma-nikiai/terraform-aws-dynamic-subnets.git?ref=master" + source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=master" namespace = "${var.namespace}" stage = "${var.stage}" name = "${var.name}" diff --git a/main.tf b/main.tf index f7917dc..a660c4d 100644 --- a/main.tf +++ b/main.tf @@ -1,6 +1,6 @@ # Define composite variables for resources module "label" { - source = "git::https://github.com/rverma-nikiai/terraform-null-label.git?ref=master" + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master" enabled = var.enabled namespace = var.namespace name = var.name @@ -134,7 +134,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" { } module "dns" { - source = "git::https://github.com/rverma-nikiai/terraform-aws-route53-cluster-hostname.git?ref=master" + source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=master" enabled = var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false" namespace = var.namespace name = var.name From d0d60475bde0efcbf94c09804f881840e1f9aed8 Mon Sep 17 00:00:00 2001 From: rverma-nikiai Date: Sun, 23 Jun 2019 07:11:19 +0530 Subject: [PATCH 4/7] referencing to rverma-nikiai for the time cloudposse updates didn't finished --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index a660c4d..b3c10ce 100644 --- a/main.tf +++ b/main.tf @@ -134,7 +134,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" { } module "dns" { - source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=master" + source = "git::https://github.com/rverma-nikiai/terraform-aws-route53-cluster-hostname.git?ref=master" enabled = var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false" namespace = var.namespace name = var.name From dc1ed146d6a66651663d8dadbedb331159288e66 Mon Sep 17 00:00:00 2001 From: rverma-nikiai Date: Sun, 23 Jun 2019 07:20:51 +0530 Subject: [PATCH 5/7] pinned null label --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b3c10ce..cb21aeb 100644 --- a/main.tf +++ b/main.tf @@ -1,6 +1,6 @@ # Define composite variables for resources module "label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master" + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.13.0" enabled = var.enabled namespace = var.namespace name = var.name From e4f6d5ee9b289250174210b703aa8a4b69b5c107 Mon Sep 17 00:00:00 2001 From: rverma-nikiai Date: Wed, 26 Jun 2019 14:59:10 +0530 Subject: [PATCH 6/7] upgraded 0.12 --- main.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.tf b/main.tf index cb21aeb..80843f2 100644 --- a/main.tf +++ b/main.tf @@ -66,7 +66,6 @@ resource "aws_elasticache_parameter_group" "default" { resource "aws_elasticache_replication_group" "default" { count = var.enabled == "true" ? 1 : 0 - auth_token = var.auth_token replication_group_id = var.replication_group_id == "" ? module.label.id : var.replication_group_id replication_group_description = module.label.id node_type = var.instance_type @@ -141,6 +140,6 @@ module "dns" { stage = var.stage ttl = 60 zone_id = var.zone_id - records = [aws_elasticache_replication_group.default.*.primary_endpoint_address] + records = aws_elasticache_replication_group.default.*.primary_endpoint_address } From 60d8b2a0276cc6df1e6b2548d30f00a3cbcbf4f8 Mon Sep 17 00:00:00 2001 From: rverma-nikiai Date: Wed, 26 Jun 2019 18:10:58 +0530 Subject: [PATCH 7/7] upgraded 0.12 --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 80843f2..d0be656 100644 --- a/main.tf +++ b/main.tf @@ -1,6 +1,6 @@ # Define composite variables for resources module "label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.13.0" + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.1" enabled = var.enabled namespace = var.namespace name = var.name