IssueRaiser

Feature Request: Defining variables/locals inside a resource block

I trying to define some variables inside a resource so that it can be referred when needed and this resource block is in the loop so I can't define these as `locals` outside the resource. Is this possible in some way?: ```hcl resource "aws_cloudwatch_metric_alarm" "httpcode_target_5xx_count" { locals { len = "${length(data.aws_lb.this.target_group_arn_suffixes)}" current_index = "${element(data.aws_lb.this.target_group_arn_suffixes, count.index)}" current_thresold = "${var.target_5xx_thresold["$local.current_index"] != "" ? var.target_5xx_thresold["$local.current_index"] : "${var.lb_5xx_thresold}"}" } count = "${local.len}" alarm_name = "${var.prefix_resources}: ALB-5XX-ERROR: TARGET: ${replace(local.current_index,"/(targetgroup/)|(/\\w+$)/","")}" comparison_operator = "GreaterThanThreshold" evaluation_periods = "${local.evaluation_periods}" metric_name = "HTTPCode_Target_5XX_Count" namespace = "AWS/ApplicationELB" period = "300" statistic = "Sum" threshold = "${local.current_thresold}" treat_missing_data = "missing" alarm_description = "HTTPCode 5XX count for ${local.current_index} over ${local.current_thresold} last 300 seconds over 1 period(s)" alarm_actions = "${concat(var.notify_sns_arns, aws_sns_topic.opsgenie_sns_topic.arn)}" dimensions = { "TargetGroup" = "${lo

Posted by rahulwa on Mar 13, 2019, 4:15 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Other)

Feature Request: Defining variables/locals inside a resource block

rahulwaMar 13, 2019, 4:15 PM

I trying to define some variables inside a resource so that it can be referred when needed and this resource block is in the loop so I can't define these as `locals` outside the resource. Is this possible in some way?: ```hcl resource "aws_cloudwatch_metric_alarm" "httpcode_target_5xx_count" { locals { len = "${length(data.aws_lb.this.target_group_arn_suffixes)}" current_index = "${element(data.aws_lb.this.target_group_arn_suffixes, count.index)}" current_thresold = "${var.target_5xx_thresold["$local.current_index"] != "" ? var.target_5xx_thresold["$local.current_index"] : "${var.lb_5xx_thresold}"}" } count = "${local.len}" alarm_name = "${var.prefix_resources}: ALB-5XX-ERROR: TARGET: ${replace(local.current_index,"/(targetgroup/)|(/\\w+$)/","")}" comparison_operator = "GreaterThanThreshold" evaluation_periods = "${local.evaluation_periods}" metric_name = "HTTPCode_Target_5XX_Count" namespace = "AWS/ApplicationELB" period = "300" statistic = "Sum" threshold = "${local.current_thresold}" treat_missing_data = "missing" alarm_description = "HTTPCode 5XX count for ${local.current_index} over ${local.current_thresold} last 300 seconds over 1 period(s)" alarm_actions = "${concat(var.notify_sns_arns, aws_sns_topic.opsgenie_sns_topic.arn)}" dimensions = { "TargetGroup" = "${lo

Comments (0)

No comments yet. Start the discussion.

Comment on this issue