Reputation: 386
I am creating a below
ABC -- ecs.tf (gives me cluster id)
Content of ecs.tf:
resource "aws_ecs_cluster" "first_cluster" {
name = "firstCluster"
capacity_providers = ["FARGATE"]
default_capacity_provider_strategy {
capacity_provider = "FARGATE"
base = 0
weight = 1
}
setting {
name = "containerInsights"
value = "enabled"
}
}
output "cluster_id" {
value = aws_ecs_cluster.first_cluster.id
}
Now under ABC folder which is root folder, i have another folder with CHILD folder which has app.tf
Question: How can i use cluster_id from ecs.tf in CHILD\app.tf ?
app.tf:
This is the challenge, i need to get the cluster_id value from ecs.tf output value from parent folder
My app.tf file contains something like below
module "xyz" {
source = "some modudle which needs cluster_id as input"
cluster_id = ??
}
Help me with what i need to put for cluster_id
Upvotes: 2
Views: 5662
Reputation: 238081
How can i use cluster_id from ecs.tf in CHILD\app.tf ?
You can't access it directly. Your parent module must pass cluster_id
as an input argument to your module, e.g.:
resource "aws_ecs_cluster" "first_cluster" {
name = "firstCluster"
capacity_providers = ["FARGATE"]
default_capacity_provider_strategy {
capacity_provider = "FARGATE"
base = 0
weight = 1
}
setting {
name = "containerInsights"
value = "enabled"
}
}
module "child" {
source = "./CHILD"
cluster_id = aws_ecs_cluster.first_cluster.id
}
Upvotes: 0