Skip to content

Commit

Permalink
feat: Add timeout_in_minutes to action block for aws_codepipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
acwwat committed Mar 12, 2024
1 parent 331d948 commit 880fc9e
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/36316.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_codepipeline: Add `timeout_in_minutes` argument to the `action` configuration block
```
13 changes: 13 additions & 0 deletions internal/service/codepipeline/codepipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ func resourcePipeline() *schema.Resource {
Computed: true,
ValidateFunc: validation.IntBetween(1, 999),
},
"timeout_in_minutes": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(5, 86400),
},
"version": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -875,6 +880,10 @@ func expandActionDeclaration(tfMap map[string]interface{}) *types.ActionDeclarat
apiObject.RunOrder = aws.Int32(int32(v))
}

if v, ok := tfMap["timeout_in_minutes"].(int); ok && v != 0 {
apiObject.TimeoutInMinutes = aws.Int32(int32(v))
}

if v, ok := tfMap["version"].(string); ok && v != "" {
apiObject.ActionTypeId.Version = aws.String(v)
}
Expand Down Expand Up @@ -1355,6 +1364,10 @@ func flattenActionDeclaration(d *schema.ResourceData, i, j int, apiObject types.
tfMap["run_order"] = aws.ToInt32(v)
}

if v := apiObject.TimeoutInMinutes; v != nil {
tfMap["timeout_in_minutes"] = aws.ToInt32(v)
}

return tfMap
}

Expand Down
218 changes: 218 additions & 0 deletions internal/service/codepipeline/codepipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,73 @@ func TestAccCodePipeline_pipelinetype(t *testing.T) {
})
}

func TestAccCodePipeline_manualApprovalTimeoutInMinutes(t *testing.T) {
ctx := acctest.Context(t)
var p types.PipelineDeclaration
rName := sdkacctest.RandString(10)
resourceName := "aws_codepipeline.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CodePipelineServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckPipelineDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccCodePipelineConfig_manualApprovalTimeoutInMinutes(rName, 5),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckPipelineExists(ctx, resourceName, &p),
resource.TestCheckResourceAttrPair(resourceName, "role_arn", "aws_iam_role.codepipeline_role", "arn"),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "codepipeline", regexache.MustCompile(fmt.Sprintf("test-pipeline-%s", rName))),
resource.TestCheckResourceAttr(resourceName, "artifact_store.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.#", "3"),
resource.TestCheckResourceAttr(resourceName, "stage.0.name", "Source"),
resource.TestCheckResourceAttr(resourceName, "stage.0.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.0.action.0.timeout_in_minutes", "0"),
resource.TestCheckResourceAttr(resourceName, "stage.1.name", "Approval"),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.0.timeout_in_minutes", "5"),
resource.TestCheckResourceAttr(resourceName, "stage.2.name", "Build"),
resource.TestCheckResourceAttr(resourceName, "stage.2.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.2.action.0.timeout_in_minutes", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccCodePipelineConfig_manualApprovalNoTimeoutInMinutes(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckPipelineExists(ctx, resourceName, &p),
resource.TestCheckResourceAttrPair(resourceName, "role_arn", "aws_iam_role.codepipeline_role", "arn"),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "codepipeline", regexache.MustCompile(fmt.Sprintf("test-pipeline-%s", rName))),
resource.TestCheckResourceAttr(resourceName, "artifact_store.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.#", "3"),
resource.TestCheckResourceAttr(resourceName, "stage.0.name", "Source"),
resource.TestCheckResourceAttr(resourceName, "stage.0.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.0.action.0.timeout_in_minutes", "0"),
resource.TestCheckResourceAttr(resourceName, "stage.1.name", "Approval"),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.0.timeout_in_minutes", "0"),
resource.TestCheckResourceAttr(resourceName, "stage.2.name", "Build"),
resource.TestCheckResourceAttr(resourceName, "stage.2.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "stage.2.action.0.timeout_in_minutes", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckPipelineExists(ctx context.Context, n string, v *types.PipelineDeclaration) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -2449,3 +2516,154 @@ resource "aws_codepipeline" "test" {
}
`, rName))
}

func testAccCodePipelineConfig_manualApprovalTimeoutInMinutes(rName string, timeoutInMinutes int) string { // nosemgrep:ci.codepipeline-in-func-name
return acctest.ConfigCompose(
testAccS3DefaultBucket(rName),
testAccServiceIAMRole(rName),
fmt.Sprintf(`
resource "aws_codepipeline" "test" {
name = "test-pipeline-%[1]s"
role_arn = aws_iam_role.codepipeline_role.arn
artifact_store {
location = aws_s3_bucket.test.bucket
type = "S3"
encryption_key {
id = "1234"
type = "KMS"
}
}
stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "AWS"
provider = "CodeStarSourceConnection"
version = "1"
output_artifacts = ["test"]
configuration = {
ConnectionArn = aws_codestarconnections_connection.test.arn
FullRepositoryId = "lifesum-terraform/test"
BranchName = "main"
}
}
}
stage {
name = "Approval"
action {
name = "Approval"
category = "Approval"
owner = "AWS"
provider = "Manual"
version = "1"
timeout_in_minutes = %[2]d
}
}
stage {
name = "Build"
action {
name = "Build"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
input_artifacts = ["test"]
version = "1"
configuration = {
ProjectName = "test"
}
}
}
}
resource "aws_codestarconnections_connection" "test" {
name = %[1]q
provider_type = "GitHub"
}
`, rName, timeoutInMinutes))
}

func testAccCodePipelineConfig_manualApprovalNoTimeoutInMinutes(rName string) string { // nosemgrep:ci.codepipeline-in-func-name
return acctest.ConfigCompose(
testAccS3DefaultBucket(rName),
testAccServiceIAMRole(rName),
fmt.Sprintf(`
resource "aws_codepipeline" "test" {
name = "test-pipeline-%[1]s"
role_arn = aws_iam_role.codepipeline_role.arn
artifact_store {
location = aws_s3_bucket.test.bucket
type = "S3"
encryption_key {
id = "1234"
type = "KMS"
}
}
stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "AWS"
provider = "CodeStarSourceConnection"
version = "1"
output_artifacts = ["test"]
configuration = {
ConnectionArn = aws_codestarconnections_connection.test.arn
FullRepositoryId = "lifesum-terraform/test"
BranchName = "main"
}
}
}
stage {
name = "Approval"
action {
name = "Approval"
category = "Approval"
owner = "AWS"
provider = "Manual"
version = "1"
}
}
stage {
name = "Build"
action {
name = "Build"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
input_artifacts = ["test"]
version = "1"
configuration = {
ProjectName = "test"
}
}
}
}
resource "aws_codestarconnections_connection" "test" {
name = %[1]q
provider_type = "GitHub"
}
`, rName))
}
1 change: 1 addition & 0 deletions website/docs/cdktf/python/r/codepipeline.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ An `action` block supports the following arguments:
* `run_order` - (Optional) The order in which actions are run.
* `region` - (Optional) The region in which to run the action.
* `namespace` - (Optional) The namespace all output variables will be accessed from.
* `timeout_in_minutes` - (Optional) A timeout duration in minutes that can be applied against the action type's default timeout value specified in [Quotas for AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/limits.html). This argument is available only to the manual approval action type.

~> **Note:** The input artifact of an action must exactly match the output artifact declared in a preceding action, but the input artifact does not have to be the next action in strict sequence from the action that provided the output artifact. Actions in parallel can declare different output artifacts, which are in turn consumed by different following actions.

Expand Down

0 comments on commit 880fc9e

Please sign in to comment.