pulumi-aws icon indicating copy to clipboard operation
pulumi-aws copied to clipboard

aws.ec2.LaunchTemplate does not set LaunchTemplatMetadataOptions

Open quodlibetor opened this issue 3 years ago • 1 comments

What happened?

given a launchtemplate that includes:

aws.ec2.LaunchTemplate(
        f"{STACK}-{name}",
        metadata_options=aws.ec2.LaunchTemplateMetadataOptionsArgs(
            http_put_response_hop_limit=2,
            instance_metadata_tags="enabled",
        ),
        # snip ..
    )

Pulumi always shows the metadata options as needing to be set. And, indeed, the instances that come up as part of the ASG do not have any metadata options set.

Repeatedly running pulumi up shows the options as unset, but never sets them.

Steps to reproduce

This pulumi stack:

import pulumi
import pulumi_aws as aws

STACK = pulumi.get_stack()

ami = aws.ec2.get_ami(
    filters=[
        aws.ec2.GetAmiFilterArgs(
            name="name",
            values=["amzn2-ami-hvm-*-x86_64-ebs"],
        ),
        aws.ec2.GetAmiFilterArgs(
            name="root-device-type",
            values=["ebs"],
        ),
        aws.ec2.GetAmiFilterArgs(
            name="virtualization-type",
            values=["hvm"],
        ),
    ],
    most_recent=True,
    owners=["amazon"],
)

lc = aws.ec2.LaunchTemplate(
    f"{STACK}-test",
    name_prefix=f"{STACK}-test-",
    image_id=ami.id,
    instance_type="t2.micro",
    metadata_options=aws.ec2.LaunchTemplateMetadataOptionsArgs(
        http_put_response_hop_limit=2,
        instance_metadata_tags="enabled",
    ),
)

group = aws.autoscaling.Group(
    f"{STACK}-test",
    launch_template=aws.autoscaling.GroupLaunchTemplateArgs(id=lc.id),
    min_size=1,
    max_size=3,
    availability_zones=["us-east-2a"]
)

Seems to succeed:

$ pulumi up
Previewing update (test)

View Live: https://app.pulumi.com/quodlibetor/whatchow/test/updates/3

     Type                       Name           Status
 +   pulumi:pulumi:Stack        whatchow-test  created
 +   ├─ aws:ec2:LaunchTemplate  test-test      created
 +   └─ aws:autoscaling:Group   test-test      created

Resources:
    + 3 created

Duration: 1m18s

But then if you examine the infrastructure created it does not have the correct settings. Additionally, running pulumi up again any number of times will not correctly set metadata options:

$ pulumi up
Previewing update (test)

View Live: https://app.pulumi.com/quodlibetor/whatchow/test/previews/f78ce6c9-c13f-4cad-a996-b9c9a3ed30c2

     Type                       Name           Plan       Info
     pulumi:pulumi:Stack        whatchow-test
 ~   └─ aws:ec2:LaunchTemplate  test-test      update     [diff: ~metadataOptions]

Resources:
    ~ 1 to update
    2 unchanged

Do you want to perform this update? details
  pulumi:pulumi:Stack: (same)
    [urn=urn:pulumi:test::whatchow::pulumi:pulumi:Stack::whatchow-test]
    ~ aws:ec2/launchTemplate:LaunchTemplate: (update)
        [id=lt-058a942266ba298bc]
        [urn=urn:pulumi:test::whatchow::aws:ec2/launchTemplate:LaunchTemplate::test-test]
        [provider=urn:pulumi:test::whatchow::pulumi:providers:aws::default_5_10_0::8d876028-a449-4c6d-a729-344e3f783a27]
      ~ metadataOptions: {
          ~ httpPutResponseHopLimit: 0 => 2
          + instanceMetadataTags   : "enabled"
        }

Do you want to perform this update?  [Use arrows to move, enter to select, type to filter]
  yes
> no
  details

Expected Behavior

I expected metadata options to be correctly set from the LaunchTemplate, or to receive an error explaining why it can't be done.

Actual Behavior

Pulumi up seems to succeed but does not set the options.

Versions used

❯ pulumi about
CLI
Version      3.36.0
Go Version   go1.17.11
Go Compiler  gc

Plugins
NAME        VERSION
aws         5.10.0
aws-iam     0.0.5
awsx        1.0.0-beta.9
docker      3.2.0
eks         0.40.0
kubernetes  3.20.0
python      unknown

Host
OS       darwin
Version  12.4
Arch     x86_64

This project is written in python: executable='~/.asdf/shims/python3' version='3.10.3'

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

quodlibetor avatar Jul 24 '22 20:07 quodlibetor

Hi @quodlibetor

I apologise for the issue here - as we are pulling the required details from the upstream TF provider into our code, I can see the same issue is present there - https://github.com/hashicorp/terraform-provider-aws/issues/25909

I will have a look and see if we can fix this up

Paul

stack72 avatar Jul 25 '22 11:07 stack72