Could someone prompt me, please? How I can declare environment?
Error: Reference to undeclared local value
on 00-init.tf line 11, in data “terraform_remote_state” “state_iam_policy_admin”:
11: key = “${local.environment}/us-west-2/01-pre-setup/iam-policy-admin/terraform.tfstate”A local value with the name “environment” has not been declared.
terragrunt.hcl
locals {
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
environment = local.environment_vars.locals.environment
}
include {
path = find_in_parent_folders()
}
00-init.tf
data "terraform_remote_state" "state_iam_policy_admin" {
backend = "s3"
config = {
region = "us-west-2"
bucket = "terragrunt-terraform-state-stage-us-west-2/"
key = "${local.environment}/us-west-2/01-pre-setup/iam-policy-admin/terraform.tfstate"
}
}
env.hcl
locals {
environment = “stage”
}
.
├── stage
│ ├── account.hcl
│ ├── env.hcl
│ └── us-west-2
│ ├── 01-pre-setup
│ │ └── iam-users-admin
│ │ ├── 00-init.tf
│ │ ├── 01-main.tf
│ │ ├── 99-outputs.tf
│ │ ├── backend.tf
│ │ ├── provider.tf
│ │ ├── README.md
│ │ ├── terragrunt.hcl
│ │ ├── variables.tf
│ │ └── versions.tf
│ └── region.hcl
└── terragrunt.hcl