google_compute_network_attachment

A network attachment is a resource that lets a producer Virtual Private Cloud (VPC) network initiate connections to a consumer VPC network through a Private Service Connect interface.

To get more information about NetworkAttachment, see:

Example Usage - Network Attachment Basic

resource "google_compute_network_attachment" "default" {
    provider = google-beta
    name = "basic-network-attachment"
    region = "us-central1"
    description = "basic network attachment description"
    connection_preference = "ACCEPT_MANUAL"

    subnetworks = [
        google_compute_subnetwork.default.self_link
    ]

    producer_accept_lists = [
        google_project.accepted_producer_project.project_id
    ]

    producer_reject_lists = [
        google_project.rejected_producer_project.project_id
    ]
}

resource "google_compute_network" "default" {
    provider = google-beta
    name = "basic-network"
    auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "default" {
    provider = google-beta
    name = "basic-subnetwork"
    region = "us-central1"

    network = google_compute_network.default.id
    ip_cidr_range = "10.0.0.0/16"
}

resource "google_project" "rejected_producer_project" {
    provider = google-beta
    project_id      = "prj-rejected"
    name            = "prj-rejected"
    org_id          = "123456789"
    billing_account = "000000-0000000-0000000-000000"
}

resource "google_project" "accepted_producer_project" {
    provider = google-beta
    project_id      = "prj-accepted"
    name            = "prj-accepted"
    org_id          = "123456789"
    billing_account = "000000-0000000-0000000-000000"
}
Open in Cloud Shell

Example Usage - Network Attachment Instance Usage

resource "google_compute_network" "default" {
    provider = google-beta
    name = "basic-network"
    auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "default" {
    provider = google-beta
    name   = "basic-subnetwork"
    region = "us-central1"

    network       = google_compute_network.default.id
    ip_cidr_range = "10.0.0.0/16"
}

resource "google_compute_network_attachment" "default" {
    provider = google-beta
    name   = "basic-network-attachment"
    region = "us-central1"
    description = "my basic network attachment"

    subnetworks = [google_compute_subnetwork.default.id]
    connection_preference = "ACCEPT_AUTOMATIC"
}

resource "google_compute_instance" "default" {
    provider = google-beta
    name         = "basic-instance"
    zone         = "us-central1-a"
    machine_type = "e2-micro"

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

    network_interface {
        network = "default"
    }

    network_interface {
        network_attachment = google_compute_network_attachment.default.self_link
    }
}

Argument Reference

The following arguments are supported:


Attributes Reference

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

The connection_endpoints block contains:

Timeouts

This resource provides the following Timeouts configuration options:

Import

NetworkAttachment can be imported using any of these accepted formats:

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

import {
  id = "projects/{{project}}/regions/{{region}}/networkAttachments/{{name}}"
  to = google_compute_network_attachment.default
}

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

$ terraform import google_compute_network_attachment.default projects/{{project}}/regions/{{region}}/networkAttachments/{{name}}
$ terraform import google_compute_network_attachment.default {{project}}/{{region}}/{{name}}
$ terraform import google_compute_network_attachment.default {{region}}/{{name}}
$ terraform import google_compute_network_attachment.default {{name}}

User Project Overrides

This resource supports User Project Overrides.