- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 230
Description
Description
Please provide a clear and concise description of the issue you are encountering and a reproduction of your configuration (see the examples/* directory for references that you can copy+paste and tailor to match your configs if you are unable to copy your exact configuration). The reproduction MUST be executable by running terraform init && terraform apply without any further changes.
If your request is for a new feature, please use the Feature request template.
- ✋ I have searched the open/closed issues and my issue is not listed.
I tried looking through the solution on issue 59, but wasn't able to fully resolve it as it's the same, but a little different as well.
Follow up/similar to the following issue:
#59
⚠️  Note
Before you submit an issue, please perform the following first:
- Remove the local .terraformdirectory (! ONLY if state is stored remotely, which hopefully you are following that best practice!):rm -rf .terraform/
- Re-initialize the project root to pull down modules: terraform init
- Re-attempt your terraform plan or apply and check if the issue still persists
Versions
- 
Module version [Required]: 2.10.12
- 
Terraform version: 1.5.2
- Provider version(s):
Reproduction Code [Required]:
resource "aws_vpc_endpoint_service" "this" {
  count = var.create && var.create_endpoint_service ? 1 : 0
  acceptance_required        = true
  network_load_balancer_arns = var.network_load_balancer_arns
  allowed_principals         = var.allowed_principals
  private_dns_name           = var.private_dns_name
  tags = merge({
    Name = format("%s-endpoint-service", var.name)
  })
}
module "r53_dns" {
  source  = "terraform-aws-modules/route53/aws//modules/zones"
  version = "~> 2.0"	
  zone_id = var.zone_id
  records_jsonencoded = jsonencode([
    {
      name = aws_vpc_endpoint_service.this[0].private_dns_name_configuration[0].name
      type = "TXT"
      ttl  = 1800
      records = [
        aws_vpc_endpoint_service.this[0].private_dns_name_configuration[0].value
      ]
    },
  ])
}
Steps to reproduce the behavior:
- Not using workspaces,
- Cleared local cache
- Run terraform init&&terraform plan -out=tfplan
Expected behavior
- Expect the r53 record to be able to be created from the created endoint resource.
Actual behavior
│ Error: Invalid for_each argument
│ 
│   on .terraform/modules/private_link_host.private_svc_endpoint_dns_verification/modules/records/main.tf line 19, in resource "aws_route53_record" "this":
│   19:   for_each = { for k, v in local.recordsets : k => v if var.create && (var.zone_id != null || var.zone_name != null) }
│     ├────────────────
│     │ local.recordsets will be known only after apply
│     │ var.create is true
│     │ var.zone_id is "Z3RSZW2EMHYAKV"
│     │ var.zone_name is null
│ 
│ The "for_each" map includes keys derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the instances of this resource.
│ 
│ When working with unknown values in for_each, it's better to define the map keys statically in your configuration and place apply-time results only in the map values.
│ 
│ Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge.
Terminal Output Screenshot(s)
Additional context
I have tried depends_on with many of the resources in there, but still met with the same error unfortunately.