简体   繁体   English

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

[英]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.

相关问题 使用 GCP terraform 将域名附加到私有内部 IP - Attach Domain Name to private internal IP with GCP terraform 为 terraform 中的 ec2 实例分配固定私有 IP - Assign fixed private IP for ec2 instance in terraform 如何找到私有区域中托管的 GCP Cloud DNS 服务器的内部 IP 地址 - How to find the Internal IP Address of GCP Cloud DNS server hosted in Private Zone Terraform GCP 中的文件布局 - Terraform File Layout in GCP 如何动态获取terraform中创建的rds实例的server IP - how to dynamically get the server IP of rds instance created in terraform Terraform - GCP 在 google_compute_vpn_gateway 上添加 IP 部分 - Terraform - GCP adding IP section on google_compute_vpn_gateway 我想使用 terraform 在 GCP 中创建公共和私有 Su.net - I want to create Public and Private Subnet in GCP using terraform 如何从 Terraform 中的 GCP 集群中删除外部 IP - How to remove external IP from GCP cluster in Terraform 使用 Terraform 将文件传递给新创建的 ec2 实例,而不共享“连接”部分中的私钥 - using Terraform to pass a file to newly created ec2 instance without sharing the private key in "connection" section 如何使用 terraform 将 ssh 密钥添加到 GCP 实例? - How to add an ssh key to an GCP instance using terraform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM