hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.72k stars 9.08k forks source link

[Bug]: Investigate why IMDSv2 are required if Ubuntu 24.04 is run on aws_instance #38294

Closed EugenKon closed 1 week ago

EugenKon commented 1 month ago

Terraform Core Version

v1.8.5

AWS Provider Version

v5.55.0

Affected Resource(s)

Expected Behavior

IMDSv2 should be optional: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#http_tokens

Actual Behavior

It was switched to required.

More details: https://github.com/hashicorp/consul/issues/21525#issuecomment-2215433543

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

n/a

Steps to Reproduce

Run EC2 instance with installed Ubuntu 24.04 instead of 22.04

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 month ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

EugenKon commented 1 month ago

So when no value is explicitly provided then instance is deployed with required value for Ubuntu 24.04 type of instance. image

Though it is still deployed with optional as documented for 22.04 type of instance.

If it is configured to use optional:

  metadata_options {
    http_tokens            = "optional"
  }

Then plan looks like next:

  # module.private-cloud.aws_instance.server[0] will be updated in-place
  ~ resource "aws_instance" "server" {
        id                                   = "i-x"
        tags                                 = {
            "ConsulAutoJoin" = "nomad-auto-join"
            "Name"           = "nomad-server-0"
            "NomadType"      = "server"
        }
        # (40 unchanged attributes hidden)

      ~ metadata_options {
          ~ http_tokens                 = "required" -> "optional"
            # (4 unchanged attributes hidden)
        }

        # (7 unchanged blocks hidden)
    }

This should be fixed to use "optional" value for any types of instances as documented.

justinretzolk commented 1 month ago

Hey @EugenKon 👋 Thank you for taking the time to raise this! It looks like the http_tokens argument is both Computed and Optional (in the provider schema), which means that if it's not provided in the configuration, it gets set to whatever is in the response from the API.

With that in mind, it sounds like this should be a documentation fix, where we either remove the mention of a default, or update it if what the API returns by default has changed. I'm of the mind that we should remove the mention of a default value because a default value is not being set at the schema level, and what's being returned from AWS by default seems to be inconsistent. Does that seem like the right course of action to you?

EugenKon commented 1 month ago

Yep, we could remove the mention about default. But it worth to add that the value could depend on AMI version (response from AWS API). I suppose the documentation should recommend to configure that option explicitly to escape problems.

stefanfreitag commented 2 weeks ago

Hi @justinretzolk, hi @EugenKon, let me have look into updating the docs.

github-actions[bot] commented 1 week ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

EugenKon commented 1 week ago

@stefanfreitag See my comment in your PR. Your fix does not contain information that the value depends on AMIs and has dynamic nature.

github-actions[bot] commented 1 week ago

This functionality has been released in v5.64.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!