Skip to content

Commit

Permalink
feat: Support Alarm Specification in Instance Refresh Preferences (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
magreenbaum committed Jun 3, 2024
1 parent ef3b1b9 commit 8c319c0
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ Note: the default behavior of the module is to create an autoscaling group and l
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.45 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.45 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |

## Modules

Expand Down
5 changes: 3 additions & 2 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.45 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.45 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_alb"></a> [alb](#module\_alb) | terraform-aws-modules/alb/aws | ~> 9.0 |
| <a name="module_asg_sg"></a> [asg\_sg](#module\_asg\_sg) | terraform-aws-modules/security-group/aws | ~> 5.0 |
| <a name="module_auto_rollback"></a> [auto\_rollback](#module\_auto\_rollback) | terraform-aws-modules/cloudwatch/aws//modules/metric-alarm | ~> 4.3 |
| <a name="module_complete"></a> [complete](#module\_complete) | ../../ | n/a |
| <a name="module_default"></a> [default](#module\_default) | ../../ | n/a |
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
Expand Down
24 changes: 24 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ module "complete" {
scale_in_protected_instances = "Refresh"
standby_instances = "Terminate"
skip_matching = false
alarm_specification = {
alarms = [module.auto_rollback.cloudwatch_metric_alarm_id]
}
}
triggers = ["tag"]
}
Expand Down Expand Up @@ -983,3 +986,24 @@ module "step_scaling_alarm" {

alarm_actions = [module.complete.autoscaling_policy_arns["scale-out"]]
}

module "auto_rollback" {
source = "terraform-aws-modules/cloudwatch/aws//modules/metric-alarm"
version = "~> 4.3"

alarm_name = "${local.name}-auto-rollback"
alarm_description = "Auto Rollback Alarm Example"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
threshold = 0
period = 60
treat_missing_data = "notBreaching"

namespace = "AWS/ApplicationELB"
metric_name = "HTTPCode_ELB_5XX_Count"
statistic = "Sum"

dimensions = {
LoadBalancer = module.alb.arn_suffix
}
}
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.45"
version = ">= 5.46"
}
}
}
16 changes: 16 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ resource "aws_autoscaling_group" "this" {
dynamic "preferences" {
for_each = try([instance_refresh.value.preferences], [])
content {

dynamic "alarm_specification" {
for_each = try([preferences.value.alarm_specification], [])
content {
alarms = alarm_specification.value.alarms
}
}

checkpoint_delay = try(preferences.value.checkpoint_delay, null)
checkpoint_percentages = try(preferences.value.checkpoint_percentages, null)
instance_warmup = try(preferences.value.instance_warmup, null)
Expand Down Expand Up @@ -702,6 +710,14 @@ resource "aws_autoscaling_group" "idc" {
dynamic "preferences" {
for_each = try([instance_refresh.value.preferences], [])
content {

dynamic "alarm_specification" {
for_each = try([preferences.value.alarm_specification], [])
content {
alarms = alarm_specification.value.alarms
}
}

checkpoint_delay = try(preferences.value.checkpoint_delay, null)
checkpoint_percentages = try(preferences.value.checkpoint_percentages, null)
instance_warmup = try(preferences.value.instance_warmup, null)
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.45"
version = ">= 5.46"
}
}
}

0 comments on commit 8c319c0

Please sign in to comment.