Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix writing of aws_security_group name_prefix to statefile. #14475

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws/internal/naming/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

var resourceUniqueIDSuffixRegexpPattern = fmt.Sprintf("\\d{%d}$", resource.UniqueIDSuffixLength)
var resourceUniqueIDSuffixRegexpPattern = fmt.Sprintf("[[:xdigit:]]{%d}$", resource.UniqueIDSuffixLength)
var resourceUniqueIDSuffixRegexp = regexp.MustCompile(resourceUniqueIDSuffixRegexpPattern)

var resourceUniqueIDRegexpPattern = resourcePrefixedUniqueIDRegexpPattern(resource.UniqueIdPrefix)
Expand Down
31 changes: 31 additions & 0 deletions aws/internal/naming/naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,21 @@ func TestHasResourceUniqueIdSuffix(t *testing.T) {
Input: "test-20060102150405000000000001",
Expected: true,
},
{
TestName: "correct suffix with hex, incorrect prefix",
Input: "test-200601021504050000000000a1",
Expected: true,
},
{
TestName: "correct suffix, correct prefix",
Input: "terraform-20060102150405000000000001",
Expected: true,
},
{
TestName: "correct suffix with hex, correct prefix",
Input: "terraform-2006010215040500000000000a",
Expected: true,
},
}

for _, testCase := range testCases {
Expand Down Expand Up @@ -152,6 +162,11 @@ func TestNamePrefixFromName(t *testing.T) {
Input: "test-20060102150405000000000001",
Expected: strPtr("test-"),
},
{
TestName: "correct prefix with hyphen, correct suffix with hex",
Input: "test-200601021504050000000000f1",
Expected: strPtr("test-"),
},
{
TestName: "incorrect prefix, correct suffix",
Input: "terraform-20060102150405000000000001",
Expand All @@ -177,4 +192,20 @@ func TestNamePrefixFromName(t *testing.T) {
}
})
}

t.Run("extracting prefix from generated name", func(t *testing.T) {
for i := 0; i < 10; i++ {
prefix := "test-"
input := Generate("", prefix)
got := NamePrefixFromName(input)

if got == nil {
t.Errorf("run%d: got nil, expected %s for input %s", i, prefix, input)
}

if got != nil && prefix != *got {
t.Errorf("run%d: got %s, expected %s for input %s", i, *got, prefix, input)
}
}
})
}