diff --git a/plugin/discovery/find.go b/plugin/discovery/find.go index 923923dccc..e66ef9a844 100644 --- a/plugin/discovery/find.go +++ b/plugin/discovery/find.go @@ -147,6 +147,12 @@ func ResolvePluginPaths(paths []string) PluginMetaSet { version = parts[1] } + // Auto-installed plugins contain an extra name portion representing + // the expected plugin version, which we must trim off. + if dashX := strings.Index(version, "-X"); dashX != -1 { + version = version[:dashX] + } + if _, ok := found[nameVersion{name, version}]; ok { // Skip duplicate versions of the same plugin // (We do this during this step because after this we will be diff --git a/plugin/discovery/find_test.go b/plugin/discovery/find_test.go index 97ae8ed2c6..887a3ad959 100644 --- a/plugin/discovery/find_test.go +++ b/plugin/discovery/find_test.go @@ -53,6 +53,7 @@ func TestResolvePluginPaths(t *testing.T) { "/example/mockos_mockarch/terraform-foo-bar-V0.0.1", "/example/mockos_mockarch/terraform-foo-baz-V0.0.1", "/example/mockos_mockarch/terraform-foo-baz-V1.0.0", + "/example/mockos_mockarch/terraform-foo-baz-V2.0.0-X4", "/example/terraform-foo-bar", "/example/mockos_mockarch/terraform-foo-bar-Vbananas", "/example/mockos_mockarch/terraform-foo-bar-V", @@ -75,6 +76,11 @@ func TestResolvePluginPaths(t *testing.T) { Version: "1.0.0", Path: "/example/mockos_mockarch/terraform-foo-baz-V1.0.0", }, + { + Name: "baz", + Version: "2.0.0", + Path: "/example/mockos_mockarch/terraform-foo-baz-V2.0.0-X4", + }, { Name: "bar", Version: "0.0.0", @@ -92,6 +98,8 @@ func TestResolvePluginPaths(t *testing.T) { }, } + t.Logf("got %#v", got) + if got, want := got.Count(), len(want); got != want { t.Errorf("got %d items; want %d", got, want) }