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

Add Stage-Level Rollback for CodePipeline #37245

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions internal/service/codepipeline/codepipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func resourcePipeline() *schema.Resource {
validation.StringMatch(regexache.MustCompile(`[0-9A-Za-z_.@-]+`), ""),
),
},
"on_failure": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: enum.Validate[types.Result](),
},
},
},
},
Expand Down Expand Up @@ -795,6 +800,12 @@ func expandStageDeclaration(tfMap map[string]interface{}) *types.StageDeclaratio
apiObject.Name = aws.String(v)
}

if v, ok := tfMap["on_failure"].(string); ok && v != "" {
apiObject.OnFailure = &types.FailureConditions{
Result: types.Result(v),
}
}

return apiObject
}

Expand Down Expand Up @@ -1282,6 +1293,10 @@ func flattenStageDeclaration(d *schema.ResourceData, i int, apiObject types.Stag
tfMap[names.AttrName] = aws.ToString(v)
}

if v := apiObject.OnFailure; v != nil {
tfMap["on_failure"] = v.Result
}

return tfMap
}

Expand Down
4 changes: 4 additions & 0 deletions internal/service/codepipeline/codepipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ func TestAccCodePipeline_pipelinetype(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "stage.0.action.0.configuration.BranchName", "stable"),
resource.TestCheckResourceAttrPair(resourceName, "stage.0.action.0.configuration.ConnectionArn", codestarConnectionResourceName, names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "stage.1.name", "Build"),
resource.TestCheckResourceAttr(resourceName, "stage.1.on_failure", "ROLLBACK"),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.0.name", "Build"),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.0.input_artifacts.#", acctest.Ct1),
Expand Down Expand Up @@ -820,6 +821,7 @@ func TestAccCodePipeline_pipelinetype(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "stage.0.action.0.configuration.BranchName", "stable"),
resource.TestCheckResourceAttrPair(resourceName, "stage.0.action.0.configuration.ConnectionArn", codestarConnectionResourceName, names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "stage.1.name", "Build"),
resource.TestCheckResourceAttr(resourceName, "stage.1.on_failure", ""),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.0.name", "Build"),
resource.TestCheckResourceAttr(resourceName, "stage.1.action.0.input_artifacts.#", acctest.Ct1),
Expand Down Expand Up @@ -1398,6 +1400,8 @@ resource "aws_codepipeline" "test" {
stage {
name = "Build"

on_failure = "ROLLBACK"

action {
name = "Build"
category = "Build"
Expand Down