Hi all, I am using the Go SDK of Pulumi. I am try...
# getting-started
b
Hi all, I am using the Go SDK of Pulumi. I am trying to get the currently configured region of my provider: provider, err := aws.NewProvider(ctx, region, &aws.ProviderArgs{ Region: pulumi.String(region), Profile: pulumi.String(ctx.Stack()), }) There is a field in provider named Region (provider.Region) that is of type StringPtrOutput. I am unable to extract the actual string value of that... can anyone point me in the right direction on how I could do that? (I know I set the region of the provider, but I then pass it into a function, so the region information gets lost)
s
If you are using a configuration value to set provider region (like I use
aws:region
in some of my Pulumi programs), you can use
config.Require
or
config.Try
(the latter would allow you to set a default value in the event the configuration value is missing):
Copy code
awsRegion := config.Require(ctx, "aws:region")
b
I use an array of regions from my config that I loop over. So what I really want to avoid is passing another variable (the region) to my function. I am already passing, context, cfg and provider. So I was hoping I could get the region I currently use (set in the provider) from one of the ones I already pass.
s
Gotcha. Are you able to share a bit more of your code?
b
Yes I will back to you with more information on monday, as my work day is over now 😅 thank you very much so far
s
No worries, have a great weekend!
b
I had kind of an epiphany on how to solve my issue. I was using the config wrong for my use case. So what I do instead now is a config structured like this:
Copy code
config:
  primary_region:
    name: us-east-1
    ...
  secondary_region:
    name: us-west-1
    ....
So now I loop over this and will have all necessary information available within my config. I got another (go specific) question now though: For this new config setup, I will use a struct to read values into. For that, the struct parameters HAVE to start with an uppercase letter (I.e. exporting them) so pulumi config can 'see' them. This struct is in the same package as my pulumi code, so why does it need to be exported to be visible for pulumi?
s
That is a great question! Honestly…I don’t know. Let me poke some of the Golang big brains within the company and see what I can dig up.
I chatted with one of our engineers. Because you have to
import
the Pulumi SDKs at the top of your code, this means they’re not in the same package as your code. Hence, any structs you define in your code need to have exported parameters in order for Pulumi to “see” them.
b
Hey Scott, thank you and your team very much for figuring this out for me. I'm just now starting to dive deep in golang and appreciate any bit of information I can get! Your explanation makes absolute sense. Back to coding, I love working with pulumi so far. Thank you for making a great product :)
s
Thanks for being a Pulumi user, and for participating in our community! If we can be of any help at all, feel free to reach out anytime.