Not able to retrieve a local value from parent terragrunt.hcl file
Closed this issue · 3 comments
Describe the bug
Hello, I'm using a custom module of S3 where I can create multiple buckets with different features of it in a single terragrunt file. Our setup is as following:
--- terragrunt.hcl (root terragrunt file, where we have defined the providers, remote states)
--- common.hcl (common variables)
----- environments/
---------- aws01/
------------- account.hcl (where we define the account name variables in locals)
------------- s3/
-----------------terragrunt.hcl (child terragrunt.hcl file)
----------------- buckets.hcl
And the problem that I have is that I can not retrieve a local variable in buckets.hcl that is defined in child terragrunt.hcl file.
child terragrunt.hcl file contains:
# ------------------------------------------------------------------------------------------
# Set source terraform module
# ------------------------------------------------------------------------------------------
terraform {
source = "XXXXXXXXXXXXXXXXXXXX"
}
# ------------------------------------------------------------------------------------------
# Run Default terragrunt (create providers and define remote state)
# ------------------------------------------------------------------------------------------
include {
path = find_in_parent_folders()
}
# ------------------------------------------------------------------------------------------
# Load common values
# ------------------------------------------------------------------------------------------
locals {
account_details = read_terragrunt_config(find_in_parent_folders("account.hcl"))
common_vars = read_terragrunt_config(find_in_parent_folders("common.hcl"))
account_name = local.account_details.locals.account_name
account_id = local.common_vars.locals.accounts[local.account_name]
s3_buckets_raw = read_terragrunt_config("./buckets.hcl")
s3_buckets = local.s3_buckets_raw.locals.s3_buckets
}
# ------------------------------------------------------------------------------------------
# Specify module input variables
# ------------------------------------------------------------------------------------------
inputs = {
s3_buckets = local.s3_buckets
}
And buckets.hcl file:
locals {
common_vars = read_terragrunt_config("./terragrunt.hcl")
account_id = local.common_vars.locals.account_id
s3_buckets = {
XXXXXXXXXXXX = {
name = "XXXXXXXXX"
force_destroy = true
tags = {}
versioning_status = "Disabled"
public_access_block = {
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
ownership_controls = {
object_ownership = "BucketOwnerPreferred"
}
lifecycle_rules = []
lambda_details = {}
bucket_policy = {
statements = [{
sid = "AllowInspector"
effect = "Allow"
actions = [
"s3:PutObject",
"s3:PutObjectAcl",
"s3:AbortMultipartUpload"
]
resources = [
"arn:aws:s3:::XXXXXXXXXXXXX/*"
]
principals = [
{
type = "Service"
identifiers = ["inspector2.amazonaws.com"]
}
]
condition = [
{
test = "StringEquals"
variable = "aws:SourceAccount"
values = [
(local.account_id)
]
},
]
}]
}
},
}
}
I'm trying to retrieve the local.account_id but when i run terragrunt plan it's crashes
Running with following OS:
$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2025-06-30"
Expected behavior
I would expect terragrunt able to retrieve the value in bucket.hcl file for my local account_id, but having this error:
runtime: sp=0xc10dc00f48 stack=[0xc10dc00000, 0xc12dc00000]
fatal error: stack overflow
runtime stack:
runtime.throw({0x16065de?, 0x23091c0?})
/usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0xc000691e18 sp=0xc000691de8 pc=0x435f3d
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1105 +0x5bd fp=0xc000691fc8 sp=0xc000691e18 pc=0x44fdbd
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:574 +0x8b fp=0xc000691fd0 sp=0xc000691fc8 pc=0x46700b
goroutine 1 [running]:
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseExpressionTerm(0xc10dc2adf8)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:944 +0x2429 fp=0xc10dc00f58 sp=0xc10dc00f50 pc=0x694889
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseExpressionWithTraversals(0x0?)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:619 +0x25 fp=0xc10dc00fd8 sp=0xc10dc00f58 pc=0x68d125
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0x0?, {0xc000122e08?, 0x0?, 0x0?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:549 +0x139 fp=0xc10dc01508 sp=0xc10dc00fd8 pc=0x68c5d9
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122e08?, 0x1?, 0x1?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc01a38 sp=0xc10dc01508 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122e00?, 0x0?, 0x0?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc01f68 sp=0xc10dc01a38 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122df8?, 0x60?, 0x2e?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc02498 sp=0xc10dc01f68 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122df0?, 0x40b30b?, 0x15440e0?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc029c8 sp=0xc10dc02498 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122de8?, 0xc18f4c2a20?, 0x60?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc02ef8 sp=0xc10dc029c8 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122de0?, 0x5?, 0x14c?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc03428 sp=0xc10dc02ef8 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseTernaryConditional(0xc10dc2adf8)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:495 +0xfe fp=0xc10dc039c8 sp=0xc10dc03428 pc=0x68b89e
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).ParseExpression(...)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:479
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseExpressionTerm(0xc10dc2adf8)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:953 +0x233 fp=0xc10dc04920 sp=0xc10dc039c8 pc=0x692693
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseExpressionWithTraversals(0xc000680000?)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:619 +0x25 fp=0xc10dc049a0 sp=0xc10dc04920 pc=0x68d125
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0x13f5c80?, {0xc000122e08?, 0x5d?, 0x20c?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:549 +0x139 fp=0xc10dc04ed0 sp=0xc10dc049a0 pc=0x68c5d9
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122e08?, 0x5d?, 0x20c?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc05400 sp=0xc10dc04ed0 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122e00?, 0x5d?, 0xc10dc05a00?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc05930 sp=0xc10dc05400 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122df8?, 0x5d?, 0x0?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc05e60 sp=0xc10dc05930 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122df0?, 0x5d?, 0x20c?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc06390 sp=0xc10dc05e60 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122de8?, 0x5d?, 0x20c?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc068c0 sp=0xc10dc06390 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122de0?, 0x1?, 0x14d?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc06df0 sp=0xc10dc068c0 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseTernaryConditional(0xc10dc2adf8)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:495 +0xfe fp=0xc10dc07390 sp=0xc10dc06df0 pc=0x68b89e
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).ParseExpression(...)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:479
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseTupleCons(0xc10dc2adf8)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:1285 +0x514 fp=0xc10dc07a30 sp=0xc10dc07390 pc=0x696474
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseExpressionTerm(0xc10dc2adf8)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:1089 +0x1d33 fp=0xc10dc08988 sp=0xc10dc07a30 pc=0x694193
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseExpressionWithTraversals(0x29?)
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:619 +0x25 fp=0xc10dc08a08 sp=0xc10dc08988 pc=0x68d125
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0x13f5c80?, {0xc000122e08?, 0x3d?, 0x161?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:549 +0x139 fp=0xc10dc08f38 sp=0xc10dc08a08 pc=0x68c5d9
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122e08?, 0x3d?, 0x161?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc09468 sp=0xc10dc08f38 pc=0x68c525
github.com/hashicorp/hcl/v2/hclsyntax.(*parser).parseBinaryOps(0xc10dc2adf8, {0xc000122e00?, 0x3d?, 0x161?})
/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.17.0/hclsyntax/parser.go:563 +0x85 fp=0xc10dc09998 sp=0xc10dc09468 pc=0x68c525
tagging @yorinasub17
Forgot to add, that works and able to retrieve the (local.account_id) when I move the s3_buckets mappings to inputs of a child terragrunt.hcl file. But would like to have all s3_buckets mappings in a different file
Created the issue in a wrong repository. - gruntwork-io/terragrunt#3008