-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat: add content block on generate_hcl #220
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Codecov Report
@@ Coverage Diff @@
## main #220 +/- ##
==========================================
+ Coverage 63.59% 63.66% +0.06%
==========================================
Files 30 29 -1
Lines 5390 5403 +13
==========================================
+ Hits 3428 3440 +12
- Misses 1779 1780 +1
Partials 183 183
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
if len(block.Body.Attributes) != 0 { | ||
return errors.New("attributes are not allowed") | ||
} | ||
if len(block.Body.Blocks) != 1 { | ||
return fmt.Errorf("one 'content' block is required, got %d blocks", len(block.Body.Blocks)) | ||
} | ||
contentBlock := block.Body.Blocks[0] | ||
if contentBlock.Type != "content" { | ||
return fmt.Errorf("one 'content' block is required, got %q block", contentBlock.Type) | ||
} | ||
if len(contentBlock.Labels) > 0 { | ||
return fmt.Errorf("content block has unexpected labels: %v", contentBlock.Labels) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we manually check those... can't we use the go structures to let HCL library check this for us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then we need to define the struct/type (which is a form of manual definition also, but more descriptive) and I didn't see any immediate use for the struct since I just grab the whole content body after validation (it is dynamic, I dont know the structure of the content body), if we had more specific attributes that we need we could indeed use a Go struct with some specific fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you mentioned "Go Structures" I immediately thought of hclsimple.
Which in this case seems less helpful IMO (but quite helpful on some scenarios), but now I think maybe you meant the BodySchema.
Which could make some of the basic validation for us, will take a look (haven't used it yet, sorry for the ignorance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Co-authored-by: Tiago de Bem Natel de Moura <t.nateldemoura@gmail.com>
This PRs changes the behavior of code generation using
generate_hcl
. Instead of generating code by doing:All generated HCL must be inside the
content
block, like this:A full example: