google_compute_address

Represents an Address resource.

Each virtual machine instance has an ephemeral internal IP address and, optionally, an external IP address. To communicate between instances on the same network, you can use an instance's internal IP address. To communicate with the Internet and instances outside of the same network, you must specify the instance's external IP address.

Internal IP addresses are ephemeral and only belong to an instance for the lifetime of the instance; if the instance is deleted and recreated, the instance is assigned a new internal IP address, either by Compute Engine or by you. External IP addresses can be either ephemeral or static.

To get more information about Address, see:

Open in Cloud Shell

Example Usage - Address Basic

resource "google_compute_address" "ip_address" {
  name = "my-address"
}
Open in Cloud Shell

Example Usage - Address With Subnetwork

resource "google_compute_network" "default" {
  name = "my-network"
}

resource "google_compute_subnetwork" "default" {
  name          = "my-subnet"
  ip_cidr_range = "10.0.0.0/16"
  region        = "us-central1"
  network       = google_compute_network.default.id
}

resource "google_compute_address" "internal_with_subnet_and_address" {
  name         = "my-internal-address"
  subnetwork   = google_compute_subnetwork.default.id
  address_type = "INTERNAL"
  address      = "10.0.42.42"
  region       = "us-central1"
}
Open in Cloud Shell

Example Usage - Address With Gce Endpoint

resource "google_compute_address" "internal_with_gce_endpoint" {
  name         = "my-internal-address-"
  address_type = "INTERNAL"
  purpose      = "GCE_ENDPOINT"
}
Open in Cloud Shell

Example Usage - Instance With Ip

resource "google_compute_address" "static" {
  name = "ipv4-address"
}

data "google_compute_image" "debian_image" {
  family  = "debian-11"
  project = "debian-cloud"
}

resource "google_compute_instance" "instance_with_ip" {
  name         = "vm-instance"
  machine_type = "f1-micro"
  zone         = "us-central1-a"

  boot_disk {
    initialize_params {
      image = data.google_compute_image.debian_image.self_link
    }
  }

  network_interface {
    network = "default"
    access_config {
      nat_ip = google_compute_address.static.address
    }
  }
}
Open in Cloud Shell

Example Usage - Compute Address Ipsec Interconnect

resource "google_compute_address" "ipsec-interconnect-address" {
  name          = "test-address"
  address_type  = "INTERNAL"
  purpose       = "IPSEC_INTERCONNECT"
  address       = "192.168.1.0"
  prefix_length = 29
  network       = google_compute_network.network.self_link
}

resource "google_compute_network" "network" {
  name                    = "test-network"
  auto_create_subnetworks = false
}

Argument Reference

The following arguments are supported:


Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Address can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Address using one of the formats above. For example:

import {
  id = "projects/{{project}}/regions/{{region}}/addresses/{{name}}"
  to = google_compute_address.default
}

When using the terraform import command, Address can be imported using one of the formats above. For example:

$ terraform import google_compute_address.default projects/{{project}}/regions/{{region}}/addresses/{{name}}
$ terraform import google_compute_address.default {{project}}/{{region}}/{{name}}
$ terraform import google_compute_address.default {{region}}/{{name}}
$ terraform import google_compute_address.default {{name}}

User Project Overrides

This resource supports User Project Overrides.