I have a module that creates a config script based on passing a vpc_id. If I try to get that vpc_id from a vpc that I will create, I start getting errors like this:
Error: Invalid for_each argument
on ../modules/eksctl-config/data.tf line 30, in data "aws_subnet" "private_subnets":
30: for_each = data.aws_subnet_ids.private_subnet_ids.ids
The "for_each" 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 for_each depends on.
I’m not sure how to handle the situation. My module inputs look like this:
module "vpc" {
source = "../modules/eks-vpc"
name = var.name
region = var.region
eks_cluster_name = var.eks_cluster_name
}
module "config" {
source = "../modules/eksctl-config"
name = var.eks_cluster_name
region = var.region
vpc_id = module.vpc.vpc_id
instance_type = "m5.2xlarge"
public_key_name = "joaquin"
filename = "${path.module}/../../eksctl/cluster_config.yaml"
}