Since you are creating subnets in modules ecs_subnets_public_1
and ecs_subnets_private_1
, you shoudn't use data source
to get the information about these subnets. The ./modules/8_subnet
module should return all the information that it wants to expose to the parent module through outputs
as indicated in Module Composition of the TF docs. This is done using outout:
Output values to return results to the calling module, which it can then use to populate arguments elsewhere.
So your ./modules/8_subnet
would have output
for the subnet id. Something like this:
output "subnet_id" {
value = aws_subnet.mysubnet.id
}
Then to access it in parent module you would use the following instead of the data source:
module.ecs_subnets_private_1.subnet_id
# and
module.ecs_subnets_public_1.subnet_id
Nevertheless, the likely reason why your data.aws_subnet_ids
fail is because they probably run before the subnets are actually created. To fix that you would have to add depends_on
:
data "aws_subnet_ids" "public_1" {
vpc_id = module.ecs_vpc.vpc_id
tags = {
Name = "*terraform-subnet-public-1" // or two filter by a unique word use; *private*
}
depends_on = [module.ecs_subnets_public_1]
}
data "aws_subnet_ids" "private_1" {
vpc_id = module.ecs_vpc.vpc_id
tags = {
Name = "*terraform-subnet-private-1" // or two filter by a unique word use; *private*
}
depends_on = [module.ecs_subnets_private_1]
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…