Hi folks.
So what I’m trying to do is that I’m creating a vpc with 3 subnets and now I want to create one kubernetes cluster in each subnet. VPC-subnets and kubernetes cluster are defined as modules. The problem is that I cannot relate these two modules together. For example, this is how my main.tf looks like:
module "vpc_subnet" {
source = "./modules/vpc_subnets"
}
module "otc_cce_cluster" {
source = "./modules/k8s"
for_each = module.vpc_subnet.subnet_id
vpc_id = module.vpc_subnet.vpc_id
subnet_id = module.vpc_subnet.subnet_id
depends_on = [
module.vpc_subnet
]
}
But then the error says:
Error: Unsupported attribute
│
│ on main.tf line 11, in module "otc_cce_cluster":
│ 11: for_each = module.vpc_subnet.subnet_id
│ ├────────────────
│ │ module.vpc_subnet is a object, known only after apply
│
│ This object does not have an attribute named "subnet_id".
╵
The arrangement of my folders are like so:
-modules
|___vpc_subnet
| |____main.tf
| |____variables.tf
|
|___k8s
| |____main.tf
| |____variables.tf
-main.tf
-variables.tf
I’m wondering if there is any solid example of doing such a thing or a quick tip how to move forward.
Thanks