Merge pull request #10579 from hashicorp/fix-single-plugin-loading

Fix issue when loading single plugin type `packer-provisioner-comment` built with latest SDK
This commit is contained in:
Megan Marsh 2021-02-05 14:06:27 -08:00 committed by GitHub
commit 2324f433f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,7 +121,9 @@ func (c *PluginConfig) discoverExternalComponents(path string) error {
}
for pluginName, pluginPath := range pluginPaths {
newPath := pluginPath // this needs to be stored in a new variable for the func below
c.Builders.Set(pluginName, c.Client(newPath).Builder)
c.Builders.Set(pluginName, func() (packersdk.Builder, error) {
return c.Client(newPath).Builder()
})
externallyUsed = append(externallyUsed, pluginName)
}
if len(externallyUsed) > 0 {
@ -136,7 +138,9 @@ func (c *PluginConfig) discoverExternalComponents(path string) error {
}
for pluginName, pluginPath := range pluginPaths {
newPath := pluginPath // this needs to be stored in a new variable for the func below
c.PostProcessors.Set(pluginName, c.Client(newPath).PostProcessor)
c.PostProcessors.Set(pluginName, func() (packersdk.PostProcessor, error) {
return c.Client(newPath).PostProcessor()
})
externallyUsed = append(externallyUsed, pluginName)
}
if len(externallyUsed) > 0 {
@ -151,12 +155,15 @@ func (c *PluginConfig) discoverExternalComponents(path string) error {
}
for pluginName, pluginPath := range pluginPaths {
newPath := pluginPath // this needs to be stored in a new variable for the func below
c.Provisioners.Set(pluginName, c.Client(newPath).Provisioner)
c.Provisioners.Set(pluginName, func() (packersdk.Provisioner, error) {
return c.Client(newPath).Provisioner()
})
externallyUsed = append(externallyUsed, pluginName)
}
if len(externallyUsed) > 0 {
sort.Strings(externallyUsed)
log.Printf("using external provisioners %v", externallyUsed)
externallyUsed = nil
}
pluginPaths, err = c.discoverSingle(filepath.Join(path, "packer-datasource-*"))