Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
first pass to allow adding cfn tags (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaggerman authored and ojkelly committed Aug 13, 2018
1 parent d90935f commit d21327a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/cloudformation/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func ResolveParameters(

env := resolveEnvironmentParameters(manifestFile, c.String("environment"))

if env == nil {
env = make(map[string]string)
}

// override envFile values with optional --param values
params := GetParamMap(c)
for key, value := range params {
Expand Down
16 changes: 16 additions & 0 deletions internal/cloudformation/tasks/upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ func UpsertStack(
capabilities []*string,
stackName string,
cf *awsCF.CloudFormation,
tags map[string]string,
) {

var err error
var action string

cfTags := make([]*awsCF.Tag, 0)
for key, value := range tags {
cfTags = append(cfTags, &awsCF.Tag{Key: &key, Value: &value})
}

// use template from file
_, err = cf.DescribeStacks(&awsCF.DescribeStacksInput{StackName: aws.String(stackName)})
if err == nil { //update
Expand All @@ -33,6 +39,7 @@ func UpsertStack(
TemplateBody: aws.String(string(templateBody)),
Parameters: parameters,
Capabilities: capabilities,
Tags: cfTags,
})
} else {
action = "Creating"
Expand All @@ -42,6 +49,7 @@ func UpsertStack(
TemplateBody: aws.String(string(templateBody)),
Parameters: parameters,
Capabilities: capabilities,
Tags: cfTags,
})
}
checkError(err)
Expand All @@ -56,11 +64,17 @@ func UpsertStackViaS3(
capabilities []*string,
stackName string,
cf *awsCF.CloudFormation,
tags map[string]string,
) {

var err error
var action string

cfTags := make([]*awsCF.Tag, 0)
for key, value := range tags {
cfTags = append(cfTags, &awsCF.Tag{Key: &key, Value: &value})
}

// use cf template url
_, err = cf.DescribeStacks(&awsCF.DescribeStacksInput{StackName: aws.String(stackName)})
if err == nil { //update
Expand All @@ -72,6 +86,7 @@ func UpsertStackViaS3(
TemplateURL: aws.String(templateURL),
Parameters: parameters,
Capabilities: capabilities,
Tags: cfTags,
})
} else { //create
action = "Creating"
Expand All @@ -81,6 +96,7 @@ func UpsertStackViaS3(
TemplateURL: aws.String(templateURL),
Parameters: parameters,
Capabilities: capabilities,
Tags: cfTags,
})
}
checkError(err)
Expand Down
3 changes: 3 additions & 0 deletions internal/manifest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type Manifest struct {
// A flag to indicate if default exports should be added to stacks in this project
// this defaults to false
GenerateDefaultOutputs bool `yaml:"GenerateDefaultOutputs"`

// A set of default tags that will be applied to created stacks
Tags map[string]string `yaml:"Tags"`
}

// Plugin specification inside the manifest
Expand Down
2 changes: 2 additions & 0 deletions internal/tasks/upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func Upsert(c *cli.Context) {
capabilities,
stackName,
cfClient,
manifestFile.Tags,
)
} else {

Expand All @@ -139,6 +140,7 @@ func Upsert(c *cli.Context) {
capabilities,
stackName,
cfClient,
manifestFile.Tags,
)
}
}
Expand Down

0 comments on commit d21327a

Please sign in to comment.