Google Compute Engine Global Address

This page shows how to write Terraform for Compute Engine Global Address and write them securely.

google_compute_global_address (Terraform)

The Global Address in Compute Engine can be configured in Terraform with the resource name google_compute_global_address. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

optional.tf#L21
resource "google_compute_global_address" "development-ingress" {
  count       = var.ingress-ip-addresses == true ? 1 : 0
  name        = "dev-ingress-ip"
  description = "IP Address for development environment's k8s Ingress"
}

networking.tf#L1
resource "google_compute_global_address" "k8s-ingress" {
  name = "k8s-ingress"
}

resource "google_compute_network" "default" {
  auto_create_subnetworks = true
addresses.tf#L1
resource "google_compute_global_address" "loadbalance-staging" {
  name         = "loadbalance-staging"
  address      = "34.107.213.88"
  address_type = "EXTERNAL"
}

publicip.tf#L1
resource "google_compute_global_address" "master" {
  name         = var.master_publicip_name
  ip_version   = "IPV4"
  address_type = "EXTERNAL"
}

main.tf#L2
resource "google_compute_global_address" "tfg_uoc_app_devel_ip_address" {
  name        = "tfg-uoc-app-devel-ip"
  description = "Adreça IP reservada pel balancejador de l'entorn devel"
}

# Creem una reserva d'IP estàtica per l'entorn de producció

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The IP address or beginning of the address range represented by this resource. This can be supplied as an input to reserve a specific address or omitted to allow GCP to choose a valid one for you.

The type of the address to reserve. EXTERNAL indicates public/external single IP address. INTERNAL indicates internal IP ranges belonging to some network. Default value: "EXTERNAL" Possible values: ["EXTERNAL", "INTERNAL"]

Creation timestamp in RFC3339 text format.

An optional description of this resource.

The IP Version that will be used by this address. The default value is 'IPV4'. Possible values: ["IPV4", "IPV6"]

Name of the resource. Provided by the client when the resource is created. 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 'a-z?' 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.

The URL of the network in which to reserve the IP range. The IP range must be in RFC1918 space. The network cannot be deleted if there are any reserved IP ranges referring to it. This should only be set when using an Internal address.

The prefix length of the IP range. If not present, it means the address field is a single IP address. This field is not applicable to addresses with addressType=EXTERNAL, or addressType=INTERNAL when purpose=PRIVATE_SERVICE_CONNECT

The purpose of the resource. Possible values include: VPC_PEERING - for peer networks PRIVATE_SERVICE_CONNECT - for (Beta only) Private Service Connect networks

Explanation in Terraform Registry

Represents a Global Address resource. Global addresses are used for HTTP(S) load balancing. To get more information about GlobalAddress, see:

Tips: Best Practices for The Other Google Compute Engine Resources

In addition to the google_compute_disk, Google Compute Engine has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

google_compute_disk

Ensure the encryption key for your GCE disk is stored securely

It is better to store the encryption key for your GCE disk securely. Secret Manager could be used instead.

risk-label

google_compute_firewall

Ensure your VPC firewall blocks unwanted outbound traffic

It is better to block unwanted outbound traffic not to expose resources in the VPC to unwanted attacks.

risk-label

google_compute_instance

Ensure appropriate service account is assigned to your GCE instance

It is better to create a custom service account for the instance and assign it.

risk-label

google_compute_project_metadata

Ensure OS login for your GCE instances is enabled at project level

It is better to enable OS login for your GCE instances. Enabling OS login ensures that SSH keys used to connect to instances are mapped with IAM users, allowing centralized and automated SSH key management.

risk-label

google_compute_ssl_policy

Ensure to use modern TLS protocols

It's better to adopt TLS v1.2+ instead of outdated TLS protocols.

risk-label

google_compute_subnetwork

Ensure VPC flow logging is enabled

It is better to enable VPC flow logging. VPC flow logging allows us to audit traffic in your network.

Review your Google Compute Engine settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Frequently asked questions

What is Google Compute Engine Global Address?

Google Compute Engine Global Address is a resource for Compute Engine of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Compute Engine Global Address?

For Terraform, the chris-ingrisani/terraform-google-securing-shift-left, ulamlabs/gcp-terraform-starter and epidemics/infra source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.