Skip to content

Commit

Permalink
fix: interpolate multiple outputs from multiple cf stacks (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari authored Nov 21, 2022
1 parent 9d9a500 commit f467bbc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
18 changes: 18 additions & 0 deletions aws/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ func (c *Cloudformation) GetOutput(stackname string) (map[string]string, error)
return result, nil
}

func (c *Cloudformation) GetOutputs(stacknames []string) (map[string]string, error) {
result := map[string]string{}

for _, stackname := range stacknames {
outputs, err := c.GetOutput(stackname)

if err != nil {
continue
}

for key, value := range outputs {
result[key] = value
}
}

return result, nil
}

func NewCloudformation() Cloudformation {
if cfClient == nil {
retryer := client.DefaultRetryer{
Expand Down
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ func loadVariables(c Config, rc rawConfig) (map[string]string, error) {
// add cloudformation outputs to variables available for interpolation
if len(c.Stacks) > 0 {
cf := aws.NewCloudformation()
// TODO: support multiple cf stack outputs
outputs, err := cf.GetOutput(c.Stacks[0])
outputs, err := cf.GetOutputs(c.Stacks)

if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions example/safebox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ provider: ssm

cloudformation-stacks:
- "{{.stage}}-shared-infra-SharedInfraServerless"
- "{{.stage}}-user-debug-stack"

config:
defaults:
DB_NAME: "database name updated"
API_ENDPOINT: "{{.internalDomainName}}"
CF_OUTPUT_API_ENDPOINT: "{{.internalDomainName}}"
NEW: "endpoint-{{.stage}}"
NEW2: "endpoint updated"
NEW3: "endpoint updated"
AWS_REGION: "{{.region}}"
AWS_ACCOUNT: "{{.account}}"
NEW6: "endpoint updated"
NEW7: "endpoint updated"
CF_OUTPUT_BUCKET_ARN: "{{.BucketArn}}"
CF_OUTPUT_ENDPOINT: "{{.Endpoint}}"

prod:
DB_NAME: "production db name"
Expand Down

0 comments on commit f467bbc

Please sign in to comment.