How to input type object variables in Terragrunt hcl files?

Hey Guys I have the following variable in my module.

variable "cluster_autoscaling" {
  type = object({
    enabled       = bool
    min_cpu_cores = number
    max_cpu_cores = number
    min_memory_gb = number
    max_memory_gb = number
    gpu_resources = list(object({ resource_type = string, minimum = number, maximum = number }))
  })
  default = {
    enabled       = false
    max_cpu_cores = 0
    min_cpu_cores = 0
    max_memory_gb = 0
    min_memory_gb = 0
    gpu_resources = []
  }

And in my terragrunt.hcl file I would like to pass a different value for the enabled. But I can’t find a way to make it work.

This is how my terragrunt.hcl file looks like:

inputs = merge(
  {
    name                          = local.parent.inputs.name
    network                       = dependency.vpc.outputs.network_name
    project_id                    = local.parent.inputs.project_name
    cluster_autoscaling.enabled   = true
  },

If I try like above gives me this error:
Ambiguous attribute key; If this expression is intended to be a reference, wrap it in parentheses. If it's instead intended as a literal name containing periods, wrap it in quotes to create a string literal.

If I try like this

cluster_autoscaling = [{ "enabled" = true }]

Gives me:

variable "cluster_autoscaling" {
│ 
│ Unsuitable value for var.cluster_autoscaling set using the
│ TF_VAR_cluster_autoscaling environment variable: object required.

There’s a way to make it work?

>Solution :

Have you tried just like this:

cluster_autoscaling =
{
  enabled       = true
  min_cpu_cores = 1
  max_cpu_cores = 4
  min_memory_gb = 1
  max_memory_gb = 8
  gpu_resources = []
}

Leave a Reply