* hcl2template/types.variables: Update logic for parsing literal value variables
In running tests via the CLI it was determined that when using the variable block with no explicit type assigned the type of the default
value was not being set within the map. This change updates the `decodeConfig` method so that a type is always set for any defined variable if not specified.
The second change is to properly handle the evaluation of basic variable types (e.g String, Number, Bool). Previously variables defined on the
CLI or via PKR_VAR required some additional quoting to for proper evaluation. This change fixes that issue so that it works like it does in Terraform :)
Build results before the change
```
⇶ PKR_VAR_example='["one","two"]' ~/bin/packer build -var 'foo=home' .
Error: Variables not allowed
on <value for var.foo from arguments> line 1:
(source code not available)
Variables may not be used here.
==> Builds finished but no artifacts were created.
```
Build results after the change
```
⇶ PKR_VAR_example='["one","two"]' ~/bin/packer build -var 'foo="home"' .
null: output will be in this color.
==> null: Running local shell script: /tmp/packer-shell885249462
null: two
null: home
Build 'null' finished.
==> Builds finished. The artifacts of successful builds are:
--> null: Did not export anything. This is the null builder
⇶ ~/bin/packer build -var 'foo=home' -var 'example=["one","another variable"]' .
null: output will be in this color.
==> null: Running local shell script: /tmp/packer-shell123467506
null: another variable
null: home
Build 'null' finished.
==> Builds finished. The artifacts of successful builds are:
--> null: Did not export anything. This is the null builder
```
* tests/hcl2template/types.variables: Update test to use Bool
Turns out a string value won't actually complain if it's given a non
string looking value. It will just covert the value to a string literal
so using a type Bool which should fail if given anything that is not
true or false.
* tests/hcl2template/types.variables: Update unit tests
During testing it was found that by default the variable stanza were defaulting to a cty.NilType, and not the Type of it's default value.
This change sets the default type of the defined variable to ensure variable evaluation behaviors correctly.
* Add a simple cty.Bool test case
* tests/hcl2template/types.variables: Enable quoted_string test case
* Update hcl2template/types.variables.go
space
Co-authored-by: Adrien Delorme <azr@users.noreply.github.com>