Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: aws_launch_template metadata_options instance_metadata_tags cannot be enabled #29209

Closed
dossy opened this issue Feb 2, 2023 · 8 comments · Fixed by #30107
Closed

[Bug]: aws_launch_template metadata_options instance_metadata_tags cannot be enabled #29209

dossy opened this issue Feb 2, 2023 · 8 comments · Fixed by #30107
Labels
bug Addresses a defect in current functionality. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@dossy
Copy link

dossy commented Feb 2, 2023

Terraform Core Version

1.3.7

AWS Provider Version

4.51.0

Affected Resource(s)

  • aws_launch_template

Expected Behavior

"Allow tags in metadata" in the launch template should be enabled when instance_metadata_tags in metadata_options is set to enabled.

Actual Behavior

"Allow tags in metadata" in the launch template is unset when instance_metadata_tags in metadata_options is set to enabled.

Relevant Error/Panic Output Snippet

2023-02-02T04:35:38.647Z [WARN]  Provider "provider[\"registry.terraform.io/hashicorp/aws\"]" produced an unexpected new value for module.api_asg.aws_launch_template.this[0], but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .metadata_options[0].instance_metadata_tags: was cty.StringVal("enabled"), but now cty.StringVal("")

Terraform Configuration Files

resource "aws_launch_template" "test" {
  name = "asg-template"
  metadata_options {
    instance_metadata_tags = "enabled"
  }
}

Steps to Reproduce

  • terraform init
  • terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

The comment in this this code on line 1141 hints at the solution to the problem: if you set metadata_options.http_endpoint to enabled, then instance_metadata_tags being set to enabled works. Otherwise, it results in the attribute being unset.

Silently ignoring the instance_metadata_tags setting is less than ideal - an error or at least a warning should be raised if it's set but will be ignored because http_endpoint is disabled.

This is especially frustrating because, according to the documentation for aws_launch_template, it says:

http_endpoint - (Optional) Whether the metadata service is available. Can be "enabled" or "disabled". (Default: "enabled").

However, this appears to be untrue, based on the code:

						"http_endpoint": {
							Type:         schema.TypeString,
							Optional:     true,
							Computed:     true,
							ValidateFunc: validation.StringInSlice(ec2.LaunchTemplateInstanceMetadataEndpointState_Values(), false),
						},

No default value specified.

Good news is if I explicitly set http_endpoint = "enabled" then instance_metadata_tags = "enabled" works as expected/advertised.

References

Would you like to implement a fix?

None

@dossy dossy added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Feb 2, 2023
@github-actions
Copy link

github-actions bot commented Feb 2, 2023

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/ec2 Issues and PRs that pertain to the ec2 service. label Feb 2, 2023
@justinretzolk justinretzolk added good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 2, 2023
@good92
Copy link

good92 commented Feb 10, 2023

It seems more linked with #25909

@w564791
Copy link

w564791 commented Mar 2, 2023

I had the same problem with v4.56.0

@pmmalinov01
Copy link

Got the same issue.

@wzzzrd86
Copy link
Contributor

I'll take a look at this

@wzzzrd86
Copy link
Contributor

I tested it and can reproduce it on the most current provider and the most current core version.

After looking at the code I also tested the following parameters which are in the same If statement together.

http-tokens
http-put-response-hop limit

  - .metadata_options[0].http_put_response_hop_limit: was cty.NumberIntVal(10), but now cty.NumberIntVal(0)
  - .metadata_options[0].http_tokens: was cty.StringVal("required"), but now cty.StringVal("")
  - .metadata_options[0].instance_metadata_tags: was cty.StringVal("enabled"), but now cty.StringVal("")

After reading the documentation I don't see that any of these values are dependent on http-endpoint.

After moving these assignments out of the larger if statement and compiling locally I was able to successfully test.

Test Code

resource "aws_launch_template" "test" {
name = "asg-template"
metadata_options {
instance_metadata_tags = "enabled"
http_tokens = "required"
http_put_response_hop_limit = 10
}

Results in AWS ASG Launch Templatesimage

I'll take a swing at some acceptance tests after this.

I think this might also resolve 23174, 25909

@github-actions
Copy link

This functionality has been released in v4.61.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
6 participants