Skip to content

Commit

Permalink
r/aws_codecommit_trigger: Fix 'RepositoryTriggerBranchNameListRequire…
Browse files Browse the repository at this point in the history
…dException: Repository trigger branch name list cannot be null' error.
  • Loading branch information
ewbankkit committed Jan 22, 2024
1 parent c9b758c commit 05d982c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/service/codecommit/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func resourceTriggerRead(ctx context.Context, d *schema.ResourceData, meta inter
}

d.Set("configuration_id", output.ConfigurationId)
d.Set("respository_name", d.Id())
d.Set("repository_name", d.Id())
if err := d.Set("trigger", flattenRepositoryTriggers(output.Triggers)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting trigger: %s", err)
}
Expand Down Expand Up @@ -193,7 +193,8 @@ func expandRepositoryTriggers(tfList []interface{}) []types.RepositoryTrigger {

apiObject := types.RepositoryTrigger{}

if v, ok := tfMap["branches"].([]interface{}); ok && len(v) > 0 {
// "RepositoryTriggerBranchNameListRequiredException: Repository trigger branch name list cannot be null".
if v, ok := tfMap["branches"].([]interface{}); ok {
apiObject.Branches = flex.ExpandStringValueList(v)
}

Expand Down
80 changes: 79 additions & 1 deletion internal/service/codecommit/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,64 @@ func TestAccCodeCommitTrigger_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccTriggerConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckTriggerExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "trigger.#", "1"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.branches.#", "0"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.events.#", "1"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.events.0", "all"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.name", rName),
),
},
},
})
}

func TestAccCodeCommitTrigger_disappears(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codecommit_trigger.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CodeCommitEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckTriggerDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTriggerConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckTriggerExists(ctx, resourceName),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfcodecommit.ResourceTrigger(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func TestAccCodeCommitTrigger_branches(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codecommit_trigger.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CodeCommitEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckTriggerDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTriggerConfig_branches(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckTriggerExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "trigger.0.branches.#", "2"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.branches.0", "main"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.branches.1", "develop"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.events.#", "2"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.events.0", "updateReference"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.events.1", "createReference"),
resource.TestCheckResourceAttr(resourceName, "trigger.0.name", rName),
),
},
},
Expand Down Expand Up @@ -102,3 +157,26 @@ resource "aws_codecommit_trigger" "test" {
}
`, rName)
}

func testAccTriggerConfig_branches(rName string) string {
return fmt.Sprintf(`
resource "aws_sns_topic" "test" {
name = %[1]q
}
resource "aws_codecommit_repository" "test" {
repository_name = %[1]q
}
resource "aws_codecommit_trigger" "test" {
repository_name = aws_codecommit_repository.test.id
trigger {
name = %[1]q
events = ["updateReference", "createReference"]
destination_arn = aws_sns_topic.test.arn
branches = ["main", "develop"]
}
}
`, rName)
}

0 comments on commit 05d982c

Please sign in to comment.