tests and fixes
This commit is contained in:
parent
aeecfcd422
commit
029729225d
|
@ -1,7 +1,13 @@
|
||||||
|
|
||||||
packer {
|
packer {
|
||||||
required_plugins {
|
required_plugins {
|
||||||
amazon = ">= v0"
|
amazon = {
|
||||||
amazon = ">= v4"
|
source = "github.com/hashicorp/amazon"
|
||||||
|
version = ">= v0"
|
||||||
|
}
|
||||||
|
amazon = {
|
||||||
|
source = "github.com/hashicorp/amazon"
|
||||||
|
version = ">= v4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,29 +3,26 @@ packer {
|
||||||
required_version = ">= v1"
|
required_version = ">= v1"
|
||||||
|
|
||||||
required_plugins {
|
required_plugins {
|
||||||
amazon = ">= v0"
|
amazon = {
|
||||||
|
source = "github.com/hashicorp/amazon"
|
||||||
|
version = ">= v0"
|
||||||
|
}
|
||||||
amazon-v1 = {
|
amazon-v1 = {
|
||||||
source = "amazon"
|
source = "github.com/hashicorp/amazon"
|
||||||
version = ">= v1"
|
version = ">= v1"
|
||||||
}
|
}
|
||||||
|
|
||||||
amazon-v2 = {
|
amazon-v2 = {
|
||||||
source = "amazon"
|
source = "github.com/hashicorp/amazon"
|
||||||
version = ">= v2"
|
version = ">= v2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
amazon-v3 = {
|
amazon-v3 = {
|
||||||
source = "hashicorp/amazon"
|
source = "github.com/hashicorp/amazon"
|
||||||
version = ">= v3"
|
version = ">= v3"
|
||||||
}
|
}
|
||||||
|
|
||||||
amazon-v3-azr = {
|
amazon-v3-azr = {
|
||||||
source = "azr/amazon"
|
source = "github.com/azr/amazon"
|
||||||
version = ">= v3"
|
version = ">= v3"
|
||||||
}
|
}
|
||||||
|
|
||||||
amazon-v4 = {
|
amazon-v4 = {
|
||||||
source = "github.com/hashicorp/amazon"
|
source = "github.com/hashicorp/amazon"
|
||||||
version = ">= v4"
|
version = ">= v4"
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
packer {
|
||||||
|
required_plugins {
|
||||||
|
amazon = {
|
||||||
|
source = "amazon"
|
||||||
|
version = ">= v0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
packer {
|
||||||
|
required_plugins {
|
||||||
|
amazon = {
|
||||||
|
source = "hashicorp/amazon"
|
||||||
|
version = ">= v0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
packer {
|
||||||
|
required_plugins {
|
||||||
|
amazon = ">= v0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -431,7 +431,7 @@ func TestParser_no_init(t *testing.T) {
|
||||||
RequiredPlugins: map[string]*RequiredPlugin{
|
RequiredPlugins: map[string]*RequiredPlugin{
|
||||||
"amazon": {
|
"amazon": {
|
||||||
Name: "amazon",
|
Name: "amazon",
|
||||||
Source: "",
|
Source: "github.com/hashicorp/amazon",
|
||||||
Type: &addrs.Plugin{
|
Type: &addrs.Plugin{
|
||||||
Type: "amazon",
|
Type: "amazon",
|
||||||
Namespace: "hashicorp",
|
Namespace: "hashicorp",
|
||||||
|
@ -443,7 +443,7 @@ func TestParser_no_init(t *testing.T) {
|
||||||
},
|
},
|
||||||
"amazon-v1": {
|
"amazon-v1": {
|
||||||
Name: "amazon-v1",
|
Name: "amazon-v1",
|
||||||
Source: "amazon",
|
Source: "github.com/hashicorp/amazon",
|
||||||
Type: &addrs.Plugin{
|
Type: &addrs.Plugin{
|
||||||
Type: "amazon",
|
Type: "amazon",
|
||||||
Namespace: "hashicorp",
|
Namespace: "hashicorp",
|
||||||
|
@ -455,7 +455,7 @@ func TestParser_no_init(t *testing.T) {
|
||||||
},
|
},
|
||||||
"amazon-v2": {
|
"amazon-v2": {
|
||||||
Name: "amazon-v2",
|
Name: "amazon-v2",
|
||||||
Source: "amazon",
|
Source: "github.com/hashicorp/amazon",
|
||||||
Type: &addrs.Plugin{
|
Type: &addrs.Plugin{
|
||||||
Type: "amazon",
|
Type: "amazon",
|
||||||
Namespace: "hashicorp",
|
Namespace: "hashicorp",
|
||||||
|
@ -467,7 +467,7 @@ func TestParser_no_init(t *testing.T) {
|
||||||
},
|
},
|
||||||
"amazon-v3": {
|
"amazon-v3": {
|
||||||
Name: "amazon-v3",
|
Name: "amazon-v3",
|
||||||
Source: "hashicorp/amazon",
|
Source: "github.com/hashicorp/amazon",
|
||||||
Type: &addrs.Plugin{
|
Type: &addrs.Plugin{
|
||||||
Type: "amazon",
|
Type: "amazon",
|
||||||
Namespace: "hashicorp",
|
Namespace: "hashicorp",
|
||||||
|
@ -479,7 +479,7 @@ func TestParser_no_init(t *testing.T) {
|
||||||
},
|
},
|
||||||
"amazon-v3-azr": {
|
"amazon-v3-azr": {
|
||||||
Name: "amazon-v3-azr",
|
Name: "amazon-v3-azr",
|
||||||
Source: "azr/amazon",
|
Source: "github.com/azr/amazon",
|
||||||
Type: &addrs.Plugin{
|
Type: &addrs.Plugin{
|
||||||
Type: "amazon",
|
Type: "amazon",
|
||||||
Namespace: "azr",
|
Namespace: "azr",
|
||||||
|
@ -610,6 +610,66 @@ func TestParser_no_init(t *testing.T) {
|
||||||
[]packersdk.Build{},
|
[]packersdk.Build{},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{"invalid_inexplicit_source.pkr.hcl",
|
||||||
|
defaultParser,
|
||||||
|
parseTestArgs{"testdata/init/invalid_inexplicit_source.pkr.hcl", nil, nil},
|
||||||
|
&PackerConfig{
|
||||||
|
Packer: struct {
|
||||||
|
VersionConstraints []VersionConstraint
|
||||||
|
RequiredPlugins []*RequiredPlugins
|
||||||
|
}{
|
||||||
|
VersionConstraints: nil,
|
||||||
|
RequiredPlugins: []*RequiredPlugins{
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CorePackerVersionString: lockedVersion,
|
||||||
|
Basedir: "testdata/init",
|
||||||
|
},
|
||||||
|
true, true,
|
||||||
|
[]packersdk.Build{},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{"invalid_short_source.pkr.hcl",
|
||||||
|
defaultParser,
|
||||||
|
parseTestArgs{"testdata/init/invalid_short_source.pkr.hcl", nil, nil},
|
||||||
|
&PackerConfig{
|
||||||
|
Packer: struct {
|
||||||
|
VersionConstraints []VersionConstraint
|
||||||
|
RequiredPlugins []*RequiredPlugins
|
||||||
|
}{
|
||||||
|
VersionConstraints: nil,
|
||||||
|
RequiredPlugins: []*RequiredPlugins{
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CorePackerVersionString: lockedVersion,
|
||||||
|
Basedir: "testdata/init",
|
||||||
|
},
|
||||||
|
true, true,
|
||||||
|
[]packersdk.Build{},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{"invalid_short_source_2.pkr.hcl",
|
||||||
|
defaultParser,
|
||||||
|
parseTestArgs{"testdata/init/invalid_inexplicit_source_2.pkr.hcl", nil, nil},
|
||||||
|
&PackerConfig{
|
||||||
|
Packer: struct {
|
||||||
|
VersionConstraints []VersionConstraint
|
||||||
|
RequiredPlugins []*RequiredPlugins
|
||||||
|
}{
|
||||||
|
VersionConstraints: nil,
|
||||||
|
RequiredPlugins: []*RequiredPlugins{
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CorePackerVersionString: lockedVersion,
|
||||||
|
Basedir: "testdata/init",
|
||||||
|
},
|
||||||
|
true, true,
|
||||||
|
[]packersdk.Build{},
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
testParse_only_Parse(t, tests)
|
testParse_only_Parse(t, tests)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,10 @@ func (cfg *PackerConfig) decodeImplicitRequiredPluginsBlocks(f *hcl.File) hcl.Di
|
||||||
// Plugin version or source.
|
// Plugin version or source.
|
||||||
type RequiredPlugin struct {
|
type RequiredPlugin struct {
|
||||||
Name string
|
Name string
|
||||||
|
// Source used to be able to tell how the template referenced this source,
|
||||||
|
// for example, "awesomecloud" instead of github.com/awesome/awesomecloud.
|
||||||
|
// This one is left here in case we want to go back to allowing inexplicit
|
||||||
|
// source url definitions.
|
||||||
Source string
|
Source string
|
||||||
Type *addrs.Plugin
|
Type *addrs.Plugin
|
||||||
Requirement VersionConstraint
|
Requirement VersionConstraint
|
||||||
|
@ -77,7 +81,7 @@ type RequiredPlugins struct {
|
||||||
func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnostics) {
|
func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnostics) {
|
||||||
attrs, diags := block.Body.JustAttributes()
|
attrs, diags := block.Body.JustAttributes()
|
||||||
ret := &RequiredPlugins{
|
ret := &RequiredPlugins{
|
||||||
RequiredPlugins: make(map[string]*RequiredPlugin),
|
RequiredPlugins: nil,
|
||||||
DeclRange: block.DefRange,
|
DeclRange: block.DefRange,
|
||||||
}
|
}
|
||||||
for name, attr := range attrs {
|
for name, attr := range attrs {
|
||||||
|
@ -112,6 +116,7 @@ func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnos
|
||||||
name, c),
|
name, c),
|
||||||
Subject: attr.Range.Ptr(),
|
Subject: attr.Range.Ptr(),
|
||||||
})
|
})
|
||||||
|
continue
|
||||||
|
|
||||||
case expr.Type().IsObjectType():
|
case expr.Type().IsObjectType():
|
||||||
if !expr.Type().HasAttribute("version") {
|
if !expr.Type().HasAttribute("version") {
|
||||||
|
@ -186,6 +191,7 @@ func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diags = append(diags, sourceDiags...)
|
diags = append(diags, sourceDiags...)
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
rp.Type = p
|
rp.Type = p
|
||||||
}
|
}
|
||||||
|
@ -214,6 +220,9 @@ func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnos
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ret.RequiredPlugins == nil {
|
||||||
|
ret.RequiredPlugins = make(map[string]*RequiredPlugin)
|
||||||
|
}
|
||||||
ret.RequiredPlugins[rp.Name] = rp
|
ret.RequiredPlugins[rp.Name] = rp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,10 +82,9 @@ func (v *Variable) GoString() string {
|
||||||
|
|
||||||
// validateValue ensures that all of the configured custom validations for a
|
// validateValue ensures that all of the configured custom validations for a
|
||||||
// variable value are passing.
|
// variable value are passing.
|
||||||
//
|
|
||||||
func (v *Variable) validateValue(val VariableAssignment) (diags hcl.Diagnostics) {
|
func (v *Variable) validateValue(val VariableAssignment) (diags hcl.Diagnostics) {
|
||||||
if len(v.Validations) == 0 {
|
if len(v.Validations) == 0 {
|
||||||
log.Printf("[TRACE] validateValue: not active for %s, so skipping", v.Name)
|
// log.Printf("[TRACE] validateValue: not active for %s, so skipping", v.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue