I am still very much a beginner in Terraform. I have a scenario where suppose only a single AWS component need to be recreated but is dependent on other component which does not require any changes e.g. Changes to Launch configuration component is not possible if the AutoScaling group is present. Even if the ASG is marked as tainted still terraform throws an error ""
aws_launch_configuration.sample-launch-configuration: 1 error(s) occurred:
aws_launch_configuration.sample-launch-configuration: Error creating launch configuration: AlreadyExists: Launch Configuration by this name already exists - A launch configuration already exists with the name sample-lc status code: 400, request id: 3dc2da6d-96e4-11e8-9086-cb6ff2d21a1c
What is the way to fix these kind of dependencies without destroying the whole cluster?
EDITED: Adding source code. (Partial code sample)
resource "aws_autoscaling_group" "sample-autoscaling-group" {
name = "sample-asg"
max_size = "${var.max_instance_size}"
min_size = "${var.min_instance_size}"
desired_capacity = "${var.desired_capacity}"
vpc_zone_identifier = ["${var.private-subnets}"]
launch_configuration = "${aws_launch_configuration.sample-launch-configuration.name}"
health_check_type = "EC2"
lifecycle {
create_before_destroy = true
}
}
resource "aws_launch_configuration" "sample-launch-configuration" {
name = "sample-lc"
image_id = "ami-706cca12"
instance_type = "t2.small"
iam_instance_profile = "${aws_iam_instance_profile.ecs-ec2-service-profile.id}"
lifecycle {
create_before_destroy = true
}
security_groups = ["${aws_security_group.test_public_sg.id}"]
associate_public_ip_address = "true"
key_name = "${var.ecs-key-pair-name}"
user_data = "${file("./templates/user_data.sh")}"
}
If I change say the user_data.sh file and try to execute this it fails.