Terraform gcp获取实例的内部私有ip并写入文件



工作在以下示例github上,我试图添加一个静态内部ip值到terraform(因此实例将使用特定的内部ip运行)或至少获得实例的内部ip,以便我可以将其写入实例的内部文件。

有什么建议或想法吗?

提前谢谢你。

您可能想检查terraform如何使用IP地址资源

一个特殊的例子(从我的脑海中,假设子网(my_subnet)是在相同的地形批处理中创建的):

resource "google_compute_address" "my_internal_ip_addr" {
project      = "my_target_project_id"
address_type = "INTERNAL"
region       = "my_region"
subnetwork   = data.google_compute_subnetwork.my_subnet.name
name         = "my_ip_address_name"
description  = "An internal IP address for my VM"
}

对于计算引擎(仅相关元素):

resource "google_compute_instance" "my_vm" {
project      = "my_target_project_id"
name         = "my_vm"
# other items omitted
network_interface {
subnetwork         = data.google_compute_subnetwork.my_subnet.name
subnetwork_project = "my_target_project_id"
network_ip         = google_compute_address.my_internal_ip_addr.address
access_config {
# Include this section to give the VM an external IP address
}
}
# other items omitted
}

然而,我不知道以上是否能帮助你满足你对i can write it in the internal file of the instance的最终要求,以及你为什么需要它。

最新更新