diff --git a/aws/resource_aws_codepipeline.go b/aws/resource_aws_codepipeline.go index 8cb011634e8..a918d84ae52 100644 --- a/aws/resource_aws_codepipeline.go +++ b/aws/resource_aws_codepipeline.go @@ -416,6 +416,9 @@ func flattenAwsCodePipelineStageActionConfiguration(config map[string]*string) m func expandAwsCodePipelineActionsOutputArtifacts(s []interface{}) []*codepipeline.OutputArtifact { outputArtifacts := []*codepipeline.OutputArtifact{} for _, artifact := range s { + if artifact == nil { + continue + } outputArtifacts = append(outputArtifacts, &codepipeline.OutputArtifact{ Name: aws.String(artifact.(string)), }) @@ -434,6 +437,9 @@ func flattenAwsCodePipelineActionsOutputArtifacts(artifacts []*codepipeline.Outp func expandAwsCodePipelineActionsInputArtifacts(s []interface{}) []*codepipeline.InputArtifact { outputArtifacts := []*codepipeline.InputArtifact{} for _, artifact := range s { + if artifact == nil { + continue + } outputArtifacts = append(outputArtifacts, &codepipeline.InputArtifact{ Name: aws.String(artifact.(string)), }) diff --git a/aws/resource_aws_codepipeline_test.go b/aws/resource_aws_codepipeline_test.go index 0951a28b7e6..bd83c6f47a4 100644 --- a/aws/resource_aws_codepipeline_test.go +++ b/aws/resource_aws_codepipeline_test.go @@ -49,6 +49,40 @@ func TestAccAWSCodePipeline_basic(t *testing.T) { }) } +func TestAccAWSCodePipeline_emptyArtifacts(t *testing.T) { + if os.Getenv("GITHUB_TOKEN") == "" { + t.Skip("Environment variable GITHUB_TOKEN is not set") + } + + name := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodePipelineDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodePipelineConfig_emptyArtifacts(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodePipelineExists("aws_codepipeline.bar"), + resource.TestMatchResourceAttr("aws_codepipeline.bar", "arn", + regexp.MustCompile(fmt.Sprintf("^arn:aws:codepipeline:[^:]+:[0-9]{12}:test-pipeline-%s", name))), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "artifact_store.0.type", "S3"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.name", "Build"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.action.#", "1"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.action.0.name", "Build"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.action.0.category", "Build"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.action.0.owner", "AWS"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.action.0.provider", "CodeBuild"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.action.0.input_artifacts.#", "1"), + resource.TestCheckResourceAttr("aws_codepipeline.bar", "stage.1.action.0.output_artifacts.#", "0"), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func TestAccAWSCodePipeline_deployWithServiceRole(t *testing.T) { if os.Getenv("GITHUB_TOKEN") == "" { t.Skip("Environment variable GITHUB_TOKEN is not set") @@ -345,6 +379,114 @@ resource "aws_codepipeline" "bar" { `, rName, rName, rName) } +func testAccAWSCodePipelineConfig_emptyArtifacts(rName string) string { + return fmt.Sprintf(` +resource "aws_s3_bucket" "foo" { + bucket = "tf-test-pipeline-%s" + acl = "private" +} + +resource "aws_iam_role" "codepipeline_role" { + name = "codepipeline-role-%s" + + assume_role_policy = <