review comments, add plugin type for a few missing builders

This commit is contained in:
Megan Marsh 2020-10-21 16:07:18 -07:00
parent 1192e457ff
commit 70cb4097e1
12 changed files with 52 additions and 46 deletions

View File

@ -580,6 +580,7 @@ func (c *Config) createCertificate() (string, error) {
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.ctx.Funcs = azcommon.TemplateFuncs
err := config.Decode(c, &config.DecodeOpts{
PluginType: BuilderId,
Interpolate: true,
InterpolateContext: &c.ctx,
}, raws...)

View File

@ -389,6 +389,7 @@ func newConfig(raws ...interface{}) (*Config, []string, error) {
var c Config
c.ctx.Funcs = TemplateFuncs
err := config.Decode(&c, &config.DecodeOpts{
PluginType: BuilderId,
Interpolate: true,
InterpolateContext: &c.ctx,
}, raws...)

View File

@ -127,6 +127,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
var md mapstructure.Metadata
err := config.Decode(c, &config.DecodeOpts{
Metadata: &md,
PluginType: BuilderId,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{

View File

@ -291,6 +291,7 @@ type Config struct {
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.ctx.Funcs = TemplateFuncs
err := config.Decode(c, &config.DecodeOpts{
PluginType: BuilderId,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{

View File

@ -51,6 +51,7 @@ type Config struct {
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
err := config.Decode(c, &config.DecodeOpts{
PluginType: parallelscommon.BuilderId,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{

View File

@ -394,6 +394,7 @@ type Config struct {
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
err := config.Decode(c, &config.DecodeOpts{
PluginType: BuilderId,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{

View File

@ -99,6 +99,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
var md mapstructure.Metadata
err := config.Decode(c, &config.DecodeOpts{
Metadata: &md,
PluginType: BuilderId,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{

1
go.mod
View File

@ -93,7 +93,6 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/go-testing-interface v1.0.3 // indirect
github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed
github.com/mitchellh/gox v1.0.1 // indirect
github.com/mitchellh/iochan v1.0.0
github.com/mitchellh/mapstructure v1.2.3
github.com/mitchellh/panicwrap v1.0.0

3
go.sum
View File

@ -377,7 +377,6 @@ github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
@ -512,8 +511,6 @@ github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZX
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=

View File

@ -156,56 +156,57 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
if err := decoder.Decode(raw); err != nil {
return err
}
// If we have unused keys, it is an error
if len(md.Unused) > 0 {
var err error
sort.Strings(md.Unused)
for _, unused := range md.Unused {
if unused == "type" || strings.HasPrefix(unused, "packer_") {
continue
}
}
// Check for whether the key is handled in a packer fix
// call.
fixable := false
// If we have unused keys, it is an error
if len(md.Unused) > 0 {
var err error
sort.Strings(md.Unused)
for _, unused := range md.Unused {
if unused == "type" || strings.HasPrefix(unused, "packer_") {
continue
}
// check whether the deprecation option can be fixed using packer fix.
if config.PluginType != "" {
for k, deprecatedOptions := range DeprecatedOptions {
// the deprecated options keys are globbable, for
// example "amazon*" for all amazon builders, or * for
// all builders
if glob.Glob(k, config.PluginType) {
for _, deprecatedOption := range deprecatedOptions {
if unused == deprecatedOption {
fixable = true
break
}
// Check for whether the key is handled in a packer fix
// call.
fixable := false
// check whether the deprecation option can be fixed using packer fix.
if config.PluginType != "" {
for k, deprecatedOptions := range DeprecatedOptions {
// the deprecated options keys are globbable, for
// example "amazon*" for all amazon builders, or * for
// all builders
if glob.Glob(k, config.PluginType) {
for _, deprecatedOption := range deprecatedOptions {
if unused == deprecatedOption {
fixable = true
break
}
}
if fixable == true {
break
}
}
if fixable == true {
break
}
}
}
unusedErr := fmt.Errorf("unknown configuration key: '%q'",
unusedErr := fmt.Errorf("unknown configuration key: '%q'",
unused)
if fixable {
unusedErr = fmt.Errorf("Deprecated configuration key: '%s'."+
" Please call `packer fix` against your template to "+
"update your template to be compatible with the current "+
"version of Packer. Visit "+
"https://www.packer.io/docs/commands/fix/ for more detail.",
unused)
if fixable {
unusedErr = fmt.Errorf("Deprecated configuration key: '%s'."+
" Please call `packer fix` against your template to "+
"update your template to be compatible with the current "+
"version of Packer. Visit "+
"https://www.packer.io/docs/commands/fix/ for more detail.",
unused)
}
err = multierror.Append(err, unusedErr)
}
if err != nil {
return err
}
err = multierror.Append(err, unusedErr)
}
if err != nil {
return err
}
}

View File

@ -51,7 +51,7 @@ func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMap
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
PluginType: "manifest",
PluginType: "packer.post-processor.manifest",
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{

View File

@ -83,6 +83,8 @@ func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMap
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
PluginType: BuilderId,
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{