terraform-aws-modules / terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws
Apache License 2.0
758 stars 1.88k forks source link

feat: Add instance IPv6 addresses to the outputs #249

Closed lucasvuotto closed 2 years ago

lucasvuotto commented 3 years ago

Description

Added an output for the ipv6_addresses of the AWS instances, similar to both public_ip and private_ip.

Motivation and Context

Motivation is the same as #241 . In particular, relying on aws_instance data source overly complicates working with IPv6 if using count or for_each in the module, having to split apply into 2 steps: one targeted for this module's instances, another one for the rest of the stuff, as you can't use a dynamic for_each in a data source:

╷
│ Error: Invalid for_each argument
│
│   on main.tf line 96, in data "aws_instance" "applied_ec2":
│   96:   for_each    = toset(module.ec2[*].id)
│     ├────────────────
│     │ module.ec2 is tuple with 1 element
│
│ The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work
│ around this, use the -target argument to first apply only the resources that the for_each depends on.
╵

This is particular handy when the subnet the instance is placed in assigns IPv6 addresses at creation time, as neither ipv6_addresses or ipv6_addresses_count are required to be set in that case to get an IPv6 address.

Do note that aws_spot_instance_request resource doesn't offer a similar attribute, hence it isn't covered in this PR.

Breaking Changes

How Has This Been Tested?

antonbabenko commented 2 years ago

This PR is included in version 3.3.0 :tada:

github-actions[bot] commented 2 years ago

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.