@@ -37,28 +37,29 @@ data "aws_ami" "this" {
37
37
]
38
38
}
39
39
40
- resource "aws_launch_configuration " "this" {
40
+ resource "aws_launch_template " "this" {
41
41
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 -"
43
43
image_id = data. aws_ami . this . id
44
44
instance_type = var. instance_type # e.g. t2.medium
45
45
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
+ }
48
54
49
55
# This user data represents a collection of “scripts” that will be executed the first time the machine starts.
50
56
# This specific example makes sure the EC2 instance is automatically attached to the ECS cluster that we create earlier
51
57
# 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
+ )
62
63
# If you want to SSH into the instance and manage it directly:
63
64
# 1. Make sure this key exists in the AWS EC2 dashboard
64
65
# 2. Make sure your local SSH agent has it loaded
@@ -80,10 +81,15 @@ resource "aws_autoscaling_group" "this" {
80
81
min_size = var. min_instance_count
81
82
desired_capacity = var. min_instance_count
82
83
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
+ }
84
89
85
90
default_cooldown = 30
86
91
health_check_grace_period = 30
92
+ health_check_type = " EC2"
87
93
88
94
termination_policies = [
89
95
" OldestInstance"
0 commit comments