Skip to content

Commit 20f34de

Browse files
authored
feat: support CodePipeline V2 (#120)
1 parent 880febb commit 20f34de

File tree

6 files changed

+48
-8
lines changed

6 files changed

+48
-8
lines changed

examples/deployment/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ aws s3api put-object --bucket example-ci-{account_id}-{region} --key deployment-
3232
|------|---------|
3333
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
3434
| <a name="requirement_archive"></a> [archive](#requirement\_archive) | >= 2.2 |
35-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
35+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.32 |
3636

3737
## Providers
3838

3939
| Name | Version |
4040
|------|---------|
4141
| <a name="provider_archive"></a> [archive](#provider\_archive) | >= 2.2 |
42-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
42+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.32 |
4343

4444
## Modules
4545

examples/deployment/complete/main.tf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,24 @@ module "deployment" {
9898
codedeploy_deployment_group_alarm_configuration_alarms = [aws_cloudwatch_metric_alarm.error_rate.id]
9999
codedeploy_deployment_group_auto_rollback_configuration_enabled = true
100100
codedeploy_deployment_group_auto_rollback_configuration_events = ["DEPLOYMENT_FAILURE", "DEPLOYMENT_STOP_ON_ALARM"]
101-
codepipeline_artifact_store_bucket = aws_s3_bucket.source.bucket // example to (optionally) use the same bucket for deployment packages and pipeline artifacts
101+
codepipeline_artifact_store_bucket = aws_s3_bucket.source.bucket // example to (optionally) use the same bucket for deployment packages and pipeline artifacts
102+
codepipeline_type = "V2"
102103
deployment_config_name = aws_codedeploy_deployment_config.canary.id // optionally use custom deployment configuration or a different default deployment configuration like `CodeDeployDefault.LambdaLinear10PercentEvery1Minute` from https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-configurations.html
103104
function_name = local.function_name
104105
s3_bucket = aws_s3_bucket.source.bucket
105106
s3_key = local.s3_key
106107

108+
codepipeline_variables = [
109+
{
110+
name = "FOO"
111+
default_value = "BAR"
112+
description = "test with all config values"
113+
},
114+
{
115+
name = "BAR"
116+
}
117+
]
118+
107119
codepipeline_post_deployment_stages = [
108120
{
109121
name = "Custom"
@@ -161,7 +173,7 @@ module "traffic_hook" {
161173
filename = data.archive_file.traffic_hook.output_path
162174
function_name = "codedeploy-hook-example"
163175
handler = "hook.handler"
164-
runtime = "python3.9"
176+
runtime = "python3.12"
165177
source_code_hash = data.archive_file.traffic_hook.output_base64sha256
166178
}
167179

examples/deployment/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.32"
88
}
99
archive = {
1010
source = "hashicorp/archive"

modules/deployment/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ No modules.
422422
| <a name="input_codepipeline_artifact_store_encryption_key_id"></a> [codepipeline\_artifact\_store\_encryption\_key\_id](#input\_codepipeline\_artifact\_store\_encryption\_key\_id) | The KMS key ARN or ID of a key block AWS CodePipeline uses to encrypt the data in the artifact store, such as an AWS Key Management Service (AWS KMS) key. If you don't specify a key, AWS CodePipeline uses the default key for Amazon Simple Storage Service (Amazon S3). | `string` | `""` | no |
423423
| <a name="input_codepipeline_post_deployment_stages"></a> [codepipeline\_post\_deployment\_stages](#input\_codepipeline\_post\_deployment\_stages) | A map of post deployment stages to execute after the Lambda function has been deployed. The following stages are supported: `CodeBuild`, `CodeDeploy`, `CodePipeline`, `CodeStarNotifications`. | <pre>list(object({<br> name = string<br> actions = list(object({<br> name = string<br> category = string<br> owner = string<br> provider = string<br> version = string<br> input_artifacts = optional(list(any))<br> output_artifacts = optional(list(any))<br> configuration = optional(map(string))<br> }))<br> }))</pre> | `[]` | no |
424424
| <a name="input_codepipeline_role_arn"></a> [codepipeline\_role\_arn](#input\_codepipeline\_role\_arn) | ARN of an existing IAM role for CodePipeline execution. If empty, a dedicated role for your Lambda function with minimal required permissions will be created. | `string` | `""` | no |
425+
| <a name="input_codepipeline_type"></a> [codepipeline\_type](#input\_codepipeline\_type) | Type of the CodePipeline. Possible values are: `V1` and `V2`. | `string` | `"V1"` | no |
426+
| <a name="input_codepipeline_variables"></a> [codepipeline\_variables](#input\_codepipeline\_variables) | CodePipeline variables. Valid only when `codepipeline_type` is `V2`. | <pre>list(object({<br> name = string<br> default_value = optional(string)<br> description = optional(string)<br> }))</pre> | `[]` | no |
425427
| <a name="input_codestar_notifications_detail_type"></a> [codestar\_notifications\_detail\_type](#input\_codestar\_notifications\_detail\_type) | The level of detail to include in the notifications for this resource. Possible values are BASIC and FULL. | `string` | `"BASIC"` | no |
426428
| <a name="input_codestar_notifications_enabled"></a> [codestar\_notifications\_enabled](#input\_codestar\_notifications\_enabled) | Enable CodeStar notifications for your pipeline. | `bool` | `true` | no |
427429
| <a name="input_codestar_notifications_event_type_ids"></a> [codestar\_notifications\_event\_type\_ids](#input\_codestar\_notifications\_event\_type\_ids) | A list of event types associated with this notification rule. For list of allowed events see https://docs.aws.amazon.com/dtconsole/latest/userguide/concepts.html#events-ref-pipeline. | `list(string)` | <pre>[<br> "codepipeline-pipeline-pipeline-execution-succeeded",<br> "codepipeline-pipeline-pipeline-execution-failed"<br>]</pre> | no |

modules/deployment/main.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ locals {
2525
resource "aws_codepipeline" "this" {
2626
depends_on = [aws_iam_role.codepipeline_role]
2727

28-
name = local.pipeline_name
29-
role_arn = var.codepipeline_role_arn == "" ? aws_iam_role.codepipeline_role[0].arn : var.codepipeline_role_arn
30-
tags = var.tags
28+
name = local.pipeline_name
29+
pipeline_type = var.codepipeline_type
30+
role_arn = var.codepipeline_role_arn == "" ? aws_iam_role.codepipeline_role[0].arn : var.codepipeline_role_arn
31+
tags = var.tags
3132

3233
artifact_store {
3334
location = local.artifact_store_bucket
@@ -157,6 +158,15 @@ resource "aws_codepipeline" "this" {
157158
}
158159
}
159160
}
161+
162+
dynamic "variable" {
163+
for_each = var.codepipeline_variables
164+
content {
165+
name = variable.value.name
166+
default_value = variable.value.default_value
167+
description = variable.value.description
168+
}
169+
}
160170
}
161171

162172
resource "aws_s3_bucket" "pipeline" {

modules/deployment/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ variable "codepipeline_artifact_store_encryption_key_id" {
3030
type = string
3131
}
3232

33+
variable "codepipeline_type" {
34+
description = "Type of the CodePipeline. Possible values are: `V1` and `V2`."
35+
default = "V1"
36+
type = string
37+
}
38+
3339
variable "codepipeline_role_arn" {
3440
description = "ARN of an existing IAM role for CodePipeline execution. If empty, a dedicated role for your Lambda function with minimal required permissions will be created."
3541
default = ""
@@ -42,6 +48,16 @@ variable "codebuild_role_arn" {
4248
type = string
4349
}
4450

51+
variable "codepipeline_variables" {
52+
description = "CodePipeline variables. Valid only when `codepipeline_type` is `V2`."
53+
default = []
54+
type = list(object({
55+
name = string
56+
default_value = optional(string)
57+
description = optional(string)
58+
}))
59+
}
60+
4561
variable "codebuild_cloudwatch_logs_retention_in_days" {
4662
description = "Specifies the number of days you want to retain log events in the CodeBuild log group."
4763
default = 14

0 commit comments

Comments
 (0)