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

Commit d21327a

Browse files
dbaggermanojkelly
authored andcommitted
first pass to allow adding cfn tags (#92)
1 parent d90935f commit d21327a

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

internal/cloudformation/parameters.go

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func ResolveParameters(
3333

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

36+
if env == nil {
37+
env = make(map[string]string)
38+
}
39+
3640
// override envFile values with optional --param values
3741
params := GetParamMap(c)
3842
for key, value := range params {

internal/cloudformation/tasks/upsert.go

+16
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ func UpsertStack(
1818
capabilities []*string,
1919
stackName string,
2020
cf *awsCF.CloudFormation,
21+
tags map[string]string,
2122
) {
2223

2324
var err error
2425
var action string
2526

27+
cfTags := make([]*awsCF.Tag, 0)
28+
for key, value := range tags {
29+
cfTags = append(cfTags, &awsCF.Tag{Key: &key, Value: &value})
30+
}
31+
2632
// use template from file
2733
_, err = cf.DescribeStacks(&awsCF.DescribeStacksInput{StackName: aws.String(stackName)})
2834
if err == nil { //update
@@ -33,6 +39,7 @@ func UpsertStack(
3339
TemplateBody: aws.String(string(templateBody)),
3440
Parameters: parameters,
3541
Capabilities: capabilities,
42+
Tags: cfTags,
3643
})
3744
} else {
3845
action = "Creating"
@@ -42,6 +49,7 @@ func UpsertStack(
4249
TemplateBody: aws.String(string(templateBody)),
4350
Parameters: parameters,
4451
Capabilities: capabilities,
52+
Tags: cfTags,
4553
})
4654
}
4755
checkError(err)
@@ -56,11 +64,17 @@ func UpsertStackViaS3(
5664
capabilities []*string,
5765
stackName string,
5866
cf *awsCF.CloudFormation,
67+
tags map[string]string,
5968
) {
6069

6170
var err error
6271
var action string
6372

73+
cfTags := make([]*awsCF.Tag, 0)
74+
for key, value := range tags {
75+
cfTags = append(cfTags, &awsCF.Tag{Key: &key, Value: &value})
76+
}
77+
6478
// use cf template url
6579
_, err = cf.DescribeStacks(&awsCF.DescribeStacksInput{StackName: aws.String(stackName)})
6680
if err == nil { //update
@@ -72,6 +86,7 @@ func UpsertStackViaS3(
7286
TemplateURL: aws.String(templateURL),
7387
Parameters: parameters,
7488
Capabilities: capabilities,
89+
Tags: cfTags,
7590
})
7691
} else { //create
7792
action = "Creating"
@@ -81,6 +96,7 @@ func UpsertStackViaS3(
8196
TemplateURL: aws.String(templateURL),
8297
Parameters: parameters,
8398
Capabilities: capabilities,
99+
Tags: cfTags,
84100
})
85101
}
86102
checkError(err)

internal/manifest/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ type Manifest struct {
2222
// A flag to indicate if default exports should be added to stacks in this project
2323
// this defaults to false
2424
GenerateDefaultOutputs bool `yaml:"GenerateDefaultOutputs"`
25+
26+
// A set of default tags that will be applied to created stacks
27+
Tags map[string]string `yaml:"Tags"`
2528
}
2629

2730
// Plugin specification inside the manifest

internal/tasks/upsert.go

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func Upsert(c *cli.Context) {
127127
capabilities,
128128
stackName,
129129
cfClient,
130+
manifestFile.Tags,
130131
)
131132
} else {
132133

@@ -139,6 +140,7 @@ func Upsert(c *cli.Context) {
139140
capabilities,
140141
stackName,
141142
cfClient,
143+
manifestFile.Tags,
142144
)
143145
}
144146
}

0 commit comments

Comments
 (0)