Skip to content

Commit

Permalink
Metrics collection for ASG
Browse files Browse the repository at this point in the history
  • Loading branch information
RaJiska committed Jun 17, 2024
1 parent 2a0cb73 commit 17927fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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 @@ -79,7 +78,6 @@ 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 Expand Up @@ -115,4 +113,4 @@ module "fck-nat" {
| <a name="output_security_group_id"></a> [security\_group\_id](#output\_security\_group\_id) | Deprecated. The ID of the security group used by fck-nat ENIs |
| <a name="output_security_group_ids"></a> [security\_group\_ids](#output\_security\_group\_ids) | List of security group IDs used by fck-nat ENIs |
| <a name="output_subnet_id"></a> [subnet\_id](#output\_subnet\_id) | Subnet ID to which the fck-nat instance is deployed into |
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | VPC ID to which the fck-nat instance is deployed into |
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | VPC ID to which the fck-nat instance is deployed into |
29 changes: 23 additions & 6 deletions asg.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
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 @@ -12,8 +8,6 @@ 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 All @@ -35,6 +29,29 @@ resource "aws_autoscaling_group" "main" {
}
}

enabled_metrics = [
"GroupMinSize",
"GroupMaxSize",
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupPendingInstances",
"GroupStandbyInstances",
"GroupTerminatingInstances",
"GroupTotalInstances",
"GroupInServiceCapacity",
"GroupPendingCapacity",
"GroupStandbyCapacity",
"GroupTerminatingCapacity",
"GroupTotalCapacity",
"WarmPoolDesiredCapacity",
"WarmPoolWarmedCapacity",
"WarmPoolPendingCapacity",
"WarmPoolTerminatingCapacity",
"WarmPoolTotalCapacity",
"GroupAndWarmPoolDesiredCapacity",
"GroupAndWarmPoolTotalCapacity"
]

timeouts {
delete = "15m"
}
Expand Down
1 change: 0 additions & 1 deletion docs/header.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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: 0 additions & 3 deletions examples/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ 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: 0 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ 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 17927fa

Please sign in to comment.