我有以下主要。在我的Terraform子模块位于./network
module "test-vpc-module" {
source = "terraform-google-modules/network/google"
version = "~> 3.3.0"
project_id = var.project_id
network_name = var.network_name
mtu = 1460
subnets = [
{
subnet_name = "xxx-private"
subnet_ip = "172.16.3.0/24"
subnet_region = "us-central1"
subnet_private_access = "true"
},{
subnet_name = "us-central1-gke"
subnet_ip = "172.16.5.0/24"
subnet_region = "us-central1"
subnet_private_access = "true"
},
]
secondary_ranges = {
us-central1-gke = [
{
range_name = "gke-cluster-pods"
ip_cidr_range = "10.188.0.0/14"
},
{
range_name = "gke-cluster-services"
ip_cidr_range = "10.192.0.0/20" },
]
}
}
我想将两个二级范围的range_name
的值相应地暴露为ip_range_pods_gke
和ip_range_ser_gke
。那么我的输出。Tf文件看起来像这样:
output "ip_range_pods_gke" {
description = "GKE PODs IP ranage."
value = module.test-vpc-module.secondary_ranges.us-central1-gke[0].range_name
}
output "ip_range_services_gke" {
description = "GKE Services IP ranage."
value = module.test-vpc-module.secondary_ranges.us-central1-gke[1].range_name
}
我的主。
module "networking"{
source = "./network"
project_id = "xxxxx-project"
network_name = "xxxxx"
}
然而,当我运行plan
命令时,我得到以下错误:
Error: Unsupported attribute
│
│ on network/outputs.tf line 4, in output "ip_range_pods_gke":
│ 4: value = module.test-vpc-module.secondary_ranges.us-central1-gke[0].range_name
│ ├────────────────
│ │ module.test-vpc-module is a object, known only after apply
│
│ This object does not have an attribute named "secondary_ranges".
为每个secondary_ranges公开range_name的正确方法是什么?
更新:我的文件夹结构看起来像这样(我知道状态文件应该在桶中,但这只是测试):
├── main.tf
├── network
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── terraform.tfstate
└── terraform.tfstate.backup
terraform-google-modules/network/google没有secondary_ranges
这样的输出。相反,您可能需要的输出称为subnets_secondary_ranges。
如果这不是你想要的输出,你必须派生模块,并修改它的输出。