#terragrunt - June 2023

terragruntArchived
1 messages

Terragrunt discussions
Archive: https://archive.sweetops.com/terragrunt/

Soham
Sohamover 3 years ago
I have a terragrunt config where I have this tags.hcl file under workloads/production/eu-west-1

locals {
  env_tags = {
    Environment = "Production"
    Region = "eu-west-1"
    Managed_by = "Terraform"
  }
}

Now, in the child module, I have this terragrunt.hcl file

include "root" {
  path = find_in_parent_folders()
}

locals {
  common_tags = read_terragrunt_config(find_in_parent_folders("tags.hcl"))
}

Now in my resource definition, I am trying to use the common_tags

module "ec2-instance" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "5.1.0"
  name    = "important-ec2"

  ami                         = var.ami
  instance_type               = var.instance_type
  
  tags = merge(
    locals.common_tags,
    {
    App          = "xxx"
    Role         = "yyy"
  }
  )
}

But it fails with

│ A managed resource "locals" "common_tags" has not been declared in the root
│ module.

Pretty sure I am misinterpreting the last section where I have to define it in the ec2-instance module. What I am doing wrong? I asked in another slack and think that locals cannot be passed to the TF config. Is that a right assumption?