https://pulumi.com logo
Title
p

polite-sandwich-68547

04/26/2023, 8:22 AM
what is the best way to gather configs from Pulumi.yaml, is this how you guys do it too?
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

careful-bird-79707

04/26/2023, 10:54 AM
Just FYI, there's
config.Require
if you want to err when a key is missing
p

polite-sandwich-68547

04/26/2023, 2:17 PM
thank you @careful-bird-79707, I'll amend my code. Appreciate your input.
looks better now, simpler 🙂
var crtArn = config.Require(ctx, "certificate:arn")
		var vpcID = config.Require(ctx, "vpc:id")
c

careful-bird-79707

04/26/2023, 2:20 PM
Definitely 🙂 I'm usually very stringent about not panic'ing but in this case it ain't too bad
p

polite-sandwich-68547

04/26/2023, 2:24 PM
In this case I actually find it brilliant to panic
s

salmon-account-74572

04/26/2023, 5:00 PM
A pattern you’ll see in some of our architecture templates is this:
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

polite-sandwich-68547

04/26/2023, 6:28 PM
thank you @salmon-account-74572, I have in mind some use cases for this approach as well!
s

salmon-account-74572

04/26/2023, 6:29 PM
Happy to help!