我具有以下结构:
modules
|_ test1
| |_vpc.tf
|_test2
|_subnet.tf
我已经在test1 / vpc.tf中创建了一个vpc
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
}
我在输出中得到vpc id,例如:
output "vpc_id" {
value = aws_vpc.main.id
}
如何将此ID传递到test2 / subnet.tf文件?我正在网上搜索,似乎找不到答案。
答案 0 :(得分:5)
在subnet.tf中创建一个变量:
variable "vpc_id" {
type = string
}
然后在要使用这两个模块的主terraform文件中,将获取vpc模块的输出并将其传递到子网模块的输入:
module "vpc" {
source = "modules/test1"
}
module "subnet" {
source = "modules/test2"
vpc_id = module.vpc.vpc_id
}