There is an example in terraform, but I have no cl...
# google-cloud
s
There is an example in terraform, but I have no clue how to do it in Pulumi.
g
The resources and resource arguments map from Terraform to Pulumi really closely. Here's a "port" of the private IP example from the Terraform docs:
Copy code
import * as gcp from "@pulumi/gcp";

const privateNetwork = new gcp.compute.Network("private");

const privateIpAddress = new gcp.compute.GlobalAddress("private", {
    network: privateNetwork.selfLink,
    purpose: "VPC_PEERING",
    addressType: "INTERNAL",
    prefixLength: 16,
});

const privateVpcConnection = new gcp.servicenetworking.Connection("private", {
    network: privateNetwork.selfLink,
    service: "<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>",
    reservedPeeringRanges: [privateIpAddress.name],
});

const instance = new gcp.sql.DatabaseInstance("private", {
    region: "us-central1",
    settings: {
        tier: "db-f1-micro",
        ipConfiguration: {
            ipv4Enabled: false,
            privateNetwork: privateNetwork.selfLink,
        }
    }
}, { dependsOn: privateVpcConnection })
s
@gentle-diamond-70147 we already have a VPC named
hq
would i just use
const privateNetwork = new gcp.computer.Network("hq")
?
i would really like to avoid a situation where i end up destroying our existing
hq
VPC when I issue a
pulumi destroy
g
Any time you do
... new <resource>
in Pulumi, Pulumi will create that resource and then manage it going forward. So you can create any number of new resources with Pulumi and it will not interfere or touch your existing resources.
s
ok. what if i want to reference an existing resource? that isn't managed by pulumi
g
If you want to use your existing VPC named
hq
you would remove the
const privateNetwork = new gcp.computer.Network("hq")
part (as that will create a new network), and pass the self link value of your
hq
network in its place.
s
i suppose i'm confused as to how i would get a reference to the existing network
ah. using python
Copy code
private_network = Network.get('hq-vpc', id='hq')
g
Yep, that's how.