TheOne745665
TheOne745665

Reputation: 437

Terraform - GCP create instance with static IP

struggling to create a gcp instance with a static IP assigned. I can create them both separately, it's just creating it and having the VM use it.

    resource "google_compute_address" "static_ip" {
  name = "terraform-static-ip"
}


resource "google_compute_instance" "vm_instance" {
  name         = "terraform-instance"
  machine_type = "f1-micro"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    network = google_compute_network.vpc_network.name
    access_config {
        nat_ip = "google_compute_address.terraform-static-ip.address"
    }
  }
}

Getting this error

Error: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.networkInterfaces[0].accessConfigs[0].natIP': 'google_compute_address.static.address'. The specified external IP address 'google_compute_address.static.address' was not found in region 'us-central1'., invalid

Anyone know what i am doing wrong.

I found this thread- How to map static IP to terraform google compute engine instance?

But neither solution worked for me.

Upvotes: 0

Views: 1834

Answers (1)

TSF
TSF

Reputation: 36

you have a typo in

access_config {
    nat_ip = "google_compute_address.terraform-static-ip.address"
}

What you want that line to be is

access_config {
    nat_ip = "google_compute_address.static-ip.address"
}

because you have the google_compute_address resource name as static-ip

Upvotes: 2

Related Questions