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

thankful-table-80113

02/01/2022, 2:23 PM
what’s up fellas, how’s everyone holding up? wondering how do i get the current provider info on code but i can’t seem to find, anyone knows? i need the current GCP project i’m operating on
p

prehistoric-activity-61023

02/01/2022, 2:30 PM
I was able to get that info in one of my project and it didn’t look good
let me find it
within
ComponentResource
in python I was able to extract current
gcp
provider using the following snippet:
Copy code
# get config from GCP provider assigned to this resource
        gcp_provider = cast(gcp.Provider, self.get_provider("gcp::"))
        gcp_project = gcp_provider.project
        gcp_region = gcp_provider.region
        gcp_zone = gcp_provider.zone
t

thankful-table-80113

02/01/2022, 2:52 PM
hmmmm, seems pretty much it, let me try 👀
p

prehistoric-activity-61023

02/01/2022, 2:59 PM
I don’t have access to golang env right now so I cannot test it
I guess you might have some issues if you want to execute that outside of component resource
in that case, I’d try to acquire reference to RootResource
o

orange-policeman-59119

02/01/2022, 5:31 PM
Is the GCP project set in your stack config? If so, there is a way to get the provider's config in a straightforward fashion.
p

prehistoric-activity-61023

02/01/2022, 5:56 PM
^+1 for the suggestion; I remember now that I did that the hard way in order to create a reusable ComponentResource that dynamically reads the data from its provider (and it could be set implicitly using pulumi ResourceOptions or inherited from the parent or the default one)
@orange-policeman-59119 Did you mean simply reading the config value of
gcp
module like this?
Copy code
gcp_project = pulumi.Config("gcp").get("project")
👍 1
o

orange-policeman-59119

02/01/2022, 6:00 PM
correct
t

thankful-table-80113

02/01/2022, 6:11 PM
perfect, not exactly this but it did great to get there:
Copy code
project := config.Get(ctx, "gcp:project")
thanks a ton fellas 🤩