hashicorp / hashicorp/hcl

[Question] How do I handle the following fields in the golang code?

Open
#536 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

I would like to generate the following file.

```
locals {
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
region = local.region_vars.locals.region

project = "abc-dev"
account_number = "443813933915"
services = [
"apiserver",
]
additional_statements = [
{
"Sid" : "",
"Effect" : "Allow",
"Action" : [
"secretsmanager:GetSecretValue",
"kms:Decrypt"
],
"Resource" : [
"arn:aws:secretsmanager:${local.region}:${local.account_number}:secret:*",
"arn:aws:kms:${local.region}:${local.account_number}:key/*"
]
}
]
}
```

But in my golang code, I can define a structure as following
```
type ProjectHcl struct {
Locals Locals `hcl:"locals,block"`
}

type Locals struct {
Project string `hcl:"project"`
AccountNumber string `hcl:"account_number"`
Services []string `hcl:"services"`
}
```

How can I deal with other fields `region_vars`, `region`, `additional_statements`?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the ProjectHcl and Locals declarations shown in the issue, then read the HCL decoding documentation for handling the additional fields in the example. Confirm the documented approach against the example configuration and explain how region_vars, region, and additional_statements should be represented.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.