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

hclwrite: generate the output it can't parse #687

Open
giautm opened this issue Jul 25, 2024 · 0 comments
Open

hclwrite: generate the output it can't parse #687

giautm opened this issue Jul 25, 2024 · 0 comments

Comments

@giautm
Copy link

giautm commented Jul 25, 2024

The input with atlas {} is parse correctly without issue, then I append new child block, it cause the issue when I parse its ouput again. Even formatted with hclwrite.Format,

func Example_Ident() {
	// This input is fine, and valid.
	f, diags := hclwrite.ParseConfig([]byte("atlas {}"), "atlas.hcl", hcl.InitialPos)
	if diags.HasErrors() {
		panic("failed to parse config")
	}
	// Append the cloud block
	f.Body().FirstMatchingBlock("atlas", nil).
		Body().AppendNewBlock("cloud", nil)
	// Format the output.
	out := hclwrite.Format(f.Bytes())
	// Parse the output to check if it's valid.
	_, diags = hclwrite.ParseConfig(out, "atlas.hcl", hcl.InitialPos)

	fmt.Println(string(out))
	fmt.Println(diags)
	// Output:
	// atlas { cloud {
	//   }
	// }
	// atlas.hcl:1,9-16: Argument definition required; A single-line block definition can contain only a single argument. If you meant to define argument "cloud", use an equals sign to assign it a value. To define a nested block, place it on a line of its own within its parent block.
}
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

1 participant