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
f0d06218
Commit
f0d06218
authored
Sep 24, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: default user var values needn't be strings [GH-456]
parent
9cb39733
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
11 deletions
+28
-11
CHANGELOG.md
CHANGELOG.md
+2
-0
packer/template.go
packer/template.go
+15
-9
packer/template_test.go
packer/template_test.go
+11
-2
No files found.
CHANGELOG.md
View file @
f0d06218
## 0.3.9 (unreleased)
## 0.3.9 (unreleased)
BUG FIXES:
*
core: default user variable values don't need to be strings. [GH-456]
## 0.3.8 (September 22, 2013)
## 0.3.8 (September 22, 2013)
...
...
packer/template.go
View file @
f0d06218
...
@@ -124,18 +124,24 @@ func ParseTemplate(data []byte) (t *Template, err error) {
...
@@ -124,18 +124,24 @@ func ParseTemplate(data []byte) (t *Template, err error) {
// Gather all the variables
// Gather all the variables
for
k
,
v
:=
range
rawTpl
.
Variables
{
for
k
,
v
:=
range
rawTpl
.
Variables
{
var
variable
RawVariable
var
variable
RawVariable
variable
.
Default
=
""
variable
.
Required
=
v
==
nil
variable
.
Required
=
v
==
nil
if
v
!=
nil
{
// Create a new mapstructure decoder in order to decode the default
def
,
ok
:=
v
.
(
string
)
// value since this is the only value in the regular template that
if
!
ok
{
// can be weakly typed.
errors
=
append
(
errors
,
decoder
,
err
:=
mapstructure
.
NewDecoder
(
&
mapstructure
.
DecoderConfig
{
fmt
.
Errorf
(
"variable '%s': default value must be string or null"
,
k
))
Result
:
&
variable
.
Default
,
continue
WeaklyTypedInput
:
true
,
}
})
if
err
!=
nil
{
// This should never happen.
panic
(
err
)
}
variable
.
Default
=
def
err
=
decoder
.
Decode
(
v
)
if
err
!=
nil
{
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Error decoding default value for user var '%s': %s"
,
k
,
err
))
}
}
t
.
Variables
[
k
]
=
variable
t
.
Variables
[
k
]
=
variable
...
...
packer/template_test.go
View file @
f0d06218
...
@@ -391,7 +391,8 @@ func TestParseTemplate_Variables(t *testing.T) {
...
@@ -391,7 +391,8 @@ func TestParseTemplate_Variables(t *testing.T) {
{
{
"variables": {
"variables": {
"foo": "bar",
"foo": "bar",
"bar": null
"bar": null,
"baz": 27
},
},
"builders": [{"type": "something"}]
"builders": [{"type": "something"}]
...
@@ -403,7 +404,7 @@ func TestParseTemplate_Variables(t *testing.T) {
...
@@ -403,7 +404,7 @@ func TestParseTemplate_Variables(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
if
result
.
Variables
==
nil
||
len
(
result
.
Variables
)
!=
2
{
if
result
.
Variables
==
nil
||
len
(
result
.
Variables
)
!=
3
{
t
.
Fatalf
(
"bad vars: %#v"
,
result
.
Variables
)
t
.
Fatalf
(
"bad vars: %#v"
,
result
.
Variables
)
}
}
...
@@ -422,6 +423,14 @@ func TestParseTemplate_Variables(t *testing.T) {
...
@@ -422,6 +423,14 @@ func TestParseTemplate_Variables(t *testing.T) {
if
!
result
.
Variables
[
"bar"
]
.
Required
{
if
!
result
.
Variables
[
"bar"
]
.
Required
{
t
.
Fatal
(
"bar should be required"
)
t
.
Fatal
(
"bar should be required"
)
}
}
if
result
.
Variables
[
"baz"
]
.
Default
!=
"27"
{
t
.
Fatal
(
"default should be empty"
)
}
if
result
.
Variables
[
"baz"
]
.
Required
{
t
.
Fatal
(
"baz should not be required"
)
}
}
}
func
TestParseTemplate_variablesBadDefault
(
t
*
testing
.
T
)
{
func
TestParseTemplate_variablesBadDefault
(
t
*
testing
.
T
)
{
...
...
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