2019-12-17 05:25:56 -05:00
|
|
|
package hcl2template
|
|
|
|
|
|
|
|
import (
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2019-12-17 05:25:56 -05:00
|
|
|
"testing"
|
|
|
|
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
2020-03-03 05:15:56 -05:00
|
|
|
"github.com/hashicorp/packer/builder/null"
|
2020-08-05 11:41:20 -04:00
|
|
|
. "github.com/hashicorp/packer/hcl2template/internal"
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-08-05 11:41:20 -04:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/zclconf/go-cty/cty/convert"
|
2019-12-17 05:25:56 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParse_variables(t *testing.T) {
|
|
|
|
defaultParser := getBasicParser()
|
|
|
|
|
|
|
|
tests := []parseTest{
|
|
|
|
{"basic variables",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/basic.pkr.hcl", nil, nil},
|
2019-12-17 05:25:56 -05:00
|
|
|
&PackerConfig{
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
2020-02-21 06:12:30 -05:00
|
|
|
"image_name": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "image_name",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("foo-image-{{user `my_secret`}}")}},
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"key": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "key",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("value")}},
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"my_secret": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "my_secret",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("foo")}},
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"image_id": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "image_id",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("image-id-default")}},
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"port": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "port",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.Number,
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.NumberIntVal(42)}},
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
"availability_zone_names": &Variable{
|
2020-03-04 06:30:01 -05:00
|
|
|
Name: "availability_zone_names",
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.ListVal([]cty.Value{
|
|
|
|
cty.StringVal("us-west-1a"),
|
|
|
|
}),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.List(cty.String),
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
Description: fmt.Sprintln("Describing is awesome ;D"),
|
|
|
|
},
|
|
|
|
"super_secret_password": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "super_secret_password",
|
|
|
|
Sensitive: true,
|
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.NullVal(cty.String),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-11-02 05:49:40 -05:00
|
|
|
Description: fmt.Sprintln("Handle with care plz"),
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
LocalVariables: Variables{
|
2020-02-21 06:12:30 -05:00
|
|
|
"owner": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "owner",
|
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.StringVal("Community Team"),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"service_name": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "service_name",
|
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.StringVal("forum"),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
2019-12-17 05:25:56 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
false, false,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
{"duplicate variable",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/duplicate_variable.pkr.hcl", nil, nil},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
2020-02-17 12:05:15 -05:00
|
|
|
"boolean_value": &Variable{
|
|
|
|
Name: "boolean_value",
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.BoolVal(false),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.Bool,
|
2020-02-17 12:05:15 -05:00
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
true, true,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"duplicate variable in variables",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/duplicate_variables.pkr.hcl", nil, nil},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
2020-02-17 12:05:15 -05:00
|
|
|
"boolean_value": &Variable{
|
|
|
|
Name: "boolean_value",
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.BoolVal(false),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.Bool,
|
2020-02-17 12:05:15 -05:00
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
true, true,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"invalid default type",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/invalid_default.pkr.hcl", nil, nil},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
2020-02-17 12:05:15 -05:00
|
|
|
"broken_type": &Variable{
|
|
|
|
Name: "broken_type",
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.UnknownVal(cty.DynamicPseudoType),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.List(cty.String),
|
2020-02-17 12:05:15 -05:00
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
true, true,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
2020-03-09 12:25:56 -04:00
|
|
|
|
2020-02-17 12:05:15 -05:00
|
|
|
{"unknown key",
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/unknown_key.pkr.hcl", nil, nil},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
2020-03-09 12:25:56 -04:00
|
|
|
"broken_variable": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "broken_variable",
|
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.BoolVal(true)}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.Bool,
|
2020-02-17 12:05:15 -05:00
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
2020-10-30 07:26:22 -04:00
|
|
|
true, true,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
2020-03-09 12:25:56 -04:00
|
|
|
|
2020-03-03 05:15:56 -05:00
|
|
|
{"unset used variable",
|
2020-02-17 10:36:19 -05:00
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/unset_used_string_variable.pkr.hcl", nil, nil},
|
2020-02-17 10:36:19 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
2020-02-17 12:05:15 -05:00
|
|
|
"foo": &Variable{
|
|
|
|
Name: "foo",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-17 12:05:15 -05:00
|
|
|
},
|
2020-02-17 10:36:19 -05:00
|
|
|
},
|
|
|
|
},
|
2020-02-17 12:05:15 -05:00
|
|
|
true, true,
|
2020-02-17 11:15:52 -05:00
|
|
|
[]packer.Build{},
|
2020-03-04 07:01:18 -05:00
|
|
|
true,
|
2020-03-03 05:15:56 -05:00
|
|
|
},
|
2020-03-04 07:01:18 -05:00
|
|
|
|
2020-03-03 05:15:56 -05:00
|
|
|
{"unset unused variable",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/unset_unused_string_variable.pkr.hcl", nil, nil},
|
2020-03-03 05:15:56 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
|
|
|
"foo": &Variable{
|
|
|
|
Name: "foo",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-03-03 05:15:56 -05:00
|
|
|
},
|
|
|
|
},
|
2020-05-25 11:09:37 -04:00
|
|
|
Sources: map[SourceRef]SourceBlock{
|
2020-07-02 05:07:59 -04:00
|
|
|
SourceRef{Type: "null", Name: "null-builder"}: SourceBlock{
|
2020-03-03 05:15:56 -05:00
|
|
|
Name: "null-builder",
|
|
|
|
Type: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Builds: Builds{
|
|
|
|
&BuildBlock{
|
2020-05-25 11:09:37 -04:00
|
|
|
Sources: []SourceRef{
|
2020-07-02 05:07:59 -04:00
|
|
|
{Type: "null", Name: "null-builder"},
|
2020-05-25 11:09:37 -04:00
|
|
|
},
|
2020-03-03 05:15:56 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-03-09 12:25:56 -04:00
|
|
|
true, true,
|
2020-03-03 05:15:56 -05:00
|
|
|
[]packer.Build{
|
|
|
|
&packer.CoreBuild{
|
|
|
|
Type: "null",
|
|
|
|
Builder: &null.Builder{},
|
|
|
|
Provisioners: []packer.CoreBuildProvisioner{},
|
|
|
|
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
2020-03-04 07:01:18 -05:00
|
|
|
Prepared: true,
|
2020-03-03 05:15:56 -05:00
|
|
|
},
|
|
|
|
},
|
2020-03-04 07:01:18 -05:00
|
|
|
false,
|
2020-03-04 06:30:01 -05:00
|
|
|
},
|
2020-03-04 07:01:18 -05:00
|
|
|
|
2020-02-21 06:12:30 -05:00
|
|
|
{"locals within another locals usage in different files",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/complicated", nil, nil},
|
2020-02-21 06:12:30 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: "testdata/variables/complicated",
|
|
|
|
InputVariables: Variables{
|
|
|
|
"name_prefix": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "name_prefix",
|
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("foo")}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
LocalVariables: Variables{
|
|
|
|
"name_prefix": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "name_prefix",
|
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("foo")}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"foo": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "foo",
|
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("foo")}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"bar": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "bar",
|
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("foo")}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"for_var": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "for_var",
|
|
|
|
Values: []VariableAssignment{{From: "default", Value: cty.StringVal("foo")}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
"bar_var": &Variable{
|
2020-03-04 07:01:18 -05:00
|
|
|
Name: "bar_var",
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{
|
|
|
|
From: "default",
|
|
|
|
Value: cty.TupleVal([]cty.Value{
|
|
|
|
cty.StringVal("foo"),
|
|
|
|
cty.StringVal("foo"),
|
|
|
|
cty.StringVal("foo"),
|
|
|
|
}),
|
|
|
|
}},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.Tuple([]cty.Type{
|
|
|
|
cty.String,
|
|
|
|
cty.String,
|
|
|
|
cty.String,
|
|
|
|
}),
|
2020-02-21 06:12:30 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false, false,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"recursive locals",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/variables/recursive_locals.pkr.hcl", nil, nil},
|
2020-02-21 06:12:30 -05:00
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
LocalVariables: Variables{},
|
|
|
|
},
|
|
|
|
true, true,
|
|
|
|
[]packer.Build{},
|
2020-03-03 05:15:56 -05:00
|
|
|
false,
|
2020-02-17 10:36:19 -05:00
|
|
|
},
|
2020-03-12 12:08:53 -04:00
|
|
|
|
|
|
|
{"set variable from var-file",
|
|
|
|
defaultParser,
|
|
|
|
parseTestArgs{"testdata/variables/foo-string.variable.pkr.hcl", nil, []string{"testdata/variables/set-foo-too-wee.hcl"}},
|
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
|
|
|
"foo": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "foo",
|
|
|
|
Values: []VariableAssignment{
|
|
|
|
VariableAssignment{"default", cty.StringVal("bar"), nil},
|
|
|
|
VariableAssignment{"varfile", cty.StringVal("wee"), nil},
|
|
|
|
},
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-03-12 12:08:53 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false, false,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
|
|
|
{"unknown variable from var-file",
|
|
|
|
defaultParser,
|
|
|
|
parseTestArgs{"testdata/variables/empty.pkr.hcl", nil, []string{"testdata/variables/set-foo-too-wee.hcl"}},
|
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
},
|
|
|
|
true, false,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
2020-08-05 11:41:20 -04:00
|
|
|
|
|
|
|
{"provisioner variable decoding",
|
|
|
|
defaultParser,
|
|
|
|
parseTestArgs{"testdata/variables/provisioner_variable_decoding.pkr.hcl", nil, nil},
|
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables"),
|
|
|
|
InputVariables: Variables{
|
|
|
|
"max_retries": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "max_retries",
|
|
|
|
Values: []VariableAssignment{{"default", cty.StringVal("1"), nil}},
|
|
|
|
Type: cty.String,
|
2020-08-05 11:41:20 -04:00
|
|
|
},
|
|
|
|
"max_retries_int": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "max_retries_int",
|
|
|
|
Values: []VariableAssignment{{"default", cty.NumberIntVal(1), nil}},
|
|
|
|
Type: cty.Number,
|
2020-08-05 11:41:20 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Sources: map[SourceRef]SourceBlock{
|
|
|
|
SourceRef{Type: "null", Name: "null-builder"}: SourceBlock{
|
|
|
|
Name: "null-builder",
|
|
|
|
Type: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Builds: Builds{
|
|
|
|
&BuildBlock{
|
|
|
|
Sources: []SourceRef{
|
|
|
|
{Type: "null", Name: "null-builder"},
|
|
|
|
},
|
|
|
|
ProvisionerBlocks: []*ProvisionerBlock{
|
|
|
|
{
|
|
|
|
PType: "shell",
|
|
|
|
MaxRetries: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PType: "shell",
|
|
|
|
MaxRetries: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false, false,
|
|
|
|
[]packer.Build{&packer.CoreBuild{
|
|
|
|
Type: "null.null-builder",
|
|
|
|
Prepared: true,
|
|
|
|
Builder: &null.Builder{},
|
|
|
|
Provisioners: []packer.CoreBuildProvisioner{
|
|
|
|
{
|
|
|
|
PType: "shell",
|
|
|
|
Provisioner: &packer.RetriedProvisioner{
|
|
|
|
MaxRetries: 1,
|
|
|
|
Provisioner: &HCL2Provisioner{
|
|
|
|
Provisioner: &MockProvisioner{
|
|
|
|
Config: MockConfig{
|
|
|
|
NestedMockConfig: NestedMockConfig{
|
|
|
|
Tags: []MockTag{},
|
|
|
|
},
|
|
|
|
NestedSlice: []NestedMockConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PType: "shell",
|
|
|
|
Provisioner: &packer.RetriedProvisioner{
|
|
|
|
MaxRetries: 1,
|
|
|
|
Provisioner: &HCL2Provisioner{
|
|
|
|
Provisioner: &MockProvisioner{
|
|
|
|
Config: MockConfig{
|
|
|
|
NestedMockConfig: NestedMockConfig{
|
|
|
|
Tags: []MockTag{},
|
|
|
|
},
|
|
|
|
NestedSlice: []NestedMockConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-10-30 07:41:29 -04:00
|
|
|
|
|
|
|
{"valid validation block",
|
|
|
|
defaultParser,
|
|
|
|
parseTestArgs{"testdata/variables/validation/valid.pkr.hcl", nil, nil},
|
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables", "validation"),
|
|
|
|
InputVariables: Variables{
|
|
|
|
"image_id": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{
|
|
|
|
{"default", cty.StringVal("ami-something-something"), nil},
|
|
|
|
},
|
|
|
|
Name: "image_id",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-10-30 07:41:29 -04:00
|
|
|
Validations: []*VariableValidation{
|
|
|
|
&VariableValidation{
|
|
|
|
ErrorMessage: `The image_id value must be a valid AMI id, starting with "ami-".`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false, false,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
2020-11-02 05:49:40 -05:00
|
|
|
|
|
|
|
{"valid validation block - invalid default",
|
|
|
|
defaultParser,
|
|
|
|
parseTestArgs{"testdata/variables/validation/invalid_default.pkr.hcl", nil, nil},
|
|
|
|
&PackerConfig{
|
|
|
|
Basedir: filepath.Join("testdata", "variables", "validation"),
|
|
|
|
InputVariables: Variables{
|
|
|
|
"image_id": &Variable{
|
2020-11-02 10:52:21 -05:00
|
|
|
Values: []VariableAssignment{{"default", cty.StringVal("potato"), nil}},
|
2020-11-02 05:49:40 -05:00
|
|
|
Name: "image_id",
|
2020-11-02 10:52:21 -05:00
|
|
|
Type: cty.String,
|
2020-11-02 05:49:40 -05:00
|
|
|
Validations: []*VariableValidation{
|
|
|
|
&VariableValidation{
|
|
|
|
ErrorMessage: `The image_id value must be a valid AMI id, starting with "ami-".`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true, true,
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
2019-12-17 05:25:56 -05:00
|
|
|
}
|
|
|
|
testParse(t, tests)
|
|
|
|
}
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
|
|
|
|
func TestVariables_collectVariableValues(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
env []string
|
|
|
|
hclFiles []string
|
|
|
|
argv map[string]string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
2020-03-09 11:16:59 -04:00
|
|
|
name string
|
|
|
|
variables Variables
|
|
|
|
validationOptions ValidationOptions
|
|
|
|
args args
|
|
|
|
wantDiags bool
|
|
|
|
wantDiagsHasError bool
|
|
|
|
wantVariables Variables
|
|
|
|
wantValues map[string]cty.Value
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
}{
|
|
|
|
|
|
|
|
{name: "string",
|
2020-03-06 09:12:26 -05:00
|
|
|
variables: Variables{"used_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{
|
|
|
|
{"default", cty.StringVal("default_value"), nil},
|
|
|
|
},
|
|
|
|
Type: cty.String,
|
2020-03-06 09:12:26 -05:00
|
|
|
}},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
args: args{
|
2020-03-06 09:12:26 -05:00
|
|
|
env: []string{`PKR_VAR_used_string=env_value`},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
hclFiles: []string{
|
|
|
|
`used_string="xy"`,
|
|
|
|
`used_string="varfile_value"`,
|
|
|
|
},
|
|
|
|
argv: map[string]string{
|
2020-03-06 09:12:26 -05:00
|
|
|
"used_string": `cmd_value`,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: false,
|
|
|
|
wantVariables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.String,
|
|
|
|
Values: []VariableAssignment{
|
2020-11-02 10:52:21 -05:00
|
|
|
{"default", cty.StringVal(`default_value`), nil},
|
|
|
|
{"env", cty.StringVal(`env_value`), nil},
|
|
|
|
{"varfile", cty.StringVal(`xy`), nil},
|
|
|
|
{"varfile", cty.StringVal(`varfile_value`), nil},
|
|
|
|
{"cmd", cty.StringVal(`cmd_value`), nil},
|
2020-11-02 05:49:40 -05:00
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"used_string": cty.StringVal("cmd_value"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-03-06 09:12:26 -05:00
|
|
|
{name: "quoted string",
|
|
|
|
variables: Variables{"quoted_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{
|
|
|
|
{"default", cty.StringVal(`"default_value"`), nil},
|
|
|
|
},
|
|
|
|
Type: cty.String,
|
2020-03-06 09:12:26 -05:00
|
|
|
}},
|
|
|
|
args: args{
|
|
|
|
env: []string{`PKR_VAR_quoted_string="env_value"`},
|
|
|
|
hclFiles: []string{
|
|
|
|
`quoted_string="\"xy\""`,
|
|
|
|
`quoted_string="\"varfile_value\""`,
|
|
|
|
},
|
|
|
|
argv: map[string]string{
|
|
|
|
"quoted_string": `"cmd_value"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: false,
|
|
|
|
wantVariables: Variables{
|
|
|
|
"quoted_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.String,
|
|
|
|
Values: []VariableAssignment{
|
|
|
|
{"default", cty.StringVal(`"default_value"`), nil},
|
|
|
|
{"env", cty.StringVal(`"env_value"`), nil},
|
|
|
|
{"varfile", cty.StringVal(`"xy"`), nil},
|
|
|
|
{"varfile", cty.StringVal(`"varfile_value"`), nil},
|
|
|
|
{"cmd", cty.StringVal(`"cmd_value"`), nil},
|
|
|
|
},
|
2020-03-06 09:12:26 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"quoted_string": cty.StringVal(`"cmd_value"`),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
{name: "array of strings",
|
|
|
|
variables: Variables{"used_strings": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{
|
|
|
|
{"default", stringListVal("default_value_1"), nil},
|
|
|
|
},
|
|
|
|
Type: cty.List(cty.String),
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
}},
|
|
|
|
args: args{
|
|
|
|
env: []string{`PKR_VAR_used_strings=["env_value_1", "env_value_2"]`},
|
|
|
|
hclFiles: []string{
|
|
|
|
`used_strings=["xy"]`,
|
|
|
|
`used_strings=["varfile_value_1"]`,
|
|
|
|
},
|
|
|
|
argv: map[string]string{
|
|
|
|
"used_strings": `["cmd_value_1"]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: false,
|
|
|
|
wantVariables: Variables{
|
|
|
|
"used_strings": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.List(cty.String),
|
|
|
|
Values: []VariableAssignment{
|
|
|
|
{"default", stringListVal("default_value_1"), nil},
|
|
|
|
{"env", stringListVal("env_value_1", "env_value_2"), nil},
|
|
|
|
{"varfile", stringListVal("xy"), nil},
|
|
|
|
{"varfile", stringListVal("varfile_value_1"), nil},
|
|
|
|
{"cmd", stringListVal("cmd_value_1"), nil},
|
|
|
|
},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"used_strings": stringListVal("cmd_value_1"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-03-06 09:12:26 -05:00
|
|
|
{name: "bool",
|
|
|
|
variables: Variables{"enabled": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{"default", cty.False, nil}},
|
|
|
|
Type: cty.Bool,
|
2020-03-06 09:12:26 -05:00
|
|
|
}},
|
|
|
|
args: args{
|
|
|
|
env: []string{`PKR_VAR_enabled=true`},
|
|
|
|
hclFiles: []string{
|
|
|
|
`enabled="false"`,
|
|
|
|
},
|
|
|
|
argv: map[string]string{
|
|
|
|
"enabled": `true`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: false,
|
|
|
|
wantVariables: Variables{
|
|
|
|
"enabled": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.Bool,
|
|
|
|
Values: []VariableAssignment{
|
|
|
|
{"default", cty.False, nil},
|
|
|
|
{"env", cty.True, nil},
|
|
|
|
{"varfile", cty.False, nil},
|
|
|
|
{"cmd", cty.True, nil},
|
|
|
|
},
|
2020-03-06 09:12:26 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"enabled": cty.True,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
{name: "invalid env var",
|
2020-03-06 09:12:26 -05:00
|
|
|
variables: Variables{"used_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Values: []VariableAssignment{{"default", cty.StringVal("default_value"), nil}},
|
|
|
|
Type: cty.String,
|
2020-03-06 09:12:26 -05:00
|
|
|
}},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
args: args{
|
|
|
|
env: []string{`PKR_VAR_used_string`},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: false,
|
|
|
|
wantVariables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.String,
|
|
|
|
Values: []VariableAssignment{{"default", cty.StringVal("default_value"), nil}},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"used_string": cty.StringVal("default_value"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-03-09 11:16:59 -04:00
|
|
|
{name: "undefined but set value - pkrvar file - normal mode",
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
variables: Variables{},
|
|
|
|
args: args{
|
2020-03-09 11:16:59 -04:00
|
|
|
hclFiles: []string{`undefined_string="value"`},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: true,
|
|
|
|
wantDiagsHasError: false,
|
|
|
|
wantVariables: Variables{},
|
|
|
|
wantValues: map[string]cty.Value{},
|
|
|
|
},
|
|
|
|
|
|
|
|
{name: "undefined but set value - pkrvar file - strict mode",
|
|
|
|
variables: Variables{},
|
|
|
|
validationOptions: ValidationOptions{
|
|
|
|
Strict: true,
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
hclFiles: []string{`undefined_string="value"`},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: true,
|
|
|
|
wantDiagsHasError: true,
|
|
|
|
wantVariables: Variables{},
|
|
|
|
wantValues: map[string]cty.Value{},
|
|
|
|
},
|
|
|
|
|
|
|
|
{name: "undefined but set value - env",
|
|
|
|
variables: Variables{},
|
|
|
|
args: args{
|
|
|
|
env: []string{`PKR_VAR_undefined_string=value`},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
|
|
|
wantDiags: false,
|
|
|
|
wantVariables: Variables{},
|
|
|
|
wantValues: map[string]cty.Value{},
|
|
|
|
},
|
|
|
|
|
2020-03-09 11:16:59 -04:00
|
|
|
{name: "undefined but set value - argv",
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
variables: Variables{},
|
|
|
|
args: args{
|
|
|
|
argv: map[string]string{
|
2020-03-09 11:16:59 -04:00
|
|
|
"undefined_string": "value",
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
2020-03-09 11:16:59 -04:00
|
|
|
wantDiags: true,
|
|
|
|
wantDiagsHasError: true,
|
|
|
|
wantVariables: Variables{},
|
|
|
|
wantValues: map[string]cty.Value{},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{name: "value not corresponding to type - env",
|
|
|
|
variables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-03-06 09:12:26 -05:00
|
|
|
Type: cty.List(cty.String),
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2020-03-06 09:12:26 -05:00
|
|
|
env: []string{`PKR_VAR_used_string="string"`},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
2020-03-09 11:16:59 -04:00
|
|
|
wantDiags: true,
|
|
|
|
wantDiagsHasError: true,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
wantVariables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.List(cty.String),
|
|
|
|
Values: []VariableAssignment{{"env", cty.DynamicVal, nil}},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"used_string": cty.DynamicVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{name: "value not corresponding to type - cfg file",
|
|
|
|
variables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-03-06 09:12:26 -05:00
|
|
|
Type: cty.Bool,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
hclFiles: []string{`used_string=["string"]`},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
2020-03-09 11:16:59 -04:00
|
|
|
wantDiags: true,
|
|
|
|
wantDiagsHasError: true,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
wantVariables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.Bool,
|
|
|
|
Values: []VariableAssignment{{"varfile", cty.DynamicVal, nil}},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"used_string": cty.DynamicVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{name: "value not corresponding to type - argv",
|
|
|
|
variables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-03-06 09:12:26 -05:00
|
|
|
Type: cty.Bool,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
argv: map[string]string{
|
2020-03-06 09:12:26 -05:00
|
|
|
"used_string": `["true"]`,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
2020-03-09 11:16:59 -04:00
|
|
|
wantDiags: true,
|
|
|
|
wantDiagsHasError: true,
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
wantVariables: Variables{
|
|
|
|
"used_string": &Variable{
|
2020-11-02 05:49:40 -05:00
|
|
|
Type: cty.Bool,
|
|
|
|
Values: []VariableAssignment{{"cmd", cty.DynamicVal, nil}},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantValues: map[string]cty.Value{
|
|
|
|
"used_string": cty.DynamicVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{name: "defining a variable block in a variables file is invalid ",
|
|
|
|
variables: Variables{},
|
|
|
|
args: args{
|
|
|
|
hclFiles: []string{`variable "something" {}`},
|
|
|
|
},
|
|
|
|
|
|
|
|
// output
|
2020-03-09 11:16:59 -04:00
|
|
|
wantDiags: true,
|
|
|
|
wantDiagsHasError: true,
|
|
|
|
wantVariables: Variables{},
|
|
|
|
wantValues: map[string]cty.Value{},
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
var files []*hcl.File
|
|
|
|
parser := getBasicParser()
|
|
|
|
for i, hclContent := range tt.args.hclFiles {
|
|
|
|
file, diags := parser.ParseHCL([]byte(hclContent), fmt.Sprintf("test_file_%d_*"+hcl2VarFileExt, i))
|
|
|
|
if diags != nil {
|
|
|
|
t.Fatalf("ParseHCLFile %d: %v", i, diags)
|
|
|
|
}
|
|
|
|
files = append(files, file)
|
|
|
|
}
|
2020-03-09 11:16:59 -04:00
|
|
|
cfg := &PackerConfig{
|
|
|
|
InputVariables: tt.variables,
|
|
|
|
ValidationOptions: tt.validationOptions,
|
|
|
|
}
|
|
|
|
gotDiags := cfg.collectInputVariableValues(tt.args.env, files, tt.args.argv)
|
|
|
|
if (gotDiags == nil) == tt.wantDiags {
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
t.Fatalf("Variables.collectVariableValues() = %v, want %v", gotDiags, tt.wantDiags)
|
|
|
|
}
|
2020-03-09 11:16:59 -04:00
|
|
|
if tt.wantDiagsHasError != gotDiags.HasErrors() {
|
|
|
|
t.Fatalf("Variables.collectVariableValues() unexpected diagnostics HasErrors. %s", gotDiags)
|
|
|
|
}
|
2020-11-02 05:49:40 -05:00
|
|
|
if diff := cmp.Diff(tt.wantVariables, tt.variables, cmpOpts...); diff != "" {
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 05:49:21 -05:00
|
|
|
t.Fatalf("didn't get expected variables: %s", diff)
|
|
|
|
}
|
|
|
|
values := map[string]cty.Value{}
|
|
|
|
for k, v := range tt.variables {
|
|
|
|
value, diag := v.Value()
|
|
|
|
if diag != nil {
|
|
|
|
t.Fatalf("Value %s: %v", k, diag)
|
|
|
|
}
|
|
|
|
values[k] = value
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(fmt.Sprintf("%#v", values), fmt.Sprintf("%#v", tt.wantValues)); diff != "" {
|
|
|
|
t.Fatalf("didn't get expected values: %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func stringListVal(strings ...string) cty.Value {
|
|
|
|
values := []cty.Value{}
|
|
|
|
for _, str := range strings {
|
|
|
|
values = append(values, cty.StringVal(str))
|
|
|
|
}
|
|
|
|
list, err := convert.Convert(cty.ListVal(values), cty.List(cty.String))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|