Skip to content

Commit e7e97fc

Browse files
committed
Fix duplicate CloudFormation tags when input tags overlap with existing stack tags
1 parent 01f2942 commit e7e97fc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

provider/aws/helpers.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,20 +1335,28 @@ func (p *Provider) updateStack(name string, template []byte, changes map[string]
13351335
}
13361336
}
13371337

1338-
req.Tags = stack.Tags
1338+
// Merge existing stack tags with input tags, deduplicating by key.
1339+
// Input tags override existing stack tags. Skip aws: prefixed tags.
1340+
tagMap := map[string]string{}
1341+
for _, t := range stack.Tags {
1342+
if !strings.HasPrefix(aws.StringValue(t.Key), "aws:") {
1343+
tagMap[aws.StringValue(t.Key)] = aws.StringValue(t.Value)
1344+
}
1345+
}
1346+
for k, v := range tags {
1347+
tagMap[k] = v
1348+
}
13391349

13401350
tks := []string{}
1341-
1342-
for key := range tags {
1351+
for key := range tagMap {
13431352
tks = append(tks, key)
13441353
}
1345-
13461354
sort.Strings(tks)
13471355

13481356
for _, key := range tks {
13491357
req.Tags = append(req.Tags, &cloudformation.Tag{
13501358
Key: aws.String(key),
1351-
Value: aws.String(tags[key]),
1359+
Value: aws.String(tagMap[key]),
13521360
})
13531361
}
13541362

0 commit comments

Comments
 (0)