terraform-aws-modules / terraform-aws-transit-gateway

Terraform module to create AWS Transit Gateway resources πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/transit-gateway/aws
Apache License 2.0
144 stars 225 forks source link

Execution fails when using `vpc_attachments[].vpc_route_table_ids` #111

Open Jarodiv opened 1 year ago

Jarodiv commented 1 year ago

Description

ℹ️ This is a copy of #100 which was closed automatically while still valid.

Trying to add routes to Route Tables provided via vpc_attachments[].vpc_route_table_ids results in Terraform failing with an error message.

Versions

Reproduction Code [Required]

Everything it needs is to configure IPv6 and provide VPC Route Tables:

module "my_vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 3.0"

  name = "my-vpc"
  cidr = "10.1.0.0/16"

  azs             = ["${local.region}a", "${local.region}b"]
  private_subnets = ["10.1.1.0/24", "10.1.2.0/24"]
  public_subnets  = ["10.1.101.0/24", "10.1.102.0/24"]

  enable_nat_gateway = false
}

module "my_tgw" {
  source  = "terraform-aws-modules/transit-gateway/aws"
  version = "~> 2.0"

  name = "my-tgw"

  vpc_attachments = {
    vpc = {
      vpc_id     = module.my_vpc.vpc_id
      subnet_ids = module.my_vpc.private_subnets

      tgw_destination_cidr = "0.0.0.0/0"
      vpc_route_table_ids  = module.my_vpc.private_route_table_ids
    },
  }
}

Expected behavior

The code runs and routes are being created.

Actual behavior

The code fails with

β•·
β”‚ Error: Invalid for_each argument
β”‚ 
β”‚   on .terraform/modules/my_tgw/main.tf line 112, in resource "aws_route" "this":
β”‚  112:   for_each = { for x in local.vpc_route_table_destination_cidr : x.rtb_id => x.cidr }
β”‚     β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚     β”‚ local.vpc_route_table_destination_cidr will be known only after apply
β”‚ 
β”‚ 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.
β•΅
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 1 year ago

"Keep alive" post

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 1 year ago

"Keep alive" post

timroh commented 1 year ago

Can confirm, we have the same issue. A two-step apply seems to be the best workaround right now.

LuckyDucky583 commented 1 year ago

Same here, it does work when replacing the for_each statement with a count, but the trade-off isn't worth it in our opinion.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 1 year ago

"Keep alive" post

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 1 year ago

"Keep alive" post

github-actions[bot] commented 11 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 11 months ago

"Keep alive" post

Jarodiv commented 11 months ago

Closing this issue as it has been resolved in version 2.12.1 πŸŽ‰ -> https://github.com/terraform-aws-modules/terraform-aws-transit-gateway/issues/112#issuecomment-1850127996

Jarodiv commented 11 months ago

Confused this issue with the other one I've created. Sorry for any inconveniences.

github-actions[bot] commented 10 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

LuckyDucky583 commented 10 months ago

keep alive post

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 9 months ago

"Keep alive" post

miguelvidex commented 8 months ago

Can confirm, I have the same issue.

lucaovieira commented 7 months ago

I have the same issue.

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 6 months ago

"Keep alive" post

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 5 months ago

"Keep alive" post

wwebster-rr commented 4 months ago

can confirm, also having this issue.

partcyborg commented 4 months ago

Same here, it does work when replacing the for_each statement with a count, but the trade-off isn't worth it in our opinion.

Really? My attempts to replace it with a count locally also fail with a similar error

β”‚ Error: Invalid count argument
β”‚
β”‚   on ../../main.tf line 133, in resource "aws_route" "this":
β”‚  133:   count = length(local.vpc_route_table_destination_cidr)
β”‚
β”‚ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict
β”‚ how many instances will be created. To work around this, use the -target argument to first apply only the resources
β”‚ that the count depends on.
LuckyDucky583 commented 3 months ago

Same here, it does work when replacing the for_each statement with a count, but the trade-off isn't worth it in our opinion.

Really? My attempts to replace it with a count locally also fail with a similar error

β”‚ Error: Invalid count argument
β”‚
β”‚   on ../../main.tf line 133, in resource "aws_route" "this":
β”‚  133:   count = length(local.vpc_route_table_destination_cidr)
β”‚
β”‚ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict
β”‚ how many instances will be created. To work around this, use the -target argument to first apply only the resources
β”‚ that the count depends on.

Interesting, might this be related to the tf version? I haven't tried this since August last year.

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 2 months ago

"Keep alive" post

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 1 month ago

"Keep alive" post

github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

Jarodiv commented 3 weeks ago

"Keep alive" post