Skip to content

Commit 13c97ec

Browse files
authored
Merge pull request #15 from aws-samples/approval
- merged approval into plan stage - default to superseded - pipeline mode input
2 parents b554fb2 + 123f290 commit 13c97ec

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module "pipeline" {
6262
module "pipeline" {
6363
...
6464
branch = "main"
65+
mode = "SUPERSEDED"
6566
detect_changes = true
6667
kms_key = aws_kms_key.this.arn
6768
access_logging_bucket = aws_s3_bucket.this.id
@@ -85,7 +86,9 @@ module "pipeline" {
8586
]
8687
}
8788
```
88-
`branch` is the branch to source. It defaults to "main" and may need to be altered if you are using pre-commit hooks that default to "master".
89+
`branch` is the branch to source. It defaults to `main`.
90+
91+
`mode` is [pipeline execution mode](https://docs.aws.amazon.com/codepipeline/latest/userguide/concepts-how-it-works.html#concepts-how-it-works-executions). It defaults to `SUPERSEDED`.
8992

9093
`detect_changes` is used with third-party services, like GitHub. It enables AWS CodeConnections to invoke the pipeline when there is a commit to the repo.
9194

codepipeline.tf

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "aws_codepipeline" "this" {
55
name = var.pipeline_name
66
pipeline_type = "V2"
77
role_arn = aws_iam_role.codepipeline_role.arn
8-
execution_mode = "QUEUED"
8+
execution_mode = var.mode
99

1010
artifact_store {
1111
location = aws_s3_bucket.this.id
@@ -34,7 +34,6 @@ resource "aws_codepipeline" "this" {
3434

3535
stage {
3636
name = "Validation"
37-
3837
dynamic "action" {
3938
for_each = var.tags == "" ? local.validation_stages : local.conditional_validation_stages
4039
content {
@@ -49,48 +48,40 @@ resource "aws_codepipeline" "this" {
4948
ProjectName = module.validation[action.key].codebuild_project.name
5049
}
5150
}
52-
5351
}
54-
5552
}
5653

5754
stage {
5855
name = "Plan"
59-
6056
action {
6157
name = "Plan"
6258
category = "Build"
6359
owner = "AWS"
6460
provider = "CodeBuild"
6561
input_artifacts = ["source_output"]
6662
version = "1"
63+
run_order = 1
6764

6865
configuration = {
6966
ProjectName = module.plan.codebuild_project.name
7067
}
7168
}
72-
}
73-
74-
stage {
75-
name = "Approve"
76-
7769
action {
78-
name = "Approval"
79-
category = "Approval"
80-
owner = "AWS"
81-
provider = "Manual"
82-
version = "1"
70+
name = "Approval"
71+
category = "Approval"
72+
owner = "AWS"
73+
provider = "Manual"
74+
version = "1"
75+
run_order = 2
8376

8477
configuration = {
85-
CustomData = "This action will approve the deployment of resources in ${var.pipeline_name}. Please ensure that you review the build logs of the plan stage before approving."
86-
ExternalEntityLink = "https://${data.aws_region.current.name}.console.aws.amazon.com/codesuite/codebuild/${data.aws_caller_identity.current.account_id}/projects/${var.pipeline_name}-plan/"
78+
CustomData = "This action will approve the deployment of resources in ${var.pipeline_name}. Please review the plan action before approving."
8779
}
8880
}
8981
}
9082

9183
stage {
9284
name = "Apply"
93-
9485
action {
9586
name = "Apply"
9687
category = "Build"
@@ -106,7 +97,6 @@ resource "aws_codepipeline" "this" {
10697
}
10798
}
10899

109-
110100
resource "aws_iam_role" "codepipeline_role" {
111101
name = "${var.pipeline_name}-role"
112102
assume_role_policy = data.aws_iam_policy_document.codepipeline-assume-role.json

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ variable "log_retention" {
7171
default = 90
7272
}
7373

74+
variable "mode" {
75+
description = "pipeline execution mode"
76+
type = string
77+
default = "SUPERSEDED"
78+
validation {
79+
condition = contains([
80+
"SUPERSEDED",
81+
"PARALLEL",
82+
"QUEUED"
83+
], var.mode)
84+
error_message = "unsupported pipeline mode"
85+
}
86+
87+
}
88+
7489
variable "kms_key" {
7590
description = "AWS KMS key ARN"
7691
type = string

0 commit comments

Comments
 (0)