[英]Terraform gcp get internal private ip of instance and write to file
Working on the following example github i am trying to add a static internal ip value to terraform ( so instance will run with specific internal ip ) or at least get the internal ip of the instance so i can write it in the internal file of the instance.处理以下示例github我正在尝试将 static 内部 ip 值添加到 terraform(因此实例将使用特定的内部 ip 运行)或至少获取内部 ip 实例的内部文件,以便我可以将其写入实例的内部文件.
Any suggestion or thoughts on this one?对此有什么建议或想法吗?
Thank you in advance.先感谢您。
You might like to check how terraform works with an IP address resource您可能想检查 terraform 如何与IP 地址资源一起使用
A particulare example (from the top of my head, assuming that the su.network ( my_su.net
) is created in the same terraform batch):一个特殊的例子(从我的头顶开始,假设 su.network (
my_su.net
) 是在同一个 terraform 批次中创建的):
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"
}
and for a compute engine (ony relevant elements):对于计算引擎(任何相关元素):
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
}
However, I don't know if the above can help you with your ultimate requirement to i can write it in the internal file of the instance
and why you need that.但是,我不知道以上是否可以帮助您满足您的最终要求,
i can write it in the internal file of the instance
以及您为什么需要它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.