what is the best way to gather configs from Pulumi...
# golang
p
what is the best way to gather configs from Pulumi.yaml, is this how you guys do it too?
Copy code
crtArn := config.Get(ctx, "certificate:arn")
		if crtArn == "" {
			return fmt.Errorf("certificate: config not found")
		}
		var vpcID = config.Get(ctx, "vpc:id")
		if vpcID == "" {
			return fmt.Errorf("vpc: config not found")
		}
c
Just FYI, there's
config.Require
if you want to err when a key is missing
p
thank you @careful-bird-79707, I'll amend my code. Appreciate your input.
looks better now, simpler 🙂
Copy code
var crtArn = config.Require(ctx, "certificate:arn")
		var vpcID = config.Require(ctx, "vpc:id")
c
Definitely 🙂 I'm usually very stringent about not panic'ing but in this case it ain't too bad
p
In this case I actually find it brilliant to panic
s
A pattern you’ll see in some of our architecture templates is this:
Copy code
minClusterSize, err := cfg.TryInt("minClusterSize")
if err != nil {
    minClusterSize = 3
}
This has the effect of setting a default value if the configuration value isn’t set. If you prefer to have the program error out, then
Require
is the way to go IMO.
p
thank you @salmon-account-74572, I have in mind some use cases for this approach as well!
s
Happy to help!