Skip to content

Commit 2071fc6

Browse files
authored
fix(deployment): use dynamic blocks for alarm and rollback configurations in CodeDeploy (#83)
1 parent 95ed278 commit 2071fc6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

modules/deployment/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ to update the function code and CodeDeploy to deploy the new function version.
1818
- creation of IAM roles with permissions following the [principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege) for CodePipeline, CodeBuild and CodeDeploy
1919
or bring your own roles
2020
- SNS topic for [AWS CodeStar Notifications](https://docs.aws.amazon.com/dtconsole/latest/userguide/welcome.html) of CodePipeline events, or bring your own SNS topic
21-
- `BeforeAllowTraffic` and `AfterAllowTraffic` [hooks](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-lambda) CodeDeploy
21+
- `BeforeAllowTraffic` and `AfterAllowTraffic` [hooks](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-lambda) for CodeDeploy
2222
- AWS predefined and custom [deployment configurations](https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-configurations.html) for CodeDeploy
2323
- automatic [rollbacks](https://docs.aws.amazon.com/codedeploy/latest/userguide/deployments-rollback-and-redeploy.html#deployments-rollback-and-redeploy-automatic-rollbacks) and support of [CloudWatch alarms](https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-groups-configure-advanced-options.html) to stop deployments
2424

modules/deployment/codedeploy.tf

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ resource "aws_codedeploy_deployment_group" "this" {
99
deployment_group_name = var.alias_name
1010
service_role_arn = aws_iam_role.codedeploy.arn
1111

12-
alarm_configuration {
13-
alarms = var.codedeploy_deployment_group_alarm_configuration_alarms
14-
enabled = var.codedeploy_deployment_group_alarm_configuration_enabled
15-
ignore_poll_alarm_failure = var.codedeploy_deployment_group_alarm_configuration_ignore_poll_alarm_failure
12+
dynamic "alarm_configuration" {
13+
for_each = var.codedeploy_deployment_group_alarm_configuration_enabled ? [true] : []
14+
content {
15+
alarms = var.codedeploy_deployment_group_alarm_configuration_alarms
16+
enabled = var.codedeploy_deployment_group_alarm_configuration_enabled
17+
ignore_poll_alarm_failure = var.codedeploy_deployment_group_alarm_configuration_ignore_poll_alarm_failure
18+
}
1619
}
1720

18-
auto_rollback_configuration {
19-
enabled = var.codedeploy_deployment_group_auto_rollback_configuration_enabled
20-
events = var.codedeploy_deployment_group_auto_rollback_configuration_events
21+
dynamic "auto_rollback_configuration" {
22+
for_each = var.codedeploy_deployment_group_auto_rollback_configuration_enabled ? [true] : []
23+
content {
24+
enabled = var.codedeploy_deployment_group_auto_rollback_configuration_enabled
25+
events = var.codedeploy_deployment_group_auto_rollback_configuration_events
26+
}
2127
}
2228

2329
deployment_style {

0 commit comments

Comments
 (0)