From db7709ab4e7c10519d100fe43e33d942734d1ab3 Mon Sep 17 00:00:00 2001 From: Kat Schelonka Date: Mon, 13 Jan 2025 14:44:51 -0800 Subject: [PATCH] feat(tfmodules): make deploymentConfigName configurable Enable different traffic patterns for deployment (defaults to All at Once) --- infrastructure/client-api/src/main.ts | 3 +++ .../src/base/ApplicationECSAlbCodeDeploy.ts | 6 +++++- .../terraform-modules/src/base/ApplicationECSService.ts | 3 +++ .../terraform-modules/src/pocket/PocketALBApplication.ts | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/infrastructure/client-api/src/main.ts b/infrastructure/client-api/src/main.ts index 7932862b4..5cf16a58d 100644 --- a/infrastructure/client-api/src/main.ts +++ b/infrastructure/client-api/src/main.ts @@ -309,6 +309,9 @@ class ClientAPI extends TerraformStack { useCodeDeploy: true, useCodePipeline: false, useTerraformBasedCodeDeploy: false, + // Shifts 10 percent of traffic in the first increment. + // The remaining 90 percent is deployed five minutes later. + deploymentConfigName: 'CodeDeployDefault.ECSCanary10Percent5Minutes', generateAppSpec: false, snsNotificationTopicArn: snsTopic.arn, successTerminationWaitTimeInMinutes: 5, diff --git a/packages/terraform-modules/src/base/ApplicationECSAlbCodeDeploy.ts b/packages/terraform-modules/src/base/ApplicationECSAlbCodeDeploy.ts index f0802ef44..a566c90fc 100644 --- a/packages/terraform-modules/src/base/ApplicationECSAlbCodeDeploy.ts +++ b/packages/terraform-modules/src/base/ApplicationECSAlbCodeDeploy.ts @@ -25,6 +25,8 @@ export interface ApplicationECSAlbCodeDeployProps targetGroupNames: string[]; tags?: { [key: string]: string }; dependsOn?: TerraformResource[]; + // Docs at Terraform Registry: CodedeployDeploymentGroup#deployment_config_name + deploymentConfigName?: string | undefined; successTerminationWaitTimeInMinutes?: number; notifications?: { notifyOnStarted?: boolean; @@ -66,7 +68,9 @@ export class ApplicationECSAlbCodeDeploy extends Construct { { dependsOn: config.dependsOn, appName: codeDeployApp.name, - deploymentConfigName: 'CodeDeployDefault.ECSAllAtOnce', + deploymentConfigName: + this.config.deploymentConfigName ?? + 'CodeDeployDefault.ECSAllAtOnce', deploymentGroupName: `${this.config.prefix}-ECS`, serviceRoleArn: ecsCodeDeployRole.arn, autoRollbackConfiguration: { diff --git a/packages/terraform-modules/src/base/ApplicationECSService.ts b/packages/terraform-modules/src/base/ApplicationECSService.ts index f52beb52b..808d3b590 100644 --- a/packages/terraform-modules/src/base/ApplicationECSService.ts +++ b/packages/terraform-modules/src/base/ApplicationECSService.ts @@ -64,6 +64,8 @@ export interface ApplicationECSServiceProps extends TerraformMetaArguments { useCodePipeline?: boolean; generateAppSpec?: boolean; successTerminationWaitTimeInMinutes?: number; + // Docs at Terraform Registry: CodedeployDeploymentGroup#deployment_config_name + deploymentConfigName?: string | undefined; codeDeployNotifications?: { notifyOnStarted?: boolean; //defaults to true notifyOnSucceeded?: boolean; //defaults to true @@ -205,6 +207,7 @@ export class ApplicationECSService extends Construct { clusterName: this.config.ecsClusterName, targetGroupNames: targetGroupNames, listenerArn: this.config.albConfig.listenerArn, + deploymentConfigName: this.config.deploymentConfigName, snsNotificationTopicArn: this.config.codeDeploySnsNotificationTopicArn, tags: this.config.tags, diff --git a/packages/terraform-modules/src/pocket/PocketALBApplication.ts b/packages/terraform-modules/src/pocket/PocketALBApplication.ts index 3031f9153..be2b5f59f 100644 --- a/packages/terraform-modules/src/pocket/PocketALBApplication.ts +++ b/packages/terraform-modules/src/pocket/PocketALBApplication.ts @@ -123,6 +123,12 @@ export interface PocketALBApplicationProps extends TerraformMetaArguments { * Option to create a CodeDeploy application. */ useCodeDeploy: boolean; + /** + * How to do the blue/green deployment + * Docs at Terraform Registry: CodedeployDeploymentGroup#deployment_config_name + * See also: https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-configurations.html + */ + deploymentConfigName?: string | undefined; /** * Option to deploy a new version using terraform, instead of externally */ @@ -644,6 +650,7 @@ export class PocketALBApplication extends Construct { ecsClusterArn: ecsCluster.cluster.arn, ecsClusterName: ecsCluster.cluster.name, useCodeDeploy: this.config.codeDeploy.useCodeDeploy, + deploymentConfigName: this.config.codeDeploy.deploymentConfigName, codeDeployNotifications: this.config.codeDeploy.notifications, useCodePipeline: this.config.codeDeploy.useCodePipeline, useTerraformBasedCodeDeploy: