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
|
|
|
"path/filepath"
|
2019-12-17 05:25:56 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParse_source(t *testing.T) {
|
|
|
|
defaultParser := getBasicParser()
|
|
|
|
|
|
|
|
tests := []parseTest{
|
|
|
|
{"two basic sources",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/sources/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", "sources"),
|
|
|
|
Sources: map[SourceRef]*SourceBlock{
|
2020-01-28 16:49:16 -05:00
|
|
|
{
|
2019-12-17 05:25:56 -05:00
|
|
|
Type: "virtualbox-iso",
|
|
|
|
Name: "ubuntu-1204",
|
|
|
|
}: {
|
|
|
|
Type: "virtualbox-iso",
|
|
|
|
Name: "ubuntu-1204",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false, false,
|
|
|
|
[]packer.Build{},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"untyped source",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/sources/untyped.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", "sources"),
|
|
|
|
},
|
2019-12-17 05:25:56 -05:00
|
|
|
true, true,
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"unnamed source",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/sources/unnamed.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", "sources"),
|
|
|
|
},
|
2019-12-17 05:25:56 -05:00
|
|
|
true, true,
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"inexistent source",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/sources/inexistent.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", "sources"),
|
|
|
|
},
|
2019-12-17 05:25:56 -05:00
|
|
|
true, true,
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"duplicate source",
|
|
|
|
defaultParser,
|
2020-03-12 09:27:56 -04:00
|
|
|
parseTestArgs{"testdata/sources/duplicate.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", "sources"),
|
|
|
|
Sources: map[SourceRef]*SourceBlock{
|
2020-01-28 16:49:16 -05:00
|
|
|
{
|
2019-12-17 05:25:56 -05:00
|
|
|
Type: "virtualbox-iso",
|
|
|
|
Name: "ubuntu-1204",
|
|
|
|
}: {
|
|
|
|
Type: "virtualbox-iso",
|
|
|
|
Name: "ubuntu-1204",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true, true,
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testParse(t, tests)
|
|
|
|
}
|