Skip to content

Commit 42b4189

Browse files
committed
Nearly done with TF 0.12 implementation
1 parent 6f7adca commit 42b4189

File tree

2 files changed

+96
-47
lines changed

2 files changed

+96
-47
lines changed

main.tf

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ data "aws_region" "current" {
2525

2626
locals {
2727
enable_http_on_alb = var.alb_http_enabled && var.alb_https_enabled && var.alb_http_to_https_redirect_enabled ? false : var.alb_http_enabled
28-
redirect_resources_count = local.enable_http_on_alb ? 1 : 0
29-
redirect_code = var.alb_http_to_https_redirect_permanent ? 302 : 301
28+
redirect_resources_count = local.enable_http_on_alb == false ? 1 : 0
29+
redirect_code = var.alb_http_to_https_redirect_permanent ? "302" : "301"
3030

3131
ec2_asg_resources_count = var.ec2_asg_enabled ? 1 : 0
3232
ec2_nat_setup = var.vpc_nat_gateway_enabled || var.vpc_nat_instance_enabled
@@ -111,22 +111,16 @@ echo 'ECS_CLUSTER=${module.ecs.this_ecs_cluster_name}' >> /etc/ecs/ecs.config
111111
echo 'ECS_DISABLE_PRIVILEGED=${var.ecs_disable_privilegged_mode}' >> /etc/ecs/ecs.config
112112
echo 'ECS_AVAILABLE_LOGGING_DRIVERS=["awslogs","fluentd"]' >> /etc/ecs/ecs.config
113113
USERDATA
114-
115-
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html
116-
vpc_subnets_ids = {
117-
private = module.dynamic_subnets.private_subnet_ids
118-
public = module.dynamic_subnets.public_subnet_ids
119-
}
120114
}
121115

122116
module "ecs_instance_label" {
123117
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
124-
attributes = [compact(concat(var.attributes, ["ecs", "instance"]))]
118+
attributes = compact(concat(var.attributes, ["ecs", "instance"]))
125119
delimiter = var.delimiter
126120
name = var.name
127121
namespace = var.namespace
128122
stage = var.stage
129-
tags = merge({
123+
tags = merge({
130124
"Cluster" = module.ecs.this_ecs_cluster_name
131125
}, var.tags)
132126
}
@@ -200,7 +194,7 @@ module "autoscaling_group" {
200194
stage = var.stage
201195
tags = module.ecs_instance_label.tags
202196

203-
security_group_ids = [var.ec2_asg_security_group_ids, aws_security_group.ecs_instance[0].id]
197+
security_group_ids = compact(concat(var.ec2_asg_security_group_ids, [aws_security_group.ecs_instance[0].id]))
204198
subnet_ids = local.ec2_nat_setup ? module.dynamic_subnets.private_subnet_ids : module.dynamic_subnets.public_subnet_ids
205199

206200
image_id = data.aws_ami.amazon_linux_ecs[0].id
@@ -353,9 +347,7 @@ module "alb_target_group_alarms" {
353347
stage = var.stage
354348
tags = var.tags
355349

356-
alb_name = module.alb.alb_name
357350
alb_arn_suffix = module.alb.alb_arn_suffix
358-
target_group_name = data.aws_alb_target_group.default.name
359351
target_group_arn_suffix = data.aws_alb_target_group.default.arn_suffix
360352
target_3xx_count_threshold = var.alb_target_group_alarms_3xx_threshold
361353
target_4xx_count_threshold = var.alb_target_group_alarms_4xx_threshold
@@ -364,9 +356,15 @@ module "alb_target_group_alarms" {
364356
period = var.alb_target_group_alarms_period
365357
evaluation_periods = var.alb_target_group_alarms_evaluation_periods
366358

367-
ok_actions = var.alb_target_group_alarms_ok_actions
368-
alarm_actions = var.alb_target_group_alarms_alarm_actions
369-
insufficient_data_actions = var.alb_target_group_alarms_insufficient_data_actions
359+
# https://github.com/cloudposse/terraform-aws-alb-target-group-cloudwatch-sns-alarms/pull/18
360+
ok_actions = [aws_sns_topic.default.arn]
361+
alarm_actions = [aws_sns_topic.default.arn]
362+
insufficient_data_actions = [aws_sns_topic.default.arn]
363+
notify_arns = [aws_sns_topic.default.arn]
364+
}
365+
366+
resource "aws_sns_topic" "default" {
367+
name = "test"
370368
}
371369

372370
#############################################################
@@ -375,7 +373,7 @@ module "alb_target_group_alarms" {
375373

376374
module "traefik" {
377375
source = "git::https://github.com/aleks-fofanov/terraform-aws-ecs-traefik-service.git?ref=terraform012_migration"
378-
attributes = [compact(concat(var.attributes, ["traefik"]))]
376+
attributes = compact(concat(var.attributes, ["traefik"]))
379377
delimiter = var.delimiter
380378
name = var.name
381379
namespace = var.namespace

variables.tf

Lines changed: 81 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,75 @@ variable "ec2_asg_ebs_optimized" {
118118
}
119119

120120
variable "ec2_asg_block_device_mappings" {
121-
description = "Specify volumes to attach to the instance in ASG besides the volumes specified by the AMI"
122-
type = list(string)
123-
default = []
121+
description = "Specify volumes to attach to the instance besides the volumes specified by the AMI"
122+
123+
type = list(object({
124+
device_name = string
125+
no_device = bool
126+
virtual_name = string
127+
ebs = object({
128+
delete_on_termination = bool
129+
encrypted = bool
130+
iops = number
131+
kms_key_id = string
132+
snapshot_id = string
133+
volume_size = number
134+
volume_type = string
135+
})
136+
}))
137+
138+
default = []
124139
}
125140

126141
variable "ec2_asg_instance_market_options" {
127-
description = "The market (purchasing) option for the instances in ASG"
128-
type = list(string)
129-
default = []
142+
description = "The market (purchasing) option for the instances"
143+
144+
type = object({
145+
market_type = string
146+
spot_options = object({
147+
block_duration_minutes = number
148+
instance_interruption_behavior = string
149+
max_price = number
150+
spot_instance_type = string
151+
valid_until = string
152+
})
153+
})
154+
155+
default = null
130156
}
131157

132158
variable "ec2_asg_placement" {
133-
description = "The placement specifications of the instances in ASG"
134-
type = list(string)
135-
default = []
159+
description = "The placement specifications of the instances"
160+
161+
type = object({
162+
affinity = string
163+
availability_zone = string
164+
group_name = string
165+
host_id = string
166+
tenancy = string
167+
})
168+
169+
default = null
136170
}
137171

138172
variable "ec2_asg_credit_specification" {
139-
description = "Customize the credit specification of the instances in ASG"
140-
type = list(string)
141-
default = []
173+
description = "Customize the credit specification of the instances"
174+
175+
type = object({
176+
cpu_credits = string
177+
})
178+
179+
default = null
142180
}
143181

144182
variable "ec2_asg_elastic_gpu_specifications" {
145-
description = "Specifications of Elastic GPU to attach to the instances in ASG"
146-
type = list(string)
147-
default = []
183+
description = "Specifications of Elastic GPU to attach to the instances"
184+
185+
type = object({
186+
type = string
187+
})
188+
189+
default = null
148190
}
149191

150192
variable "ec2_asg_disable_api_termination" {
@@ -416,8 +458,9 @@ variable "alb_https_ingress_prefix_list_ids" {
416458
}
417459

418460
variable "alb_https_ssl_policy" {
419-
description = "The name of the SSL Policy for the listener."
420-
default = "ELBSecurityPolicy-2015-05"
461+
description = "The name of the SSL Policy for the listener. See https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html"
462+
default = "ELBSecurityPolicy-TLS-1-2-2017-01"
463+
type = string
421464
}
422465

423466
variable "alb_http_to_https_redirect_enabled" {
@@ -519,19 +562,19 @@ variable "alb_target_group_alarms_evaluation_periods" {
519562
variable "alb_target_group_alarms_alarm_actions" {
520563
type = list(string)
521564
description = "A list of ARNs (i.e. SNS Topic ARN) to execute when ALB Target Group alarms transition into an ALARM state from any other state"
522-
default = []
565+
default = [""]
523566
}
524567

525568
variable "alb_target_group_alarms_ok_actions" {
526569
type = list(string)
527570
description = "A list of ARNs (i.e. SNS Topic ARN) to execute when ALB Target Group alarms transition into an OK state from any other state"
528-
default = []
571+
default = [""]
529572
}
530573

531574
variable "alb_target_group_alarms_insufficient_data_actions" {
532575
type = list(string)
533576
description = "A list of ARNs (i.e. SNS Topic ARN) to execute when ALB Target Group alarms transition into an INSUFFICIENT_DATA state from any other state"
534-
default = []
577+
default = [""]
535578
}
536579

537580
variable "traefik_launch_type" {
@@ -661,20 +704,28 @@ variable "traefik_deployment_minimum_healthy_percent" {
661704
}
662705

663706
variable "traefik_mount_points" {
664-
type = list(string)
707+
type = list(object({
708+
containerPath = string
709+
sourceVolume = string
710+
}))
711+
665712
description = "Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`"
666-
default = []
667-
#default = [
668-
# {
669-
# containerPath = "/tmp"
670-
# sourceVolume = "test-volume"
671-
# }
672-
#]
713+
default = null
673714
}
674715

675716
variable "traefik_volumes" {
676-
type = list(string)
677-
description = "Task volume definitions as list of maps"
717+
type = list(object({
718+
host_path = string
719+
name = string
720+
docker_volume_configuration = list(object({
721+
autoprovision = bool
722+
driver = string
723+
driver_opts = map(string)
724+
labels = map(string)
725+
scope = string
726+
}))
727+
}))
728+
description = "Task volume definitions as list of configuration objects"
678729
default = []
679730
}
680731

0 commit comments

Comments
 (0)