Skip to content

Commit 5d69100

Browse files
authored
Fix name tag and add test (#67)
1 parent e2b880b commit 5d69100

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

main.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ locals {
2525
# Merge attributes
2626
attributes = compact(distinct(concat(var.attributes, var.context.attributes, local.defaults.attributes)))
2727

28-
generated_tags = { for l in keys(local.id_context) : title(l) => local.id_context[l] if length(local.id_context[l]) > 0 }
2928

3029
tags = merge(var.context.tags, local.generated_tags, var.tags)
3130
tags_as_list_of_maps = data.null_data_source.tags_as_list_of_maps.*.outputs
3231

32+
tags_context = {
33+
# For AWS we need `Name` to be disambiguated sine it has a special meaning
34+
name = local.id
35+
namespace = local.namespace
36+
environment = local.environment
37+
stage = local.stage
38+
attributes = local.id_context.attributes
39+
}
40+
generated_tags = { for l in keys(local.tags_context) : title(l) => local.tags_context[l] if length(local.tags_context[l]) > 0 }
41+
3342
id_context = {
3443
name = local.name
3544
namespace = local.namespace

test/src/examples_complete_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,35 @@ func TestExamplesComplete(t *testing.T) {
2525

2626
// Run `terraform output` to get the value of an output variable
2727
label1 := terraform.OutputMap(t, terraformOptions, "label1")
28+
label1Tags := terraform.OutputMap(t, terraformOptions, "label1_tags")
2829

2930
// Verify we're getting back the outputs we expect
3031
assert.Equal(t, "winstonchurchroom-uat-build-fire-water-earth-air", label1["id"])
32+
assert.Equal(t, "winstonchurchroom-uat-build-fire-water-earth-air", label1Tags["Name"])
3133

3234
// Run `terraform output` to get the value of an output variable
3335
label2 := terraform.OutputMap(t, terraformOptions, "label2")
36+
label2Tags := terraform.OutputMap(t, terraformOptions, "label2_tags")
3437

3538
// Verify we're getting back the outputs we expect
3639
assert.Equal(t, "charlie+uat+test+fire+water+earth+air", label2["id"])
40+
assert.Equal(t, "charlie+uat+test+fire+water+earth+air", label2Tags["Name"])
3741

3842
// Run `terraform output` to get the value of an output variable
3943
label3 := terraform.OutputMap(t, terraformOptions, "label3")
44+
label3Tags := terraform.OutputMap(t, terraformOptions, "label3_tags")
4045

4146
// Verify we're getting back the outputs we expect
4247
assert.Equal(t, "starfish.uat.release.fire.water.earth.air", label3["id"])
48+
assert.Equal(t, "starfish.uat.release.fire.water.earth.air", label3Tags["Name"])
4349

4450
// Run `terraform output` to get the value of an output variable
4551
label4 := terraform.OutputMap(t, terraformOptions, "label4")
52+
label4Tags := terraform.OutputMap(t, terraformOptions, "label4_tags")
4653

4754
// Verify we're getting back the outputs we expect
4855
assert.Equal(t, "cloudposse-uat-big-fat-honking-cluster", label4["id"])
56+
assert.Equal(t, "cloudposse-uat-big-fat-honking-cluster", label4Tags["Name"])
4957

5058
// Run `terraform output` to get the value of an output variable
5159
label5 := terraform.OutputMap(t, terraformOptions, "label5")

0 commit comments

Comments
 (0)