Skip to content

googleComputeAddress

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:

Example Usage - Address Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeAddress.ComputeAddress(this, "ip_address", {
  name: "my-address",
});

Example Usage - Address With Subnetwork

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeNetworkDefault = new google.computeNetwork.ComputeNetwork(
  this,
  "default",
  {
    name: "my-network",
  }
);
const googleComputeSubnetworkDefault =
  new google.computeSubnetwork.ComputeSubnetwork(this, "default_1", {
    ip_cidr_range: "10.0.0.0/16",
    name: "my-subnet",
    network: googleComputeNetworkDefault.id,
    region: "us-central1",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeSubnetworkDefault.overrideLogicalId("default");
new google.computeAddress.ComputeAddress(
  this,
  "internal_with_subnet_and_address",
  {
    address: "10.0.42.42",
    address_type: "INTERNAL",
    name: "my-internal-address",
    region: "us-central1",
    subnetwork: googleComputeSubnetworkDefault.id,
  }
);

Example Usage - Address With Gce Endpoint

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeAddress.ComputeAddress(this, "internal_with_gce_endpoint", {
  address_type: "INTERNAL",
  name: "my-internal-address-",
  purpose: "GCE_ENDPOINT",
});

Example Usage - Instance With Ip

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeAddressStatic = new google.computeAddress.ComputeAddress(
  this,
  "static",
  {
    name: "ipv4-address",
  }
);
const dataGoogleComputeImageDebianImage =
  new google.dataGoogleComputeImage.DataGoogleComputeImage(
    this,
    "debian_image",
    {
      family: "debian-11",
      project: "debian-cloud",
    }
  );
new google.computeInstance.ComputeInstance(this, "instance_with_ip", {
  boot_disk: [
    {
      initialize_params: [
        {
          image: dataGoogleComputeImageDebianImage.selfLink,
        },
      ],
    },
  ],
  machine_type: "f1-micro",
  name: "vm-instance",
  network_interface: [
    {
      access_config: [
        {
          nat_ip: googleComputeAddressStatic.address,
        },
      ],
      network: "default",
    },
  ],
  zone: "us-central1-a",
});

Example Usage - Compute Address Ipsec Interconnect

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeNetworkNetwork = new google.computeNetwork.ComputeNetwork(
  this,
  "network",
  {
    auto_create_subnetworks: false,
    name: "test-network",
  }
);
new google.computeAddress.ComputeAddress(this, "ipsec-interconnect-address", {
  address: "192.168.1.0",
  address_type: "INTERNAL",
  name: "test-address",
  network: googleComputeNetworkNetwork.selfLink,
  prefix_length: 29,
  purpose: "IPSEC_INTERCONNECT",
});

Argument Reference

The following arguments are supported:

  • name - (Required) Name of the resource. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [aZ]([AZ09]*[aZ09])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

  • address - (Optional) The static external IP address represented by this resource. Only IPv4 is supported. An address may only be specified for INTERNAL address types. The IP address must be inside the specified subnetwork, if any. Set by the API if undefined.

  • addressType - (Optional) The type of address to reserve. Note: if you set this argument's value as internal you need to leave the networkTier argument unset in that resource block. Default value is external. Possible values are internal and external.

  • description - (Optional) An optional description of this resource.

  • purpose - (Optional) The purpose of this resource, which can be one of the following values.

    • GCE_ENDPOINT for addresses that are used by VM instances, alias IP ranges, load balancers, and similar resources.
    • SHARED_LOADBALANCER_VIP for an address that can be used by multiple internal load balancers.
    • VPC_PEERING for addresses that are reserved for VPC peer networks.
    • IPSEC_INTERCONNECT for addresses created from a private IP range that are reserved for a VLAN attachment in an HA VPN over Cloud Interconnect configuration. These addresses are regional resources.
    • PRIVATE_SERVICE_CONNECT for a private network address that is used to configure Private Service Connect. Only global internal addresses can use this purpose.

    This should only be set when using an Internal address.

  • networkTier - (Optional) The networking tier used for configuring this address. If this field is not specified, it is assumed to be PREMIUM. This argument should not be used when configuring Internal addresses, because network tier cannot be set for internal traffic; it's always Premium. Possible values are premium and standard.

  • subnetwork - (Optional) The URL of the subnetwork in which to reserve the address. If an IP address is specified, it must be within the subnetwork's IP range. This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER purposes.

  • labels - (Optional, Beta) Labels to apply to this address. A list of key->value pairs.

  • network - (Optional) The URL of the network in which to reserve the address. This field can only be used with INTERNAL type with the VPC_PEERING and IPSEC_INTERCONNECT purposes.

  • prefixLength - (Optional) The prefix length if the resource represents an IP range.

  • region - (Optional) The Region in which the created address should reside. If it is not provided, the provider region is used.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Attributes Reference

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

  • id - an identifier for the resource with format projects/{{project}}/regions/{{region}}/addresses/{{name}}

  • creationTimestamp - Creation timestamp in RFC3339 text format.

  • users - The URLs of the resources that are using this address.

  • labelFingerprint - (Beta) The fingerprint used for optimistic locking of this resource. Used internally during updates.

  • selfLink - The URI of the created resource.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

Address can be imported using any of these accepted formats:

$ 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.