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

average-plastic-1653

09/15/2023, 2:31 PM
Does anyone have a working code example to configure a peered VPC Network? using gpc.compute.NetworkPeering My use case is I am peering with another GCP project (in this case an Aiven.io VPC) and have it working via the GCP Console, so I know it works.
s

stocky-restaurant-98004

09/15/2023, 2:36 PM
If you're not able to find an example, there's a couple of options: 1. You can try
pulumi import
in an empty project, get the generated code, and then delete the state file (without deleting the resources, of course!) 2. Ask Pulumi AI: https://www.pulumi.com/ai
a

average-plastic-1653

09/15/2023, 3:48 PM
I have not used the import capability yet; thanks!
s

stocky-restaurant-98004

09/15/2023, 5:27 PM
Check out this blog post. It'll show you how to grab everything in your Google Cloud environment via Config Connector. You might not even need to actually import to Pulumi - viewing the attribs in a K8s resource might be sufficient to figure it out. https://www.pulumi.com/blog/google-cloud-pulumi-import-account-scraper/
a

average-plastic-1653

09/15/2023, 5:37 PM
thanks @stocky-restaurant-98004
I got this working:
Copy code
pulumi import  gcp:compute/networkPeering:NetworkPeering mypeer ir-dryrun/default/aiven-jmtest-01
Took me quite a bit of time to work out the resource naming
s

stocky-restaurant-98004

09/15/2023, 5:41 PM
Getting the ID, you mean? (Last param above.)
a

average-plastic-1653

09/15/2023, 5:42 PM
working out: gcpcompute/networkPeeringNetworkPeering
s

stocky-restaurant-98004

09/15/2023, 5:43 PM
Was that because you couldn't figure out the name of the resource, or how to type out the resource type?
a

average-plastic-1653

09/15/2023, 5:43 PM
thats my lack of knowledge LOL
type out the resource type
s

stocky-restaurant-98004

09/15/2023, 5:43 PM
FYI, most resources have a block in their API page that tells you how to import: https://www.pulumi.com/registry/packages/gcp/api-docs/compute/networkpeering/#import
a

average-plastic-1653

09/15/2023, 5:44 PM
😞
thanks! I didnt see that
s

stocky-restaurant-98004

09/15/2023, 5:44 PM
If there's something we can do to make that more obvious, please let me know.
a

average-plastic-1653

09/15/2023, 5:45 PM
oh my, I didnt scroll down enough
i'm fairly new to the Pulumi ecosystem and documentation
s

stocky-restaurant-98004

09/15/2023, 5:46 PM
Pulumi is a very capable, but complex product with a huge surface area (by necessity), and I personally hate to see people get hung up on "first time doing something" (because I hate that experience myself), so again - if there's a place where you would've caught it, and saved yourself some pain, please let us know!
a

average-plastic-1653

09/15/2023, 5:46 PM
will do!
now that I have you here...I do have a question
I get this back:
Copy code
+ mypeer.network     : "<https://www.googleapis.com/compute/v1/projects/ir-dryrun/global/networks/default>"
  + mypeer.peer_network: "<https://www.googleapis.com/compute/beta/projects/aiven-prod-idcn/global/networks/aivenprod-a173e186-36b5-4ab7-969a-3455394a19e2>"
s

stocky-restaurant-98004

09/15/2023, 5:46 PM
BTW, not every resource has "import" documented. In most cases, we would consider this a bug, so please report it as such.
a

average-plastic-1653

09/15/2023, 5:48 PM
is there way to programmatically get the network urls or parts of them? I dont really want to have to craft the urls like: "https://www.googleapis.com/compute/v1/projects/" + project.project_name + "global/networks/default"
s

stocky-restaurant-98004

09/15/2023, 5:48 PM
What's the context of that output above?
Like, what did you run to see that output?
a

average-plastic-1653

09/15/2023, 5:49 PM
pulumi.export("mypeer.network",mypeer.network) pulumi.export("mypeer.peer_network",mypeer.peer_network)
s

stocky-restaurant-98004

09/15/2023, 5:51 PM
I think you'd just drop down to string parsing using regular ol' Python.
If you you want to work with
Output[str]
, the
pulumi
Python SDK has helper methods to do this. Alternatively, you can use
apply
, e.g.:
Copy code
def get_url_good_part(full_url: str):
  # do stuff

some_regular_string = resource.some_str_output.apply(get_url_good_part)
Of course, you can also do
apply(lambda some_str: )
if you can fit it on one line.
Pulumi SDK methods can be found here: https://www.pulumi.com/docs/concepts/inputs-outputs/
a

average-plastic-1653

09/15/2023, 5:59 PM
thanks!
Thanks for the help @stocky-restaurant-98004