Skip to content

Commit bbf007e

Browse files
author
Ryan Jiang
authored
Merge pull request #9 from yilinjuang/patch-2
Fix deleting launch configuration because it is attached to AutoScalingGroup
2 parents 858dda6 + 95543a8 commit bbf007e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/aws_ecs_ec2/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ data "aws_ami" "this" {
3737
}
3838

3939
resource "aws_launch_configuration" "this" {
40-
name = "${var.deployment_name}-ecs-launch-configuration"
40+
name_prefix = "${var.deployment_name}-ecs-launch-configuration-"
4141
image_id = data.aws_ami.this.id
4242
instance_type = var.instance_type # e.g. t2.medium
4343

@@ -65,6 +65,10 @@ resource "aws_launch_configuration" "this" {
6565

6666
# Allow the EC2 instances to access AWS resources on your behalf, using this instance profile and the permissions defined there
6767
iam_instance_profile = aws_iam_instance_profile.ec2.arn
68+
69+
lifecycle {
70+
create_before_destroy = true
71+
}
6872
}
6973

7074
resource "aws_autoscaling_group" "this" {
@@ -99,6 +103,10 @@ resource "aws_autoscaling_group" "this" {
99103
value = "${var.deployment_name}-ec2-instance"
100104
propagate_at_launch = true
101105
}
106+
107+
lifecycle {
108+
create_before_destroy = true
109+
}
102110
}
103111

104112
# Attach an autoscaling policy to the spot cluster to target 70% MemoryReservation on the ECS cluster.

0 commit comments

Comments
 (0)