Terraform: provider/aws: name_prefix in aws_launch_configuration not used

Created on 31 Oct 2016  ยท  3Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.7.7

Affected Resource(s)

aws_launch_configuration

Terraform Configuration Files

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
    }
}

Debug Output

Panic Output

Expected Behavior

Instances launched should have a the prefix appended by some number in the EC2 console.

Actual Behavior

All the instances launch with a blank name.

Steps to Reproduce

  1. terraform apply
  2. Check EC2 console

Important Factoids

Running in us-east-2 (Ohio) region of AWS

References

bug provideaws

Most helpful comment

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

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ronnix picture ronnix  ยท  3Comments

rjinski picture rjinski  ยท  3Comments

thebenwaters picture thebenwaters  ยท  3Comments

ketzacoatl picture ketzacoatl  ยท  3Comments

shanmugakarna picture shanmugakarna  ยท  3Comments