-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(terraform-recipe): resource group tagging
- Loading branch information
1 parent
2600f80
commit 16e1a0d
Showing
6 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package terraform | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// serializeTagsIntoAzureCliString converts the given tags from the map to a text that can be passed to an azure cli command | ||
// with the --tags parameter | ||
// The key and value will be quoted e.g. "This is a key"="This is a value" (to support key and value with spaces) | ||
func serializeTagsIntoAzureCliString(tags map[string]string) string { | ||
var tagTexts []string | ||
for key, value := range tags { | ||
tagTexts = append(tagTexts, fmt.Sprintf("%q=%q", key, value)) | ||
} | ||
|
||
return strings.Join(tagTexts, " ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package terraform | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_TagSerialization(t *testing.T) { | ||
result := serializeTagsIntoAzureCliString(map[string]string{ | ||
"tag1": "valueA", | ||
"tag_b": "long string value", | ||
"tag-c": "123", | ||
}) | ||
|
||
// has to be asserted separately, because iterating go maps does not guarantee order! | ||
assert.Contains(t, result, "\"tag1\"=\"valueA\"", result) | ||
assert.Contains(t, result, "\"tag_b\"=\"long string value\"", result) | ||
assert.Contains(t, result, "\"tag-c\"=\"123\"", result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters