https://pulumi.com logo
#google-cloud
Title
# google-cloud
s

some-xylophone-39695

01/24/2020, 3:48 AM
There is an example in terraform, but I have no clue how to do it in Pulumi.
g

gentle-diamond-70147

01/24/2020, 4:07 PM
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

some-xylophone-39695

01/24/2020, 5:20 PM
@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

gentle-diamond-70147

01/24/2020, 5:22 PM
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

some-xylophone-39695

01/24/2020, 5:23 PM
ok. what if i want to reference an existing resource? that isn't managed by pulumi
g

gentle-diamond-70147

01/24/2020, 5:23 PM
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

some-xylophone-39695

01/24/2020, 5:24 PM
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

gentle-diamond-70147

01/24/2020, 5:35 PM
Yep, that's how.
2 Views