Closed schniber closed 2 years ago
closed in #282
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.
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
⚠️ Note
Before you submit an issue, please perform the following first:
.terraform
directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!):rm -rf .terraform/
terraform init
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