AWS - Variable dimensions Names and Values in aws_cloudwatch_metric_alarm

165 views
Skip to first unread message

samuel levy

unread,
Apr 11, 2018, 9:07:20 AM4/11/18
to Terraform
Hi 

We are using Terraform v0.11.1 to maintain our AWS deployments.
We externalized our cloudwatch alarm creation in a module.

resource "aws_cloudwatch_metric_alarm" "metric_alarms" {
count = "${length(var.service_asg_config)*(1-var.is_sqs_based_dimension)}"
alarm_name = "${var.cluster}-${var.name}-${element(split("=",element(split(",",var.service_asg_config[count.index]),1)),1)}-${element(split("=",element(split(",",var.service_asg_config[count.index]),2)),1)}-${element(split("=",element(split(",",var.service_asg_config[count.index]),6)),1)}"
alarm_description = "This alarm monitors if ${var.cluster}-${var.name} ${element(split("=",element(split(",",var.service_asg_config[count.index]),1)),1)} ${element(split("=",element(split(",",var.service_asg_config[count.index]),2)),1)} ${element(split("=",element(split(",",var.service_asg_config[count.index]),6)),1)}"
comparison_operator = "${element(split("=",element(split(",",var.service_asg_config[count.index]),2)),1)}"
evaluation_periods = "${element(split("=",element(split(",",var.service_asg_config[count.index]),4)),1)}"
metric_name = "${element(split("=",element(split(",",var.service_asg_config[count.index]),1)),1)}"
namespace = "${element(split("=",element(split(",",var.service_asg_config[count.index]),0)),1)}"
period = "${element(split("=",element(split(",",var.service_asg_config[count.index]),5)),1)}"
statistic = "${element(split("=",element(split(",",var.service_asg_config[count.index]),3)),1)}"
threshold = "${element(split("=",element(split(",",var.service_asg_config[count.index]),6)),1)}"

dimensions {
ClusterName = "${var.cluster}"
ServiceName = "${var.name}"
}

alarm_actions = ["${aws_appautoscaling_policy.scale_action.*.arn[count.index]}"]

depends_on = ["aws_appautoscaling_policy.scale_action"]
}

One of the limitations we are hitting is regarding the dimensions definition.

Ideally we would like to be able to have them also fully parametrised  (number of dimensions, names and values should be all modularised), for the moment we can't find a proper way to pass a full map to the module and use it to define the dimensions.

I tried a lot of things, searched a lot but couldn't find any solution for that, is it a limitation ? Is there some way to do so?

Many thanks

Sam

erik MOLNAR

unread,
Jun 13, 2019, 9:03:54 AM6/13/19
to Terraform
Were you ever able to figure this out? I am trying to make a generic CW module and I am running into issues with the dimensions as well. I tried to make it a simple variable and have not had success. I hate to have to create a different module for each dimension we want to use. There has to be a better way, but I have not found one yet.

Thanks,

Erik
Reply all
Reply to author
Forward
0 new messages