fix this !

This commit is contained in:
Adrien Delorme 2020-03-04 12:42:56 +01:00
parent e851050774
commit 23b940dbd5
2 changed files with 9 additions and 15 deletions

View File

@ -33,13 +33,11 @@ type PackerConfig struct {
// decoder in order to tell what is the actual value of a var or a local and
// the list of defined functions.
func (cfg *PackerConfig) EvalContext() *hcl.EvalContext {
v, _ := cfg.InputVariables.Values()
l, _ := cfg.LocalVariables.Values()
ectx := &hcl.EvalContext{
Functions: Functions(cfg.Basedir),
Variables: map[string]cty.Value{
"var": cty.ObjectVal(v),
"local": cty.ObjectVal(l),
"var": cty.ObjectVal(cfg.InputVariables.Values()),
"local": cty.ObjectVal(cfg.LocalVariables.Values()),
},
}
return ectx

View File

@ -68,9 +68,6 @@ func (v *Variable) Value() (cty.Value, *hcl.Diagnostic) {
}
value := cty.NullVal(cty.DynamicPseudoType)
if v.Type != cty.NilType {
cty.NullVal(v.Type)
}
return value, &hcl.Diagnostic{
Severity: hcl.DiagError,
@ -83,17 +80,16 @@ func (v *Variable) Value() (cty.Value, *hcl.Diagnostic) {
type Variables map[string]*Variable
func (variables Variables) Values() (map[string]cty.Value, hcl.Diagnostics) {
func (variables Variables) Values() map[string]cty.Value {
res := map[string]cty.Value{}
var diags hcl.Diagnostics
for k, v := range variables {
var diag *hcl.Diagnostic
res[k], diag = v.Value()
if diag != nil {
diags = append(diags, diag)
}
res[k], _ = v.Value()
// here the value might not be used and in that case we don't want to
// force users to set it. So this error is ignored. we still set it as
// it can be a `cty.NullVal(cty.DynamicPseudoType)`, which is the go
// cty value for 'unknown value' and should error when used.
}
return res, diags
return res
}
// decodeVariable decodes a variable key and value into Variables