pulumi_wasm_providers_gcp_mini::compute

Module network_attachment

source
Expand description

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

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let acceptedProducerProject = project::create(
        "acceptedProducerProject",
        ProjectArgs::builder()
            .billing_account("000000-0000000-0000000-000000")
            .deletion_policy("DELETE")
            .name("prj-accepted")
            .org_id("123456789")
            .project_id("prj-accepted")
            .build_struct(),
    );
    let default = network_attachment::create(
        "default",
        NetworkAttachmentArgs::builder()
            .connection_preference("ACCEPT_MANUAL")
            .description("basic network attachment description")
            .name("basic-network-attachment")
            .producer_accept_lists(vec!["${acceptedProducerProject.projectId}",])
            .producer_reject_lists(vec!["${rejectedProducerProject.projectId}",])
            .region("us-central1")
            .subnetworks(vec!["${defaultSubnetwork.selfLink}",])
            .build_struct(),
    );
    let defaultNetwork = network::create(
        "defaultNetwork",
        NetworkArgs::builder()
            .auto_create_subnetworks(false)
            .name("basic-network")
            .build_struct(),
    );
    let defaultSubnetwork = subnetwork::create(
        "defaultSubnetwork",
        SubnetworkArgs::builder()
            .ip_cidr_range("10.0.0.0/16")
            .name("basic-subnetwork")
            .network("${defaultNetwork.id}")
            .region("us-central1")
            .build_struct(),
    );
    let rejectedProducerProject = project::create(
        "rejectedProducerProject",
        ProjectArgs::builder()
            .billing_account("000000-0000000-0000000-000000")
            .deletion_policy("DELETE")
            .name("prj-rejected")
            .org_id("123456789")
            .project_id("prj-rejected")
            .build_struct(),
    );
}

§Network Attachment Instance Usage

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = network::create(
        "default",
        NetworkArgs::builder()
            .auto_create_subnetworks(false)
            .name("basic-network")
            .build_struct(),
    );
    let defaultInstance = instance::create(
        "defaultInstance",
        InstanceArgs::builder()
            .boot_disk(
                InstanceBootDisk::builder()
                    .initializeParams(
                        InstanceBootDiskInitializeParams::builder()
                            .image("debian-cloud/debian-11")
                            .build_struct(),
                    )
                    .build_struct(),
            )
            .machine_type("e2-micro")
            .name("basic-instance")
            .network_interfaces(
                vec![
                    InstanceNetworkInterface::builder().network("default")
                    .build_struct(), InstanceNetworkInterface::builder()
                    .networkAttachment("${defaultNetworkAttachment.selfLink}")
                    .build_struct(),
                ],
            )
            .zone("us-central1-a")
            .build_struct(),
    );
    let defaultNetworkAttachment = network_attachment::create(
        "defaultNetworkAttachment",
        NetworkAttachmentArgs::builder()
            .connection_preference("ACCEPT_AUTOMATIC")
            .description("my basic network attachment")
            .name("basic-network-attachment")
            .region("us-central1")
            .subnetworks(vec!["${defaultSubnetwork.id}",])
            .build_struct(),
    );
    let defaultSubnetwork = subnetwork::create(
        "defaultSubnetwork",
        SubnetworkArgs::builder()
            .ip_cidr_range("10.0.0.0/16")
            .name("basic-subnetwork")
            .network("${default.id}")
            .region("us-central1")
            .build_struct(),
    );
}

§Import

NetworkAttachment can be imported using any of these accepted formats:

  • projects/{{project}}/regions/{{region}}/networkAttachments/{{name}}

  • {{project}}/{{region}}/{{name}}

  • {{region}}/{{name}}

  • {{name}}

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

$ pulumi import gcp:compute/networkAttachment:NetworkAttachment default projects/{{project}}/regions/{{region}}/networkAttachments/{{name}}
$ pulumi import gcp:compute/networkAttachment:NetworkAttachment default {{project}}/{{region}}/{{name}}
$ pulumi import gcp:compute/networkAttachment:NetworkAttachment default {{region}}/{{name}}
$ pulumi import gcp:compute/networkAttachment:NetworkAttachment default {{name}}

Structs§

Functions§

  • Registers a new resource with the given unique name and arguments