Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Merged
merged 12 commits into from
Jul 21, 2022
Merged

Conversation

schniber
Copy link
Contributor

@schniber schniber commented Jul 19, 2022

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?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
    This fix is hard to test since it requires to have an ongoing capacity reservation which is released by AWS.
    In order to test this, I stopped at the plan stage.
  • I have executed pre-commit run -a on my pull request

@schniber
Copy link
Contributor Author

Hello @bryantbiggs,

Would it be possible for your to review this PR ?

Thanks in advance.

Bests.

Keep up the good work !

Copy link
Member

@bryantbiggs bryantbiggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be deleting the README documentation - not sure why our checks are still passing with all this being deleted. Please update when you get a chance

@schniber
Copy link
Contributor Author

@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.

@schniber schniber changed the title fix: Creation of an Intance with a Capacity Reservation ID fix: Creation of an Instance with a Capacity Reservation ID Jul 21, 2022
Copy link
Member

@bryantbiggs bryantbiggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @schniber !

@bryantbiggs bryantbiggs merged commit f12ac95 into terraform-aws-modules:master Jul 21, 2022
antonbabenko pushed a commit that referenced this pull request Jul 21, 2022
### [4.1.1](v4.1.0...v4.1.1) (2022-07-21)

### Bug Fixes

* Creation of an Instance with a Capacity Reservation ID ([#278](#278)) ([f12ac95](f12ac95))
@antonbabenko
Copy link
Member

This PR is included in version 4.1.1 🎉

@github-actions
Copy link

github-actions bot commented Nov 8, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creation of an Instance with a Capacity Reservation ID
3 participants