Does anyone have a working code example to configu...
# google-cloud
a
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
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
I have not used the import capability yet; thanks!
s
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
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
Getting the ID, you mean? (Last param above.)
a
working out: gcpcompute/networkPeeringNetworkPeering
s
Was that because you couldn't figure out the name of the resource, or how to type out the resource type?
a
thats my lack of knowledge LOL
type out the resource type
s
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
😞
thanks! I didnt see that
s
If there's something we can do to make that more obvious, please let me know.
a
oh my, I didnt scroll down enough
i'm fairly new to the Pulumi ecosystem and documentation
s
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
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
BTW, not every resource has "import" documented. In most cases, we would consider this a bug, so please report it as such.
a
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
What's the context of that output above?
Like, what did you run to see that output?
a
pulumi.export("mypeer.network",mypeer.network) pulumi.export("mypeer.peer_network",mypeer.peer_network)
s
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
thanks!
Thanks for the help @stocky-restaurant-98004