diff --git a/README.md b/README.md index da0c03a..69a0668 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,39 @@ Create an deployment group for a codedeploy app trigger_target_arn = "arn:aws:sns:eu-west-1:123456780:CodeDeploy" } ``` +## deployment-group-blue-green +Creates a deployment group for a CodeDeploy app. This works in a blue/green way + +### Available variables + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| action\_on\_timeout | When to reroute traffic from an original environment to a replacement environment in a blue/green deployment | string | `"CONTINUE_DEPLOYMENT"` | no | +| app\_name | Name of the app | string | n/a | yes | +| autoscaling\_groups | Autoscaling groups you want to attach to the deployment group | list | n/a | yes | +| environment | Environment where your codedeploy deployment group is used for | string | n/a | yes | +| rollback\_enabled | Whether to enable auto rollback | string | `"false"` | no | +| rollback\_events | The event types that trigger a rollback | list | `` | no | +| service\_role\_arn | IAM role that is used by the deployment group | string | n/a | yes | +| terminate\_blue\_instances\_on\_deployment\_success | The action to take on instances in the original environment after a successful blue/green deployment | string | `"KEEP_ALIVE"` | no | +| trigger\_events | events that can trigger the notifications | list | `` | no | +| trigger\_target\_arn | ARN of the target group | string | n/a | yes | + +### Outputs + +/ + +### Example +``` + module "deployment_group-ec2tag" { + environment = "environment" + app_name = "codedeploy_app_app_name" + service_role_arn = "codedeploy_role_arn" + autoscaling_groups = ["${var.blue_desired_capacity > 0 ? blue_asg_id : green_asg_id}"] + trigger_target_arn = "sns_lambda_topic" + rollback_enabled = true + } +``` ## deployment-group-ec2tag Create an deployment group for a codedeploy app. This module will filter for tags diff --git a/deployment-group-blue-green/main.tf b/deployment-group-blue-green/main.tf new file mode 100644 index 0000000..8757d21 --- /dev/null +++ b/deployment-group-blue-green/main.tf @@ -0,0 +1,33 @@ +resource "aws_codedeploy_deployment_group" "deployment_group" { + app_name = "${var.app_name}" + deployment_group_name = "${var.app_name}-${var.environment}" + deployment_config_name = "CodeDeployDefault.AllAtOnce" + service_role_arn = "${var.service_role_arn}" + autoscaling_groups = ["${var.autoscaling_groups}"] + + auto_rollback_configuration { + enabled = "${var.rollback_enabled}" + events = "${var.rollback_events}" + } + + blue_green_deployment_config { + deployment_ready_option { + action_on_timeout = "${var.action_on_timeout}" + } + + terminate_blue_instances_on_deployment_success { + action = "${var.terminate_blue_instances_on_deployment_success}" + } + } + + deployment_style { + deployment_option = "WITH_TRAFFIC_CONTROL" + deployment_type = "BLUE_GREEN" + } + + trigger_configuration { + trigger_events = "${var.trigger_events}" + trigger_name = "${var.app_name}-${var.environment}" + trigger_target_arn = "${var.trigger_target_arn}" + } +} diff --git a/deployment-group-blue-green/variables.tf b/deployment-group-blue-green/variables.tf new file mode 100644 index 0000000..478d38b --- /dev/null +++ b/deployment-group-blue-green/variables.tf @@ -0,0 +1,47 @@ +variable "environment" { + description = "Environment where your codedeploy deployment group is used for" +} + +variable "app_name" { + description = "Name of the app" +} + +variable "service_role_arn" { + description = "IAM role that is used by the deployment group" +} + +variable "autoscaling_groups" { + type = "list" + description = "Autoscaling groups you want to attach to the deployment group" +} + +variable "rollback_enabled" { + description = "Whether to enable auto rollback" + default = false +} + +variable "rollback_events" { + description = "The event types that trigger a rollback" + type = "list" + default = ["DEPLOYMENT_FAILURE"] +} + +variable "trigger_events" { + description = "events that can trigger the notifications" + type = "list" + default = ["DeploymentStop", "DeploymentRollback", "DeploymentSuccess", "DeploymentFailure", "DeploymentStart"] +} + +variable "trigger_target_arn" { + description = "ARN of the target group" +} + +variable "action_on_timeout" { + description = "When to reroute traffic from an original environment to a replacement environment in a blue/green deployment" + default = "CONTINUE_DEPLOYMENT" +} + +variable "terminate_blue_instances_on_deployment_success" { + description = " The action to take on instances in the original environment after a successful blue/green deployment" + default = "KEEP_ALIVE" +}