remove unused file, set up prepare() properly to work with HCL2 in vsphere-clone builder

This commit is contained in:
Megan Marsh 2020-01-13 12:33:56 -08:00
parent 9459e2233b
commit dfb45e86cc
4 changed files with 7 additions and 31 deletions

View File

@ -1,20 +0,0 @@
<component name="ProjectDictionaryState">
<dictionary name="project">
<words>
<w>abcdefghijklmnopqrstuvwxyz</w>
<w>cdrom</w>
<w>cdroms</w>
<w>datastore</w>
<w>datastores</w>
<w>esxi</w>
<w>hashicorp</w>
<w>mozilla</w>
<w>sata</w>
<w>scancode</w>
<w>vcenter</w>
<w>vmware</w>
<w>vmxnet</w>
<w>vsphere</w>
</words>
</dictionary>
</component>

View File

@ -12,25 +12,23 @@ import (
) )
type Builder struct { type Builder struct {
config *Config config Config
runner multistep.Runner runner multistep.Runner
} }
func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() }
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...) warnings, errs := b.config.Prepare()
if errs != nil { if errs != nil {
return warnings, nil, errs return warnings, nil, errs
} }
b.config = c
return warnings, nil, nil return warnings, nil, nil
} }
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("comm", &b.config.Comm)
state.Put("hook", hook) state.Put("hook", hook)
state.Put("ui", ui) state.Put("ui", ui)

View File

@ -35,14 +35,13 @@ type Config struct {
ctx interpolate.Context ctx interpolate.Context
} }
func NewConfig(raws ...interface{}) (*Config, []string, error) { func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c := new(Config)
err := config.Decode(c, &config.DecodeOpts{ err := config.Decode(c, &config.DecodeOpts{
Interpolate: true, Interpolate: true,
InterpolateContext: &c.ctx, InterpolateContext: &c.ctx,
}, raws...) }, raws...)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
errs := new(packer.MultiError) errs := new(packer.MultiError)
@ -56,8 +55,8 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...) errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
if len(errs.Errors) > 0 { if len(errs.Errors) > 0 {
return nil, nil, errs return nil, errs
} }
return c, nil, nil return nil, nil
} }

View File

@ -12,7 +12,7 @@ import (
) )
type Builder struct { type Builder struct {
config *Config config Config
runner multistep.Runner runner multistep.Runner
} }
@ -29,7 +29,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("comm", &b.config.Comm)
state.Put("hook", hook) state.Put("hook", hook)
state.Put("ui", ui) state.Put("ui", ui)