Amazon web services 模块内未识别地形子网详细信息
我有Terraform脚本,它将创建VPC、负载均衡器和ECS。 使用模块(主应用程序文件夹内的文件夹)创建任务定义,但不允许访问在此模块外创建的资源,如子网、安全组。Amazon web services 模块内未识别地形子网详细信息,amazon-web-services,module,terraform,terraform-template-file,Amazon Web Services,Module,Terraform,Terraform Template File,我有Terraform脚本,它将创建VPC、负载均衡器和ECS。 使用模块(主应用程序文件夹内的文件夹)创建任务定义,但不允许访问在此模块外创建的资源,如子网、安全组。 我想知道如何从此模块文件夹tf访问这些资源。如果您想通过实例访问从名为create\u VPC的模块创建的VPC的ID,您需要将其导出,并将类似内容添加到模块代码中 创建专有网络/output.tf: output "vpc_id" { value="${aws_vpc.my_vpc.id}" } module "crea
我想知道如何从此模块文件夹tf访问这些资源。如果您想通过实例访问从名为
create\u VPC
的模块创建的VPC的ID,您需要将其导出,并将类似内容添加到模块代码中
创建专有网络/output.tf:
output "vpc_id" {
value="${aws_vpc.my_vpc.id}"
}
module "create_vpc" {
source = "../create_vpc"
}
resource "aws_internet_gateway" "vpc_internet_gateway" {
vpc_id = "${module.create_vpc.vpc_id}"
}
注意:显然,您需要在模块内部创建一个名为my_-VPC
的专有网络,通常在名为create_-VPC/main.tf
的文件中,但我认为您可以控制该部分
然后,您只需调用该模块的vpc\u id
输出,如下所示:
site/main.tf:
output "vpc_id" {
value="${aws_vpc.my_vpc.id}"
}
module "create_vpc" {
source = "../create_vpc"
}
resource "aws_internet_gateway" "vpc_internet_gateway" {
vpc_id = "${module.create_vpc.vpc_id}"
}
注意:此处创建的专有网络互联网网关只是使用专有网络ID的示例
以类似的方式,您可以将子网、安全组名称和ID等从一个模块导出到另一个模块