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

Creation of an Intance with a Capacity Reservation ID [ref #277] #281

Closed
1 task done
schniber opened this issue Jul 23, 2022 · 2 comments
Closed
1 task done

Creation of an Intance with a Capacity Reservation ID [ref #277] #281

schniber opened this issue Jul 23, 2022 · 2 comments

Comments

@schniber
Copy link
Contributor

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, "capacity_reservation_id", null)

it should rather be as follows:

capacity_reservation_id = lookup(capacity_reservation_specification.value.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

  • ✋ I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

  • Module version [Required]: 4.1.1

  • Terraform version: v1.2.5

  • Provider version(s): v4.22.0

Reproduction Code [Required]

Steps to reproduce the behavior:

Call the module with following inputs:

module "ec2_capacity_reservation" {
source = "../../"

name = "${local.name}-capacity-reservation"

ami = data.aws_ami.amazon_linux.id
instance_type = "u-6tb1.56xlarge"
subnet_id = element(module.vpc.private_subnets, 0)
vpc_security_group_ids = [module.security_group.security_group_id]
associate_public_ip_address = true

capacity_reservation_specification = {
capacity_reservation_target = {
capacity_reservation_id = "cr-00000000000000000"
}
}

tags = local.tags
}

Expected behavior

TF plan should go through and the module should create an EC2 Instance which consumes the capacity reservation.

Actual behavior

TF plan fails in assigning the right reservation id

Terminal Output Screenshot(s)

Additional context

@bryantbiggs
Copy link
Member

closed in #282

@github-actions
Copy link

github-actions bot commented Nov 8, 2022

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 Nov 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants