Google compute engine 由模块创建的所有实例的列表
我有许多模块调用,看起来与此类似Google compute engine 由模块创建的所有实例的列表,google-compute-engine,terraform,Google Compute Engine,Terraform,我有许多模块调用,看起来与此类似 1 module "gcpue4a1" { 2 source = "../../../modules/pods" 3 4 } 模块正在创建实例、DNS记录等的位置 locals { gateway_name = "gateway-${var.network_zone}-${var.environment}-1" } resource "google_compute_instance" "gateway" { name
1 module "gcpue4a1" {
2 source = "../../../modules/pods"
3
4 }
模块正在创建实例、DNS记录等的位置
locals {
gateway_name = "gateway-${var.network_zone}-${var.environment}-1"
}
resource "google_compute_instance" "gateway" {
name = "${local.gateway_name}"
machine_type = "n1-standard-8"
zone = "${var.zone}"
allow_stopping_for_update = true
}
如何迭代通过此模块创建的所有实例的列表。我可以使用实例标记或标签吗
最后,我想要的是能够遍历一个列表以导出到ansible库存文件。但当我的资源被封装在模块中时,我不知道如何做到这一点
通过terraform show,我可以清楚地看到变量的结构
➜ gcp-us-east4 git:(integration) ✗ terraform show | grep google_compute_instance.gateway -n1
640- zone = us-east4-a
641:module.screencast-gcp-pod-gcpue4a1-food.google_compute_instance.gateway:
642- id = gateway-gcpue4a1-food-1
--
--
991- zone = us-east4-a
992:module.screencast-gcp-pod-gcpue4a2-food.google_compute_instance.gateway:
993- id = gateway-gcpue4a2-food-1
--
--
1342- zone = us-east4-a
1343:module.screencast-gcp-pod-gcpue4a3-food.google_compute_instance.gateway:
1344- id = gateway-gcpue4a3-food-1
--
--
1693- zone = us-east4-a
1694:module.screencast-gcp-pod-gcpue4a4-food.google_compute_instance.gateway:
1695- id = gateway-gcpue4a4-food-1
当我明确地说出我想要哪个节点时,etcd清单工作得很好。下面的整体库存没有,我不知道如何修复它
10 ##Create ETCD Inventory
11 provisioner "local-exec" {
12 command = "echo \"\n[etcd]\n${google_compute_instance.k8s-master.name} ansible_s sh_host=${google_compute_instance.k8s-master.network_interface.0.address}\" >> kubesp ray-inventory"
13 }
14
15 ##Create Nodes Inventory
16 provisioner "local-exec" {
17 command = "echo \"\n[kube-node]\" >> kubespray-inventory"
18 }
19 # provisioner "local-exec" {
20 # command = "echo \"${join("\n",formatlist("%s ansible_ssh_host=%s", google_compu te_instance.gateway.*.name, google_compute_instance.gateway.*.network_interface.0.add ress))}\" >> kubespray-inventory"
21 # }
➜ gcp-us-east4 git:(integration) ✗ terraform apply
Error: resource 'null_resource.ansible-provision' provisioner local-exec (#4): unknown resource 'google_compute_instance.gateway' referenced in variable google_compute_instance.gateway.*.id
您可以确保每个模块都添加了与该模块匹配的 然后,您可以使用并使用过滤器仅显示具有特定标签的标签