Terraform v0.7.7
aws_launch_configuration
resource "aws_launch_configuration" "as_some_lc" {
name_prefix = "terraform-lc-group-"
image_id = "${data.aws_ami.jessie.id}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.some_key_pair.id}"
associate_public_ip_address = false
enable_monitoring = false
security_groups = ["${aws_security_group.some_sg.id}"]
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "some_asg" {
launch_configuration = "${aws_launch_configuration.as_some_lc.name}"
min_size = 1
max_size = 1
# subnets to launch in
vpc_zone_identifier = ["${aws_subnet.some_subnet_a.id}"]
lifecycle {
create_before_destroy = true
}
}
Instances launched should have a the prefix appended by some number in the EC2 console.
All the instances launch with a blank name.
terraform applyRunning in us-east-2 (Ohio) region of AWS
Hi @druidsbane
Sorry for the confusion here. The name_prefix isn't actually for naming the instances themselves, it's for the name of the launch config. To give you a little background here.
You create a Launch Configuration in AWS and associate it with an AutoScaling Group.
If you want to make an amendment to that Launch Config, you cannot edit it directly, you need to create a new one and associate that new one to the AutoScaling Group
In Terraform, if we used a name parameter on the LaunchConfig and the lifecycle block, then we need to terraform to create a new LaunchConfig and associate it to the ASG before destroying the old one. We can't create 2 LaunchConfigs of the same name
So we introduced the name_prefix parameter - so this is the name prefix of the Launch Config only
If you want to name instances, you need to edit your AutoScaling Group to look as follows:
resource "aws_autoscaling_group" "some_asg" {
launch_configuration = "${aws_launch_configuration.as_some_lc.name}"
min_size = 1
max_size = 1
# subnets to launch in
vpc_zone_identifier = ["${aws_subnet.some_subnet_a.id}"]
lifecycle {
create_before_destroy = true
}
tag {
key = "Name"
value = "mymachine_name"
propagate_at_launch = true
}
}
Hope this helps
Paul
@stack72 That makes perfect sense. Thank you very much for clearing that up. Hopefully this will serve as documentation for anyone else that runs into this!
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Hi @druidsbane
Sorry for the confusion here. The
name_prefixisn't actually for naming the instances themselves, it's for the name of the launch config. To give you a little background here.You create a Launch Configuration in AWS and associate it with an AutoScaling Group.
If you want to make an amendment to that Launch Config, you cannot edit it directly, you need to create a new one and associate that new one to the AutoScaling Group
In Terraform, if we used a
nameparameter on the LaunchConfig and the lifecycle block, then we need to terraform to create a new LaunchConfig and associate it to the ASG before destroying the old one. We can't create 2 LaunchConfigs of the same nameSo we introduced the
name_prefixparameter - so this is the name prefix of the Launch Config onlyIf you want to name instances, you need to edit your AutoScaling Group to look as follows:
Hope this helps
Paul