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
754 stars 1.87k forks source link

fix: Creation of an Instance with a Capacity Reservation ID #278

Closed schniber closed 2 years ago

schniber commented 2 years ago

Description

When trying to call the module with the specification of a Capacity Reservation ID, the module ends up with the following error:

╷ │ Error: Invalid function argument │ │ on .terraform/modules/terraform-aws-ec2-instance/main.tf line 45, in resource "aws_instance" "this": │ 45: capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null) │ ├──────────────── │ │ capacity_reservation_target.value is "cr-xxxxxxxx" │ │ Invalid value for "inputMap" parameter: lookup() requires a map as the │ first argument. ╵

As per line 45 analysis, it looks like the bug is in the following statement:

capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null)

it should rather be as follows:

capacity_reservation_id = lookup(capacity_reservation_target, "capacity_reservation_id", null)

In this case, terraform should lookup in the capacity reservation target map (since it is the iterator in the for_each) rather than in its value for the mapping of the attribute capacity reservation id

Motivation and Context

Fixes #277

Breaking Changes

No breaking changes, just fixing a typo in line 45 in the main.tf

How Has This Been Tested?

schniber commented 2 years ago

Hello @bryantbiggs,

Would it be possible for your to review this PR ?

Thanks in advance.

Bests.

Keep up the good work !

schniber commented 2 years ago

@bryantbiggs thanks for your feedback.

this was due to the fact that I mistakenly removed the end of tfdocs hook in the complete example README:

Now pre-commit hooks run correctly.

antonbabenko commented 2 years ago

This PR is included in version 4.1.1 :tada:

github-actions[bot] commented 1 year 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.