Skip to content

Resource: awsCodedeployDeploymentGroup

Provides a CodeDeploy Deployment Group for a CodeDeploy Application

\~> NOTE on blue/green deployments: When using greenFleetProvisioningOption with the COPY_AUTO_SCALING_GROUP action, CodeDeploy will create a new ASG with a different name. This ASG is not managed by terraform and will conflict with existing configuration and state. You may want to use a different approach to managing deployments that involve multiple ASG, such as DISCOVER_EXISTING with separate blue and green ASG.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsCodedeployAppExample = new aws.codedeployApp.CodedeployApp(
  this,
  "example",
  {
    name: "example-app",
  }
);
const awsSnsTopicExample = new aws.snsTopic.SnsTopic(this, "example_1", {
  name: "example-topic",
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsSnsTopicExample.overrideLogicalId("example");
const dataAwsIamPolicyDocumentAssumeRole =
  new aws.dataAwsIamPolicyDocument.DataAwsIamPolicyDocument(
    this,
    "assume_role",
    {
      statement: [
        {
          actions: ["sts:AssumeRole"],
          effect: "Allow",
          principals: [
            {
              identifiers: ["codedeploy.amazonaws.com"],
              type: "Service",
            },
          ],
        },
      ],
    }
  );
const awsIamRoleExample = new aws.iamRole.IamRole(this, "example_3", {
  assumeRolePolicy: dataAwsIamPolicyDocumentAssumeRole.json,
  name: "example-role",
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsIamRoleExample.overrideLogicalId("example");
new aws.iamRolePolicyAttachment.IamRolePolicyAttachment(
  this,
  "AWSCodeDeployRole",
  {
    policyArn: "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole",
    role: awsIamRoleExample.name,
  }
);
const awsCodedeployDeploymentGroupExample =
  new aws.codedeployDeploymentGroup.CodedeployDeploymentGroup(
    this,
    "example_5",
    {
      alarmConfiguration: {
        alarms: ["my-alarm-name"],
        enabled: true,
      },
      appName: awsCodedeployAppExample.name,
      autoRollbackConfiguration: {
        enabled: true,
        events: ["DEPLOYMENT_FAILURE"],
      },
      deploymentGroupName: "example-group",
      ec2TagSet: [
        {
          ec2TagFilter: [
            {
              key: "filterkey1",
              type: "KEY_AND_VALUE",
              value: "filtervalue",
            },
            {
              key: "filterkey2",
              type: "KEY_AND_VALUE",
              value: "filtervalue",
            },
          ],
        },
      ],
      serviceRoleArn: awsIamRoleExample.arn,
      triggerConfiguration: [
        {
          triggerEvents: ["DeploymentFailure"],
          triggerName: "example-trigger",
          triggerTargetArn: awsSnsTopicExample.arn,
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsCodedeployDeploymentGroupExample.overrideLogicalId("example");

Blue Green Deployments with ECS

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsCodedeployAppExample = new aws.codedeployApp.CodedeployApp(
  this,
  "example",
  {
    computePlatform: "ECS",
    name: "example",
  }
);
const awsCodedeployDeploymentGroupExample =
  new aws.codedeployDeploymentGroup.CodedeployDeploymentGroup(
    this,
    "example_1",
    {
      appName: awsCodedeployAppExample.name,
      autoRollbackConfiguration: {
        enabled: true,
        events: ["DEPLOYMENT_FAILURE"],
      },
      blueGreenDeploymentConfig: {
        deploymentReadyOption: {
          actionOnTimeout: "CONTINUE_DEPLOYMENT",
        },
        terminateBlueInstancesOnDeploymentSuccess: {
          action: "TERMINATE",
          terminationWaitTimeInMinutes: 5,
        },
      },
      deploymentConfigName: "CodeDeployDefault.ECSAllAtOnce",
      deploymentGroupName: "example",
      deploymentStyle: {
        deploymentOption: "WITH_TRAFFIC_CONTROL",
        deploymentType: "BLUE_GREEN",
      },
      ecsService: {
        clusterName: "${aws_ecs_cluster.example.name}",
        serviceName: "${aws_ecs_service.example.name}",
      },
      loadBalancerInfo: {
        targetGroupPairInfo: {
          prodTrafficRoute: {
            listenerArns: ["${aws_lb_listener.example.arn}"],
          },
          targetGroup: [
            {
              name: "${aws_lb_target_group.blue.name}",
            },
            {
              name: "${aws_lb_target_group.green.name}",
            },
          ],
        },
      },
      serviceRoleArn: "${aws_iam_role.example.arn}",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsCodedeployDeploymentGroupExample.overrideLogicalId("example");

Blue Green Deployments with Servers and Classic ELB

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsCodedeployAppExample = new aws.codedeployApp.CodedeployApp(
  this,
  "example",
  {
    name: "example-app",
  }
);
const awsCodedeployDeploymentGroupExample =
  new aws.codedeployDeploymentGroup.CodedeployDeploymentGroup(
    this,
    "example_1",
    {
      appName: awsCodedeployAppExample.name,
      blueGreenDeploymentConfig: {
        deploymentReadyOption: {
          actionOnTimeout: "STOP_DEPLOYMENT",
          waitTimeInMinutes: 60,
        },
        greenFleetProvisioningOption: {
          action: "DISCOVER_EXISTING",
        },
        terminateBlueInstancesOnDeploymentSuccess: {
          action: "KEEP_ALIVE",
        },
      },
      deploymentGroupName: "example-group",
      deploymentStyle: {
        deploymentOption: "WITH_TRAFFIC_CONTROL",
        deploymentType: "BLUE_GREEN",
      },
      loadBalancerInfo: {
        elbInfo: [
          {
            name: "${aws_elb.example.name}",
          },
        ],
      },
      serviceRoleArn: "${aws_iam_role.example.arn}",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsCodedeployDeploymentGroupExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • appName - (Required) The name of the application.
  • deploymentGroupName - (Required) The name of the deployment group.
  • serviceRoleArn - (Required) The service role ARN that allows deployments.
  • alarmConfiguration - (Optional) Configuration block of alarms associated with the deployment group (documented below).
  • autoRollbackConfiguration - (Optional) Configuration block of the automatic rollback configuration associated with the deployment group (documented below).
  • autoscalingGroups - (Optional) Autoscaling groups associated with the deployment group.
  • blueGreenDeploymentConfig - (Optional) Configuration block of the blue/green deployment options for a deployment group (documented below).
  • deploymentConfigName - (Optional) The name of the group's deployment config. The default is "CodeDeployDefault.OneAtATime".
  • deploymentStyle - (Optional) Configuration block of the type of deployment, either in-place or blue/green, you want to run and whether to route deployment traffic behind a load balancer (documented below).
  • ec2TagFilter - (Optional) Tag filters associated with the deployment group. See the AWS docs for details.
  • ec2TagSet - (Optional) Configuration block(s) of Tag filters associated with the deployment group, which are also referred to as tag groups (documented below). See the AWS docs for details.
  • ecsService - (Optional) Configuration block(s) of the ECS services for a deployment group (documented below).
  • loadBalancerInfo - (Optional) Single configuration block of the load balancer to use in a blue/green deployment (documented below).
  • onPremisesInstanceTagFilter - (Optional) On premise tag filters associated with the group. See the AWS docs for details.
  • triggerConfiguration - (Optional) Configuration block(s) of the triggers for the deployment group (documented below).
  • tags - (Optional) Key-value map of resource tags. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

alarm_configuration Argument Reference

You can configure a deployment to stop when a CloudWatch alarm detects that a metric has fallen below or exceeded a defined threshold. alarmConfiguration supports the following:

  • alarms - (Optional) A list of alarms configured for the deployment group. A maximum of 10 alarms can be added to a deployment group.
  • enabled - (Optional) Indicates whether the alarm configuration is enabled. This option is useful when you want to temporarily deactivate alarm monitoring for a deployment group without having to add the same alarms again later.
  • ignorePollAlarmFailure - (Optional) Indicates whether a deployment should continue if information about the current state of alarms cannot be retrieved from CloudWatch. The default value is false.
  • true: The deployment will proceed even if alarm status information can't be retrieved.
  • false: The deployment will stop if alarm status information can't be retrieved.

Only one alarmConfiguration is allowed.

auto_rollback_configuration Argument Reference

You can configure a deployment group to automatically rollback when a deployment fails or when a monitoring threshold you specify is met. In this case, the last known good version of an application revision is deployed. autoRollbackConfiguration supports the following:

  • enabled - (Optional) Indicates whether a defined automatic rollback configuration is currently enabled for this Deployment Group. If you enable automatic rollback, you must specify at least one event type.
  • events - (Optional) The event type or types that trigger a rollback. Supported types are DEPLOYMENT_FAILURE and DEPLOYMENT_STOP_ON_ALARM.

Only one autoRollbackConfiguration is allowed.

blue_green_deployment_config Argument Reference

You can configure options for a blue/green deployment. blueGreenDeploymentConfig supports the following:

  • deploymentReadyOption - (Optional) Information about the action to take when newly provisioned instances are ready to receive traffic in a blue/green deployment (documented below).
  • greenFleetProvisioningOption - (Optional) Information about how instances are provisioned for a replacement environment in a blue/green deployment (documented below).
  • terminateBlueInstancesOnDeploymentSuccess - (Optional) Information about whether to terminate instances in the original fleet during a blue/green deployment (documented below).

Only one blueGreenDeploymentConfig is allowed.

You can configure how traffic is rerouted to instances in a replacement environment in a blue/green deployment. deploymentReadyOption supports the following:

  • actionOnTimeout - (Optional) When to reroute traffic from an original environment to a replacement environment in a blue/green deployment.
  • CONTINUE_DEPLOYMENT: Register new instances with the load balancer immediately after the new application revision is installed on the instances in the replacement environment.
  • STOP_DEPLOYMENT: Do not register new instances with load balancer unless traffic is rerouted manually. If traffic is not rerouted manually before the end of the specified wait period, the deployment status is changed to Stopped.
  • waitTimeInMinutes - (Optional) The number of minutes to wait before the status of a blue/green deployment changed to Stopped if rerouting is not started manually. Applies only to the STOP_DEPLOYMENT option for actionOnTimeout.

You can configure how instances will be added to the replacement environment in a blue/green deployment. greenFleetProvisioningOption supports the following:

  • action - (Optional) The method used to add instances to a replacement environment.
  • DISCOVER_EXISTING: Use instances that already exist or will be created manually.
  • COPY_AUTO_SCALING_GROUP: Use settings from a specified Auto Scaling group to define and create instances in a new Auto Scaling group. Exactly one Auto Scaling group must be specified when selecting COPY_AUTO_SCALING_GROUP. Use autoscalingGroups to specify the Auto Scaling group.

You can configure how instances in the original environment are terminated when a blue/green deployment is successful. terminateBlueInstancesOnDeploymentSuccess supports the following:

  • action - (Optional) The action to take on instances in the original environment after a successful blue/green deployment.
  • terminate: Instances are terminated after a specified wait time.
  • KEEP_ALIVE: Instances are left running after they are deregistered from the load balancer and removed from the deployment group.
  • terminationWaitTimeInMinutes - (Optional) The number of minutes to wait after a successful blue/green deployment before terminating instances from the original environment.

deployment_style Argument Reference

You can configure the type of deployment, either in-place or blue/green, you want to run and whether to route deployment traffic behind a load balancer. deploymentStyle supports the following:

  • deploymentOption - (Optional) Indicates whether to route deployment traffic behind a load balancer. Valid Values are WITH_TRAFFIC_CONTROL or WITHOUT_TRAFFIC_CONTROL. Default is WITHOUT_TRAFFIC_CONTROL.
  • deploymentType - (Optional) Indicates whether to run an in-place deployment or a blue/green deployment. Valid Values are IN_PLACE or BLUE_GREEN. Default is IN_PLACE.

Only one deploymentStyle is allowed.

ec2_tag_filter Argument Reference

The ec2TagFilter configuration block supports the following:

  • key - (Optional) The key of the tag filter.
  • type - (Optional) The type of the tag filter, either KEY_ONLY, VALUE_ONLY, or KEY_AND_VALUE.
  • value - (Optional) The value of the tag filter.

Multiple occurrences of ec2TagFilter are allowed, where any instance that matches to at least one of the tag filters is selected.

ec2_tag_set Argument Reference

You can form a tag group by putting a set of tag filters into ec2TagSet. If multiple tag groups are specified, any instance that matches to at least one tag filter of every tag group is selected.

ecs_service Argument Reference

Each ecsService configuration block supports the following:

  • clusterName - (Required) The name of the ECS cluster.
  • serviceName - (Required) The name of the ECS service.

load_balancer_info Argument Reference

You can configure the Load Balancer to use in a deployment. loadBalancerInfo supports the following:

  • elbInfo - (Optional) The Classic Elastic Load Balancer to use in a deployment. Conflicts with targetGroupInfo and targetGroupPairInfo.
  • targetGroupInfo - (Optional) The (Application/Network Load Balancer) target group to use in a deployment. Conflicts with elbInfo and targetGroupPairInfo.
  • targetGroupPairInfo - (Optional) The (Application/Network Load Balancer) target group pair to use in a deployment. Conflicts with elbInfo and targetGroupInfo.

load_balancer_info elb_info Argument Reference

The elbInfo configuration block supports the following:

  • name - (Optional) The name of the load balancer that will be used to route traffic from original instances to replacement instances in a blue/green deployment. For in-place deployments, the name of the load balancer that instances are deregistered from so they are not serving traffic during a deployment, and then re-registered with after the deployment completes.

load_balancer_info target_group_info Argument Reference

The targetGroupInfo configuration block supports the following:

  • name - (Optional) The name of the target group that instances in the original environment are deregistered from, and instances in the replacement environment registered with. For in-place deployments, the name of the target group that instances are deregistered from, so they are not serving traffic during a deployment, and then re-registered with after the deployment completes.

load_balancer_info target_group_pair_info Argument Reference

The targetGroupPairInfo configuration block supports the following:

  • prodTrafficRoute - (Required) Configuration block for the production traffic route (documented below).
  • targetGroup - (Required) Configuration blocks for a target group within a target group pair (documented below).
  • testTrafficRoute - (Optional) Configuration block for the test traffic route (documented below).
load_balancer_info target_group_pair_info prod_traffic_route Argument Reference

The prodTrafficRoute configuration block supports the following:

  • listenerArns - (Required) List of Amazon Resource Names (ARNs) of the load balancer listeners.
load_balancer_info target_group_pair_info target_group Argument Reference

The targetGroup configuration block supports the following:

  • name - (Required) Name of the target group.
load_balancer_info target_group_pair_info test_traffic_route Argument Reference

The testTrafficRoute configuration block supports the following:

  • listenerArns - (Required) List of Amazon Resource Names (ARNs) of the load balancer listeners.

on_premises_instance_tag_filter Argument Reference

The onPremisesInstanceTagFilter configuration block supports the following:

  • key - (Optional) The key of the tag filter.
  • type - (Optional) The type of the tag filter, either KEY_ONLY, VALUE_ONLY, or KEY_AND_VALUE.
  • value - (Optional) The value of the tag filter.

trigger_configuration Argument Reference

Add triggers to a Deployment Group to receive notifications about events related to deployments or instances in the group. Notifications are sent to subscribers of the SNS topic associated with the trigger. CodeDeploy must have permission to publish to the topic from this deployment group. triggerConfiguration supports the following:

  • triggerEvents - (Required) The event type or types for which notifications are triggered. Some values that are supported: deploymentStart, deploymentSuccess, deploymentFailure, deploymentStop, deploymentRollback, instanceStart, instanceSuccess, instanceFailure. See the CodeDeploy documentation for all possible values.
  • triggerName - (Required) The name of the notification trigger.
  • triggerTargetArn - (Required) The ARN of the SNS topic through which notifications are sent.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • arn - The ARN of the CodeDeploy deployment group.
  • id - Application name and deployment group name.
  • computePlatform - The destination platform type for the deployment.
  • deploymentGroupId - The ID of the CodeDeploy deployment group.
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

CodeDeploy Deployment Groups can be imported by their appName, a colon, and deploymentGroupName, e.g.,

$ terraform import aws_codedeploy_deployment_group.example my-application:my-deployment-group