lorenzoaiello / terraform-aws-rds-alarms

This Terraform module manages Cloudwatch Alarms for an RDS instance.
https://registry.terraform.io/modules/lorenzoaiello/rds-alarms/aws
MIT License
37 stars 36 forks source link

alarm `cpu_credit_balance_too_low` causes error during `plan` when db instance does not exist yet #5

Closed hanswesterbeek closed 3 years ago

hanswesterbeek commented 3 years ago

This line:

resource "aws_cloudwatch_metric_alarm" "cpu_credit_balance_too_low" {
  count               = length(regexall("(t2|t3)", data.aws_db_instance.database.db_instance_class)) > 0 ? "1" : "0"

results in:


Error: Invalid count argument

  on .terraform/modules/mymod.rds-alarms/main.tf line 28, in resource "aws_cloudwatch_metric_alarm" "cpu_credit_balance_too_low":
  28:   count               = length(regexall("(t2|t3)", data.aws_db_instance.database.db_instance_class)) > 0 ? "1" : "0"

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.

probably the instance-class should not be read from the data provider but passed via a regular variable.

hanswesterbeek commented 3 years ago

It is hard to fix this without introducing a breaking change. The new var must be mandatory.

hanswesterbeek commented 3 years ago

Hi @lorenzoaiello... My previous PR went very quickly. Is there something you'd like to see different with this one?

lorenzoaiello commented 3 years ago

Hi @lorenzoaiello... My previous PR went very quickly. Is there something you'd like to see different with this one?

No, last time you managed to catch me with GitHub open working on something :)

Merged and cut v2 to address the breaking change. Thank you for the improvements.