tests and fixes
This commit is contained in:
parent
aeecfcd422
commit
029729225d
|
@ -1,7 +1,13 @@
|
|||
|
||||
packer {
|
||||
required_plugins {
|
||||
amazon = ">= v0"
|
||||
amazon = ">= v4"
|
||||
amazon = {
|
||||
source = "github.com/hashicorp/amazon"
|
||||
version = ">= v0"
|
||||
}
|
||||
amazon = {
|
||||
source = "github.com/hashicorp/amazon"
|
||||
version = ">= v4"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,29 +3,26 @@ packer {
|
|||
required_version = ">= v1"
|
||||
|
||||
required_plugins {
|
||||
amazon = ">= v0"
|
||||
|
||||
amazon = {
|
||||
source = "github.com/hashicorp/amazon"
|
||||
version = ">= v0"
|
||||
}
|
||||
amazon-v1 = {
|
||||
source = "amazon"
|
||||
source = "github.com/hashicorp/amazon"
|
||||
version = ">= v1"
|
||||
}
|
||||
|
||||
amazon-v2 = {
|
||||
source = "amazon"
|
||||
source = "github.com/hashicorp/amazon"
|
||||
version = ">= v2"
|
||||
}
|
||||
|
||||
|
||||
amazon-v3 = {
|
||||
source = "hashicorp/amazon"
|
||||
source = "github.com/hashicorp/amazon"
|
||||
version = ">= v3"
|
||||
}
|
||||
|
||||
amazon-v3-azr = {
|
||||
source = "azr/amazon"
|
||||
source = "github.com/azr/amazon"
|
||||
version = ">= v3"
|
||||
}
|
||||
|
||||
amazon-v4 = {
|
||||
source = "github.com/hashicorp/amazon"
|
||||
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{
|
||||
"amazon": {
|
||||
Name: "amazon",
|
||||
Source: "",
|
||||
Source: "github.com/hashicorp/amazon",
|
||||
Type: &addrs.Plugin{
|
||||
Type: "amazon",
|
||||
Namespace: "hashicorp",
|
||||
|
@ -443,7 +443,7 @@ func TestParser_no_init(t *testing.T) {
|
|||
},
|
||||
"amazon-v1": {
|
||||
Name: "amazon-v1",
|
||||
Source: "amazon",
|
||||
Source: "github.com/hashicorp/amazon",
|
||||
Type: &addrs.Plugin{
|
||||
Type: "amazon",
|
||||
Namespace: "hashicorp",
|
||||
|
@ -455,7 +455,7 @@ func TestParser_no_init(t *testing.T) {
|
|||
},
|
||||
"amazon-v2": {
|
||||
Name: "amazon-v2",
|
||||
Source: "amazon",
|
||||
Source: "github.com/hashicorp/amazon",
|
||||
Type: &addrs.Plugin{
|
||||
Type: "amazon",
|
||||
Namespace: "hashicorp",
|
||||
|
@ -467,7 +467,7 @@ func TestParser_no_init(t *testing.T) {
|
|||
},
|
||||
"amazon-v3": {
|
||||
Name: "amazon-v3",
|
||||
Source: "hashicorp/amazon",
|
||||
Source: "github.com/hashicorp/amazon",
|
||||
Type: &addrs.Plugin{
|
||||
Type: "amazon",
|
||||
Namespace: "hashicorp",
|
||||
|
@ -479,7 +479,7 @@ func TestParser_no_init(t *testing.T) {
|
|||
},
|
||||
"amazon-v3-azr": {
|
||||
Name: "amazon-v3-azr",
|
||||
Source: "azr/amazon",
|
||||
Source: "github.com/azr/amazon",
|
||||
Type: &addrs.Plugin{
|
||||
Type: "amazon",
|
||||
Namespace: "azr",
|
||||
|
@ -610,6 +610,66 @@ func TestParser_no_init(t *testing.T) {
|
|||
[]packersdk.Build{},
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,11 @@ func (cfg *PackerConfig) decodeImplicitRequiredPluginsBlocks(f *hcl.File) hcl.Di
|
|||
// RequiredPlugin represents a declaration of a dependency on a particular
|
||||
// Plugin version or source.
|
||||
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
|
||||
Type *addrs.Plugin
|
||||
Requirement VersionConstraint
|
||||
|
@ -77,7 +81,7 @@ type RequiredPlugins struct {
|
|||
func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnostics) {
|
||||
attrs, diags := block.Body.JustAttributes()
|
||||
ret := &RequiredPlugins{
|
||||
RequiredPlugins: make(map[string]*RequiredPlugin),
|
||||
RequiredPlugins: nil,
|
||||
DeclRange: block.DefRange,
|
||||
}
|
||||
for name, attr := range attrs {
|
||||
|
@ -112,6 +116,7 @@ func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnos
|
|||
name, c),
|
||||
Subject: attr.Range.Ptr(),
|
||||
})
|
||||
continue
|
||||
|
||||
case expr.Type().IsObjectType():
|
||||
if !expr.Type().HasAttribute("version") {
|
||||
|
@ -186,6 +191,7 @@ func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnos
|
|||
}
|
||||
}
|
||||
diags = append(diags, sourceDiags...)
|
||||
continue
|
||||
} else {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -82,10 +82,9 @@ func (v *Variable) GoString() string {
|
|||
|
||||
// validateValue ensures that all of the configured custom validations for a
|
||||
// variable value are passing.
|
||||
//
|
||||
func (v *Variable) validateValue(val VariableAssignment) (diags hcl.Diagnostics) {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue