Cloudwatch_metric_alarm how to use a var as a dimension name

attempting to create a terraform module that is customized via terragrunt config, assuming the following configs:

main.tf

/* create the cloudwatch alarm */
resource "aws_cloudwatch_metric_alarm" "alarm" {
    depends_on                  = [ aws_sns_topic.sns_alarm_topic ]
    alarm_name                  = var.cw_alarm_name
    comparison_operator         = var.cw_comparison_operator
    evaluation_periods          = var.cw_eval_period
    metric_name                 = var.cw_metric_name
    namespace                   = var.cw_namespace
    period                      = var.cw_period
    statistic                   = var.cw_statistic
    threshold                   = var.cw_alarm_threshold
    alarm_description           = var.cw_alarm_description
    alarm_actions               = [ aws_sns_topic.sns_alarm_topic.arn ]
    ok_actions                  = [ aws_sns_topic.sns_alarm_topic.arn ]
    insufficient_data_actions   = []
    treat_missing_data          = var.cw_missing_data

    dimensions = {
        (var.dimension_list)
    }

variables.tf (trimmed)

variable "dimension_list" {
    description = "Dimensions variables in 'key = value' pairs"
    default = null
    type = map(string)
}

terragrunt.hc (trimmed)l:

   dimension_list = {
        Environment = "uat"
    }

The issue is that to create a generic terraform module, I need the ability to replace the dimension assigned, which should be pulled in as a list from the terragrunt customization file.

When attempting to do the above, I get this error:

│ Error: Missing attribute value

│ on main.tf line 49, in resource “aws_cloudwatch_metric_alarm” “alarm”:
│ 48: dimensions = {
│ 49: (var.dimension_list)
│ 50: }

│ Expected an attribute value, introduced by an equals sign ("=").

Hi @jofficer,
as per my understanding the documentation includes the code-snippet you are looking for:

example = [
  for ex in var.examples: merge({
    foo = null # (or any other suitable default value)
  }, ex)
]

thanks for the reply @tbugfinder ,

I’m not clear on how I would apply this example. I tried adding this to the main.tf:

dimensions = [
        for ex in var.dimension_list : merge({
            foo = null
        }, ex)
    ]

and this to variables.tf

variable "dimension_list" {
    description = "Dimensions variables in 'key = value' pairs"
    default = null
    type = map(string)
}

but my syntax in the terragrunt.hcl does not seem correct

    dimension_list = {
        "Environment" = "uat"
    }

now receiving this error

Error: Iteration over null value

│ on main.tf line 53, in resource “aws_cloudwatch_metric_alarm” “alarm”:
│ 52: dimensions = [
│ 53: for ex in var.dimension_list : merge({
│ 54: foo = null
│ 55: }, ex)
│ 56: ]
│ ├────────────────
│ │ var.dimension_list is null

│ A null value cannot be used as the collection in a ‘for’ expression.

This rather reads like the input is not passed from terragrunt to terraform.
I’ve copied your code and actually it might be easier than pointed out before.

    .....
    treat_missing_data          = var.cw_missing_data

    dimensions = var.dimension_list
    .....

I tried with a default value of null as well as a map.