diff --git a/README.md b/README.md
index 79f03e5..ba58a8f 100644
--- a/README.md
+++ b/README.md
@@ -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
@@ -78,6 +79,7 @@ module "fck-nat" {
| [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 |
| [encryption](#input\_encryption) | Whether or not to encrypt the EBS volume | `bool` | `true` | no |
| [ha\_mode](#input\_ha\_mode) | Whether or not high-availability mode should be enabled via autoscaling group | `bool` | `true` | no |
+| [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 |
| [instance\_type](#input\_instance\_type) | Instance type to use for the NAT instance | `string` | `"t4g.micro"` | no |
| [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 |
| [name](#input\_name) | Name used for resources created within the module | `string` | n/a | yes |
diff --git a/asg.tf b/asg.tf
index ba0724a..4c895b9 100644
--- a/asg.tf
+++ b/asg.tf
@@ -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
@@ -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"
diff --git a/docs/header.md b/docs/header.md
index b7fd0a0..4896da7 100644
--- a/docs/header.md
+++ b/docs/header.md
@@ -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
diff --git a/examples/full/main.tf b/examples/full/main.tf
index 0943ad9..9aa0afd 100644
--- a/examples/full/main.tf
+++ b/examples/full/main.tf
@@ -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 = {
diff --git a/variables.tf b/variables.tf
index 8d01029..0789a16 100644
--- a/variables.tf
+++ b/variables.tf
@@ -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