Skip to content

Commit

Permalink
adds blue-green codedeploy option (#15)
Browse files Browse the repository at this point in the history
* adds blue-green codedeploy option

* add example
  • Loading branch information
Luca Venturelli committed Apr 12, 2019
1 parent bb7b3ec commit d3846c3
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `<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 | `<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
Expand Down
33 changes: 33 additions & 0 deletions deployment-group-blue-green/main.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
}
47 changes: 47 additions & 0 deletions deployment-group-blue-green/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit d3846c3

Please sign in to comment.