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

Execution fails when using vpc_attachments[].vpc_route_table_ids #111

Open
1 task done
Jarodiv opened this issue Jun 1, 2023 · 33 comments
Open
1 task done

Execution fails when using vpc_attachments[].vpc_route_table_ids #111

Jarodiv opened this issue Jun 1, 2023 · 33 comments

Comments

@Jarodiv
Copy link
Contributor

Jarodiv commented Jun 1, 2023

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.

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

Versions

  • Module version [Required]: 2.8.2
  • Terraform version:
    Terraform v1.3.7
    on darwin_arm64
    
  • Provider version(s):
    provider registry.terraform.io/hashicorp/aws v4.46.0
    

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
Copy link

github-actions bot commented Jul 2, 2023

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

@github-actions github-actions bot added the stale label Jul 2, 2023
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Jul 3, 2023

"Keep alive" post

@github-actions github-actions bot removed the stale label Jul 4, 2023
@github-actions
Copy link

github-actions bot commented Aug 4, 2023

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

@github-actions github-actions bot added the stale label Aug 4, 2023
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Aug 5, 2023

"Keep alive" post

@github-actions github-actions bot removed the stale label Aug 6, 2023
@timroh
Copy link

timroh commented Aug 31, 2023

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

@LuckyDucky583
Copy link

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
Copy link

github-actions bot commented Oct 1, 2023

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

@github-actions github-actions bot added the stale label Oct 1, 2023
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Oct 1, 2023

"Keep alive" post

@github-actions github-actions bot removed the stale label Oct 2, 2023
Copy link

github-actions bot commented Nov 1, 2023

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

@github-actions github-actions bot added the stale label Nov 1, 2023
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Nov 2, 2023

"Keep alive" post

@github-actions github-actions bot removed the stale label Nov 3, 2023
Copy link

github-actions bot commented Dec 3, 2023

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

@github-actions github-actions bot added the stale label Dec 3, 2023
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Dec 7, 2023

"Keep alive" post

@github-actions github-actions bot removed the stale label Dec 8, 2023
@Jarodiv Jarodiv closed this as completed Dec 19, 2023
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Dec 19, 2023

Closing this issue as it has been resolved in version 2.12.1 🎉
-> #112 (comment)

@Jarodiv Jarodiv reopened this Dec 19, 2023
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Dec 19, 2023

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

Copy link

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

@github-actions github-actions bot added the stale label Jan 19, 2024
@LuckyDucky583
Copy link

keep alive post

@github-actions github-actions bot removed the stale label Jan 20, 2024
Copy link

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

@github-actions github-actions bot added the stale label Feb 19, 2024
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Feb 20, 2024

"Keep alive" post

@github-actions github-actions bot removed the stale label Feb 21, 2024
@miguelvidex
Copy link

Can confirm, I have the same issue.

@lucaovieira
Copy link

I have the same issue.

Copy link

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

@github-actions github-actions bot added the stale label May 12, 2024
@Jarodiv
Copy link
Contributor Author

Jarodiv commented May 13, 2024

"Keep alive" post

@github-actions github-actions bot removed the stale label May 14, 2024
Copy link

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

@github-actions github-actions bot added the stale label Jun 13, 2024
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Jun 13, 2024

"Keep alive" post

@github-actions github-actions bot removed the stale label Jun 14, 2024
@wwebster-rr
Copy link

can confirm, also having this issue.

@partcyborg
Copy link

partcyborg commented Jul 17, 2024

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
Copy link

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.

Copy link

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

@github-actions github-actions bot added the stale label Aug 21, 2024
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Aug 21, 2024

"Keep alive" post

@github-actions github-actions bot removed the stale label Aug 22, 2024
Copy link

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

@github-actions github-actions bot added the stale label Sep 21, 2024
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Sep 21, 2024

"Keep alive" post

@github-actions github-actions bot removed the stale label Sep 22, 2024
Copy link

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

@github-actions github-actions bot added the stale label Oct 23, 2024
@Jarodiv
Copy link
Contributor Author

Jarodiv commented Oct 24, 2024

"Keep alive" post

@github-actions github-actions bot removed the stale label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants