Skip to content

Commit

Permalink
Allow enabling cloudwatch auto scaling group metrics collection for H…
Browse files Browse the repository at this point in the history
…A mode
  • Loading branch information
denvazh committed Feb 28, 2024
1 parent 79983a3 commit 2a0cb73
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module "fck-nat" {
vpc_id = "vpc-abc1234"
subnet_id = "subnet-abc1234"
# ha_mode = true # Enables high-availability mode
# ha_mode_enabled_metrics = ["GroupInServiceInstances"] # Enables specified Cloudwatch metrics collection for high-availability mode
# eip_allocation_ids = ["eipalloc-abc1234"] # Allocation ID of an existing EIP
# use_cloudwatch_agent = true # Enables Cloudwatch agent and have metrics reported
Expand Down Expand Up @@ -78,6 +79,7 @@ module "fck-nat" {
| <a name="input_eip_allocation_ids"></a> [eip\_allocation\_ids](#input\_eip\_allocation\_ids) | EIP allocation IDs to use for the NAT instance. Automatically assign a public IP if none is provided. Note: Currently only supports at most one EIP allocation. | `list(string)` | `[]` | no |
| <a name="input_encryption"></a> [encryption](#input\_encryption) | Whether or not to encrypt the EBS volume | `bool` | `true` | no |
| <a name="input_ha_mode"></a> [ha\_mode](#input\_ha\_mode) | Whether or not high-availability mode should be enabled via autoscaling group | `bool` | `true` | no |
| <a name="input_ha_mode_enabled_metrics"></a> [ha\_mode\_enabled\_metrics](#input\_ha\_mode\_enabled\_metrics) | Whether or not to enable autoscaling group cloudwatch metrics collection for specified metrics. Disabled by default or when no metrics were provided | `list(string)` | `[]` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Instance type to use for the NAT instance | `string` | `"t4g.micro"` | no |
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | Will use the provided KMS key ID to encrypt the EBS volume. Uses the default KMS key if none provided | `string` | `null` | no |
| <a name="input_name"></a> [name](#input\_name) | Name used for resources created within the module | `string` | n/a | yes |
Expand Down
6 changes: 6 additions & 0 deletions asg.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
asg_cw_metrics_enabled = length(var.ha_mode_enabled_metrics) >= 1
}

resource "aws_autoscaling_group" "main" {
count = var.ha_mode ? 1 : 0

Expand All @@ -8,6 +12,8 @@ resource "aws_autoscaling_group" "main" {
health_check_type = "EC2"
vpc_zone_identifier = [var.subnet_id]

enabled_metrics = local.asg_cw_metrics_enabled ? var.ha_mode_enabled_metrics : null

launch_template {
id = aws_launch_template.main.id
version = "$Latest"
Expand Down
1 change: 1 addition & 0 deletions docs/header.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module "fck-nat" {
vpc_id = "vpc-abc1234"
subnet_id = "subnet-abc1234"
# ha_mode = true # Enables high-availability mode
# ha_mode_enabled_metrics = ["GroupInServiceInstances"] # Enables specified Cloudwatch metrics collection for high-availability mode
# eip_allocation_ids = ["eipalloc-abc1234"] # Allocation ID of an existing EIP
# use_cloudwatch_agent = true # Enables Cloudwatch agent and have metrics reported
Expand Down
3 changes: 3 additions & 0 deletions examples/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module "fck-nat" {
vpc_id = aws_vpc.main.id
subnet_id = aws_subnet.public.id
ha_mode = true
ha_mode_enabled_metrics = [
"GroupInServiceInstances"
]

update_route_tables = true
route_tables_ids = {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ variable "ha_mode" {
default = true
}

variable "ha_mode_enabled_metrics" {
description = "Whether or not to enable autoscaling group cloudwatch metrics collection for specified metrics. Disabled by default or when no metrics were provided"
type = list(string)
default = []
}

variable "instance_type" {
description = "Instance type to use for the NAT instance"
type = string
Expand Down

0 comments on commit 2a0cb73

Please sign in to comment.