Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable_autoscaling: Issue with CloudWatch Metric alarm_actions Handling Null Values #102

Open
adrian-slowik-zaven opened this issue Jul 2, 2024 · 1 comment

Comments

@adrian-slowik-zaven
Copy link

Provider and Module Versions
AWS Provider Version: ~> 5.0
Module Version: 2.0.43

Description
I am experiencing an issue with the terraform-aws-ecs-fargate-service module, specifically with the handling of alarm_actions in CloudWatch metric alarms. The module is calling another module (cn-terraform/ecs-service-autoscaling/aws) which is responsible for setting up auto-scaling.

Every time I execute terraform apply, I see the following changes in the plan, even though no actual changes are made to the infrastructure:

# module.ecs_service_web-api.module.ecs-fargate-service.module.ecs-autoscaling[0].aws_cloudwatch_metric_alarm.api-cpu_high will be updated in-place
~ resource "aws_cloudwatch_metric_alarm" "api-cpu_high" {
    ~ alarm_actions                         = [
        + null,
          # (1 unchanged element hidden)
      ]
      id                                    = "api-cpu-high"
      tags                                  = {
          "Environment" = "dev"
          "Project"     = "example-project"
      }
      # (21 unchanged attributes hidden)
  }

Module Call
Here is how the ecs-autoscaling module is being called:

module "ecs-autoscaling" {
  count = var.enable_autoscaling ? 1 : 0

  source  = "cn-terraform/ecs-service-autoscaling/aws"
  version = "1.0.9"

  name_prefix               = var.name_prefix
  ecs_cluster_name          = var.ecs_cluster_name
  ecs_service_name          = aws_ecs_service.service.name
  max_cpu_threshold         = var.max_cpu_threshold
  min_cpu_threshold         = var.min_cpu_threshold
  max_cpu_evaluation_period = var.max_cpu_evaluation_period
  min_cpu_evaluation_period = var.min_cpu_evaluation_period
  max_cpu_period            = var.max_cpu_period
  min_cpu_period            = var.min_cpu_period
  scale_target_max_capacity = var.scale_target_max_capacity
  scale_target_min_capacity = var.scale_target_min_capacity
  tags                      = var.tags
}

Problematic Section in the ecs-autoscaling Module

The issue seems to be originating from the following part of the ecs-autoscaling module:

resource "aws_cloudwatch_metric_alarm" "cpu_low" {
  alarm_name          = "${var.name_prefix}-cpu-low"
  comparison_operator = "LessThanOrEqualToThreshold"
  evaluation_periods  = var.min_cpu_evaluation_period
  metric_name         = "CPUUtilization"
  namespace           = "AWS/ECS"
  period              = var.min_cpu_period
  statistic           = "Average"
  threshold           = var.min_cpu_threshold
  dimensions = {
    ClusterName = var.ecs_cluster_name
    ServiceName = var.ecs_service_name
  }
  alarm_actions = [
    aws_appautoscaling_policy.scale_down_policy.arn,
    var.sns_topic_arn != "" ? var.sns_topic_arn : ""
  ]
  tags = var.tags
}

Issue
The alarm_actions attribute is supposed to include the ARN of the scaling policy and optionally an SNS topic ARN if it is provided. However, it ends up including null instead of an empty string, leading to unnecessary in-place updates in the Terraform plan.

Question
Why does the conditional expression for alarm_actions end with a null value instead of an empty string? How can this be resolved to avoid unnecessary updates?

Any help or guidance on this issue would be greatly appreciated.

@stevie-
Copy link

stevie- commented Sep 19, 2024

probably solved with cn-terraform/terraform-aws-ecs-service-autoscaling#37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants