From b228e759c0d432dba3960fcc1057c1fc0a853fbb Mon Sep 17 00:00:00 2001 From: Ingo Miosga Date: Tue, 3 Aug 2021 15:36:05 +0200 Subject: [PATCH 1/3] Fix branch name symmetry issue for Amplify --- aws/internal/service/amplify/id.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/internal/service/amplify/id.go b/aws/internal/service/amplify/id.go index 20bb749cbb0..aeda71e1b48 100644 --- a/aws/internal/service/amplify/id.go +++ b/aws/internal/service/amplify/id.go @@ -34,7 +34,7 @@ func BranchCreateResourceID(appID, branchName string) string { } func BranchParseResourceID(id string) (string, string, error) { - parts := strings.Split(id, branchResourceIDSeparator) + parts := strings.SplitN(id, branchResourceIDSeparator, 2) if len(parts) == 2 && parts[0] != "" && parts[1] != "" { return parts[0], parts[1], nil From 95bc9c1cbc5d3235db8b57ac58e5ffcfcc46b006 Mon Sep 17 00:00:00 2001 From: Ingo Miosga Date: Tue, 3 Aug 2021 16:34:38 +0200 Subject: [PATCH 2/3] Add changelog for PR #20426 --- .changelog/20426.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/20426.txt diff --git a/.changelog/20426.txt b/.changelog/20426.txt new file mode 100644 index 00000000000..d14edd58e90 --- /dev/null +++ b/.changelog/20426.txt @@ -0,0 +1,3 @@ +```release-note:bug +aws/resource_aws_amplify_branch: Correctly handle branch names that contain '/' +``` \ No newline at end of file From 0f0ca0e731cf2da449d3855d7d9d776fabb35b56 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 4 Aug 2021 09:55:13 -0400 Subject: [PATCH 3/3] Add unit tests for 'BranchParseResourceID'. --- aws/internal/service/amplify/id_test.go | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 aws/internal/service/amplify/id_test.go diff --git a/aws/internal/service/amplify/id_test.go b/aws/internal/service/amplify/id_test.go new file mode 100644 index 00000000000..b90b3c86618 --- /dev/null +++ b/aws/internal/service/amplify/id_test.go @@ -0,0 +1,68 @@ +package amplify_test + +import ( + "testing" + + tfamplify "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/amplify" +) + +func TestBranchParseResourceID(t *testing.T) { + testCases := []struct { + TestName string + InputID string + ExpectError bool + ExpectedAppID string + ExpectedBranchName string + }{ + { + TestName: "empty ID", + InputID: "", + ExpectError: true, + }, + { + TestName: "incorrect format", + InputID: "test", + ExpectError: true, + }, + { + TestName: "valid ID", + InputID: tfamplify.BranchCreateResourceID("appID", "branchName"), + ExpectedAppID: "appID", + ExpectedBranchName: "branchName", + }, + { + TestName: "valid ID one slash", + InputID: tfamplify.BranchCreateResourceID("appID", "part1/part_2"), + ExpectedAppID: "appID", + ExpectedBranchName: "part1/part_2", + }, + { + TestName: "valid ID three slashes", + InputID: tfamplify.BranchCreateResourceID("appID", "part1/part_2/part-3/part4"), + ExpectedAppID: "appID", + ExpectedBranchName: "part1/part_2/part-3/part4", + }, + } + + for _, testCase := range testCases { + t.Run(testCase.TestName, func(t *testing.T) { + gotAppID, gotBranchName, err := tfamplify.BranchParseResourceID(testCase.InputID) + + if err == nil && testCase.ExpectError { + t.Fatalf("expected error") + } + + if err != nil && !testCase.ExpectError { + t.Fatalf("unexpected error") + } + + if gotAppID != testCase.ExpectedAppID { + t.Errorf("got AppID %s, expected %s", gotAppID, testCase.ExpectedAppID) + } + + if gotBranchName != testCase.ExpectedBranchName { + t.Errorf("got BranchName %s, expected %s", gotBranchName, testCase.ExpectedBranchName) + } + }) + } +}