Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
facbb657
Commit
facbb657
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template: allow _ prefix to root level keys for comments [GH-2066]
parent
f1cef0ba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
2 deletions
+40
-2
template/parse.go
template/parse.go
+7
-2
template/parse_test.go
template/parse_test.go
+13
-0
template/test-fixtures/parse-comment.json
template/test-fixtures/parse-comment.json
+4
-0
website/source/docs/templates/introduction.html.markdown
website/source/docs/templates/introduction.html.markdown
+16
-0
No files found.
template/parse.go
View file @
facbb657
...
...
@@ -291,11 +291,16 @@ func Parse(r io.Reader) (*Template, error) {
if
len
(
md
.
Unused
)
>
0
{
sort
.
Strings
(
md
.
Unused
)
for
_
,
unused
:=
range
md
.
Unused
{
// Ignore keys starting with '_' as comments
if
unused
[
0
]
==
'_'
{
continue
}
err
=
multierror
.
Append
(
err
,
fmt
.
Errorf
(
"Unknown root level key in template: '%s'"
,
unused
))
}
// Return early for these errors
}
if
err
!=
nil
{
return
nil
,
err
}
...
...
template/parse_test.go
View file @
facbb657
...
...
@@ -303,6 +303,19 @@ func TestParse(t *testing.T) {
},
false
,
},
{
"parse-comment.json"
,
&
Template
{
Builders
:
map
[
string
]
*
Builder
{
"something"
:
&
Builder
{
Name
:
"something"
,
Type
:
"something"
,
},
},
},
false
,
},
}
for
_
,
tc
:=
range
cases
{
...
...
template/test-fixtures/parse-comment.json
0 → 100644
View file @
facbb657
{
"_info"
:
"foo"
,
"builders"
:
[{
"type"
:
"something"
}]
}
website/source/docs/templates/introduction.html.markdown
View file @
facbb657
...
...
@@ -58,6 +58,22 @@ Along with each key, it is noted whether it is required or not.
For more information on how to define and use user variables, read the
sub-section on
[
user variables in templates
](
/docs/templates/user-variables.html
)
.
## Comments
JSON doesn't support comments and Packer reports unknown keys as validation
errors. If you'd like to comment your template, you can prefix a _root level_
key with an underscore. Example:
```
javascript
{
"
_comment
"
:
"
This is a comment
"
,
"
builders
"
:
[{}]
}
```
**Important:**
Only _root level_ keys can be underscore prefixed. Keys within
builders, provisioners, etc. will still result in validation errors.
## Example Template
Below is an example of a basic template that is nearly fully functional. It is just
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment