Skip to content

Commit

Permalink
Update PostProcessor interface for Packer 1.4.0
Browse files Browse the repository at this point in the history
Packer 1.4.0 introduced breaking changes to the plugin interface[1]:

  1. Builder, provisioner, and post-processor plugins now require a
     `context.Context`.
  2. Post-processor plugins also return a Boolean indicating whether the
     plugin should ignore `keep_input_artifact`.

As of writing, these changes are not documented in the plugin
documentation or release notes[2][3].

References:

  1. hashicorp/packer#7440
  2. https://github.com/hashicorp/packer/blob/4639f92f638a5186e5dcefd733dd1f77ee44de35/website/source/docs/extending/custom-post-processors.html.md
  3. https://github.com/hashicorp/packer/blob/4639f92f638a5186e5dcefd733dd1f77ee44de35/CHANGELOG.md

Fixes: #5 (#5)
  • Loading branch information
benwebber committed Apr 28, 2019
1 parent a3b8ea5 commit 5ef923d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions vhd/post-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package vhd

import (
"context"
"fmt"
"os"

Expand Down Expand Up @@ -71,10 +72,10 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {

// PostProcess is the main entry point. It calls a Provider's Convert() method
// to delegate conversion to that Provider's command-line tool.
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error) {
provider, err := providerForBuilderId(artifact.BuilderId())
if err != nil {
return nil, false, err
return nil, false, false, err
}

ui.Say(fmt.Sprintf("Converting %s image to VHD file...", provider))
Expand All @@ -87,7 +88,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
}
outputPath, err := interpolate.Render(p.config.OutputPath, &p.config.ctx)
if err != nil {
return nil, false, err
return nil, false, false, err
}

// Check if VHD file exists. Remove if the user specified `force` in the
Expand All @@ -100,20 +101,20 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
ui.Message(fmt.Sprintf("Removing existing VHD file at %s", outputPath))
os.Remove(outputPath)
} else {
return nil, false, fmt.Errorf("VHD file exists: %s\nUse the force flag to delete it.", outputPath)
return nil, false, false, fmt.Errorf("VHD file exists: %s\nUse the force flag to delete it.", outputPath)
}
}

err = provider.Convert(ui, artifact, outputPath)
if err != nil {
return nil, false, err
return nil, false, false, err
}

ui.Say(fmt.Sprintf("Converted VHD: %s", outputPath))
artifact = NewArtifact(provider.String(), outputPath)
keep := p.config.KeepInputArtifact

return artifact, keep, nil
return artifact, keep, false, nil
}

// Pick a provider to use from known builder sources.
Expand Down

0 comments on commit 5ef923d

Please sign in to comment.