hashicorp / packer-plugin-sdk

Packer Plugin SDK enables building Packer plugins (builders, provisioners, or post-processors) to manage any service providers or custom in-house solutions
Mozilla Public License 2.0
34 stars 47 forks source link

`packer-sdc plugin-check` outputs cryptic error string: Version needs to be set #125

Open mschuchard opened 2 years ago

mschuchard commented 2 years ago

When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.

Overview of the Issue

Executing packer-sdc plugin-check <plugin binary> outputs the following error string:

2022/08/22 17:21:02 Version needs to be set

Although the packer-sdc documentation and usage has no information about this, and I saw no error message similar to this in the source code, I did notice there seems to be a potential secret requirement for plugins: a version/version.go file. This seemed like a possible fix. However, even after populating this file appropriately according to two other official plugins as a reference, the behavior did not deviate at all from the above. Thus, this behavior is unfortunately contrary to published documentation, usage, source code, and other official plugins as a reference.

I should also note the plugin currently passes acceptance testing with the latest version of Packer and the Packer SDK, so it should also conceivably pass the plugin-check too.

Reproduction Steps

packer-sdc plugin-check <plugin binary>

Packer Plugin SDK version

0.3.1

Operating system and Environment details

Ubuntu 22.04

Log Fragments and crash.log files

n/a

mschuchard commented 2 years ago

Update that the plugin check also fails in goreleaser. I removed it from the hooks, and the released binaries install and behave completely correctly within a normal init/build workflow in Packer 1.7.10. This may help to debug, and also to further prove this error is a false positive.

mschuchard commented 1 year ago

I figured this out eventually. The following is absent from documentation:

// version/version.go
package version

import "github.com/hashicorp/packer-plugin-sdk/version"

var (
  // Version is the main version number that is being run at the moment.
  Version = "1.2.0"

  // VersionPrerelease is A pre-release marker for the Version. If this is ""
  // (empty string) then it means that it is a final release. Otherwise, this
  // is a pre-release such as "dev" (in development), "beta", "rc1", etc.
  VersionPrerelease = ""

  // PluginVersion is used by the plugin set to allow Packer to recognize
  // what version this plugin is.
  PluginVersion = version.InitializePluginVersion(Version, VersionPrerelease)
)

// main.go
import "<module>/version"

func main() {
  ...
  packerPluginSet.SetVersion(version.PluginVersion)
}

This fixes the issue, so adding this information to the documentation would be sufficient here.