简体   繁体   中英

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.

Any suggestion or thoughts on this one?

Thank you in advance.

You might like to check how terraform works with an IP address resource

A particulare example (from the top of my head, assuming that the su.network ( my_su.net ) is created in the same terraform batch):

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM