what’s up fellas, how’s everyone holding up? wonde...
# google-cloud
t
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
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
hmmmm, seems pretty much it, let me try 👀
p
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
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
^+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
correct
t
perfect, not exactly this but it did great to get there:
Copy code
project := config.Get(ctx, "gcp:project")
thanks a ton fellas 🤩