Skip to content

Commit 5b5f342

Browse files
Everett SmithEverett Smith
authored andcommitted
Migrate from aws_launch_configuration to aws_launch_template
1 parent 24c36eb commit 5b5f342

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

modules/aws_ecs/ecs.tf

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,29 @@ data "aws_ami" "this" {
3737
]
3838
}
3939

40-
resource "aws_launch_configuration" "this" {
40+
resource "aws_launch_template" "this" {
4141
count = var.launch_type == "EC2" ? 1 : 0
42-
name_prefix = "${var.deployment_name}-ecs-launch-configuration-"
42+
name_prefix = "${var.deployment_name}-ecs-launch-template-"
4343
image_id = data.aws_ami.this.id
4444
instance_type = var.instance_type # e.g. t2.medium
4545

46-
enable_monitoring = true
47-
associate_public_ip_address = true
46+
monitoring {
47+
enabled = true
48+
}
49+
50+
network_interfaces {
51+
associate_public_ip_address = false
52+
security_groups = [aws_security_group.containers.id]
53+
}
4854

4955
# This user data represents a collection of “scripts” that will be executed the first time the machine starts.
5056
# This specific example makes sure the EC2 instance is automatically attached to the ECS cluster that we create earlier
5157
# and marks the instance as purchased through the Spot pricing
52-
user_data = <<-EOF
53-
#!/bin/bash
54-
echo ECS_CLUSTER=${var.deployment_name}-ecs >> /etc/ecs/ecs.config
55-
EOF
56-
57-
# We’ll see security groups later
58-
security_groups = [
59-
aws_security_group.containers.id
60-
]
61-
58+
user_data = base64encod(<<-EOF
59+
#!/bin/bash
60+
echo ECS_CLUSTER=${var.deployment_name}-ecs >> /etc/ecs/ecs.config
61+
EOF
62+
)
6263
# If you want to SSH into the instance and manage it directly:
6364
# 1. Make sure this key exists in the AWS EC2 dashboard
6465
# 2. Make sure your local SSH agent has it loaded
@@ -80,10 +81,15 @@ resource "aws_autoscaling_group" "this" {
8081
min_size = var.min_instance_count
8182
desired_capacity = var.min_instance_count
8283
vpc_zone_identifier = var.private_subnet_ids
83-
launch_configuration = aws_launch_configuration.this[0].name
84+
85+
launch_template {
86+
id = aws_launch_template.this[0].id
87+
version = "$Latest"
88+
}
8489

8590
default_cooldown = 30
8691
health_check_grace_period = 30
92+
health_check_type = "EC2"
8793

8894
termination_policies = [
8995
"OldestInstance"

0 commit comments

Comments
 (0)