terraform-aws-vpc-peering
terraform-aws-vpc-peering copied to clipboard
[BUG] "count" cannot be determined until apply
Describe the bug I just want to configure a VPC peering between 3 AWS account, but I have an error message "The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created."
The issue looks related to this : https://github.com/grem11n/terraform-aws-vpc-peering/issues/83 but as you can see in my configuration, I have set depends_on
.
Terraform version: 1.4.6
Module version: 5.1.0
Error message:
╷
│ Error: Invalid count argument
│
│ on .terraform/modules/vpc-peering/main.tf line 55, in resource "aws_route" "this_routes":
│ 55: count = local.create_routes_this ? length(local.this_routes) : 0
│
│ 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.
╵
╷
│ Error: Invalid count argument
│
│ on .terraform/modules/vpc-peering/main.tf line 79, in resource "aws_route" "peer_routes":
│ 79: count = local.create_routes_peer ? length(local.peer_routes) : 0
│
│ 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.
Terraform code that produces the error:
module "vpc-peering" {
source = "grem11n/vpc-peering/aws"
version = "5.1.0"
depends_on = [
module.vpc_source,
module.vpc_destination
]
providers = {
aws.this = aws.source
aws.peer = aws.destination
}
this_vpc_id = module.vpc_source.vpc_id
peer_vpc_id = module.vpc_destination.vpc_id
auto_accept_peering = true
tags = local.common_tags
}
Additional context I use the "terraform-aws-modules/vpc/aws" module to create a VPC for each AWS account and I want to configure peering between theses VPC in the same terraform project.