How to declare undeclared local value in

Hi @rmalenko,

This is similar to the issue in Problems with getting inputs from dependent module outputs - is it a syntax problem? Typing?, and the solution should be the same.

You want to expose environment as a variable in 00-init.tf, and then use inputs in terragrunt.hcl to set it for terraform:

terragrunt.hcl

locals {
  environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}

include {
  path = find_in_parent_folders()
}

inputs = {
  environment = local.environment_vars.locals.environment
}

00-init.tf

variable "environment" {
  type = string
  # This is passed in from terragrunt inputs attribute
}

data "terraform_remote_state" "state_iam_policy_admin" {
  backend = "s3"
  config = {
    region = "us-west-2"
    bucket = "terragrunt-terraform-state-stage-us-west-2/"
    key = "${var.environment}/us-west-2/01-pre-setup/iam-policy-admin/terraform.tfstate"
  }
}

Best regards,
Yori

1 Like