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

bug: TF tries to apply null on each run. #37

Closed
stevie- opened this issue Jul 19, 2024 · 0 comments · Fixed by #38
Closed

bug: TF tries to apply null on each run. #37

stevie- opened this issue Jul 19, 2024 · 0 comments · Fixed by #38

Comments

@stevie-
Copy link

stevie- commented Jul 19, 2024

if sns_topic is not set, the default is empty string "".
This leads to null as an element added to the list which is a NOOP change.
On each run, TF detects a drift and tries to add it.

we are using https://github.com/cn-terraform/terraform-aws-ecs-fargate-service
version "2.0.43"

which uses this module version "1.0.9"

tf plan

# module.ecs_service.module.ecs-autoscaling[0].aws_cloudwatch_metric_alarm.cpu_high will be updated in-place
  ~ resource "aws_cloudwatch_metric_alarm" "cpu_high" {
      ~ alarm_actions                         = [
          + null,
            # (1 unchanged element hidden)
        ]

better implemention would be this

  alarm_actions = compact([
    aws_appautoscaling_policy.scale_up_policy.arn,
    var.sns_topic_arn != "" ? var.sns_topic_arn : ""
  ])

or

  alarm_actions = concat(
  [
    aws_appautoscaling_policy.scale_up_policy.arn,
  ],
  var.sns_topic_arn != "" ? [var.sns_topic_arn] : [],
  )

PS:
there is no way, to set sns_topic_arn within the service module.
You may want to add the variable.

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

Successfully merging a pull request may close this issue.

1 participant