Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoHCL output attribute value without string quotes ? #610

Closed
pr-ish opened this issue May 12, 2023 · 1 comment
Closed

GoHCL output attribute value without string quotes ? #610

pr-ish opened this issue May 12, 2023 · 1 comment

Comments

@pr-ish
Copy link

pr-ish commented May 12, 2023

I'm trying to generate HCL using gohcl, and was wondering how to make sure the generator does not put quotes around strings.

resource "github_team_repository" "team1_repo1_access" {
    team_id = github_team.team1.id
    repository = github_repository.repo1.name
    permission = "push"
}

If I use the following struct,

type ResGithubTeamRepo struct {
	ResTypeLabel string `hcl:",label"`
	ResId        string `hcl:",label"`
	TeamId       string `hcl:"team_id"`
	Repository   string `hcl:"repository"`
	Permission   string `hcl:"permission"`
}

Then all fields would be quoted in the output.

What tags would I need to ensure that team_id and repository is not double quoted ?
I couldn't find any info on the different types of tags that are supported.

@apparentlymart
Copy link
Contributor

Hi @pr-ish,

gohcl is a high-level abstraction for simple cases primarily involving static values, and so it does not support all possible expression types such as references to variables.

To generate something like this you'll need to use the lower-level hclwrite API, which gives more detailed control over the expressions in the output.

The "GenerateFromScratch" example shown in the documentation includes a mixture of constant values and references to variables ("traversals" in HCL's terminology), so hopefully you can see from that example how to adapt it to produce a structure like you've shown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants