Skip to content

Commit e26ec58

Browse files
authored
Merge pull request #34380 from hashicorp/jbardin/unmanaged-plugin-schema-cache
ensure unmanaged plugins have an address
2 parents be33a7e + a9cc3ba commit e26ec58

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

internal/command/meta_providers.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,26 @@ func providerFactory(meta *providercache.CachedProvider) providers.Factory {
378378

379379
// store the client so that the plugin can kill the child process
380380
protoVer := client.NegotiatedVersion()
381-
switch protoVer {
382-
case 5:
383-
p := raw.(*tfplugin.GRPCProvider)
384-
p.PluginClient = client
385-
p.Addr = meta.Provider
386-
return p, nil
387-
case 6:
388-
p := raw.(*tfplugin6.GRPCProvider)
389-
p.PluginClient = client
390-
p.Addr = meta.Provider
391-
return p, nil
392-
default:
393-
panic("unsupported protocol version")
394-
}
381+
return finalizeFactoryPlugin(raw, protoVer, meta.Provider, client), nil
382+
}
383+
}
384+
385+
// finalizeFactoryPlugin completes the setup of a plugin dispensed by the rpc
386+
// client to be returned by the plugin factory.
387+
func finalizeFactoryPlugin(rawPlugin any, protoVersion int, addr addrs.Provider, client *plugin.Client) providers.Interface {
388+
switch protoVersion {
389+
case 5:
390+
p := rawPlugin.(*tfplugin.GRPCProvider)
391+
p.PluginClient = client
392+
p.Addr = addr
393+
return p
394+
case 6:
395+
p := rawPlugin.(*tfplugin6.GRPCProvider)
396+
p.PluginClient = client
397+
p.Addr = addr
398+
return p
399+
default:
400+
panic("unsupported protocol version")
395401
}
396402
}
397403

@@ -460,13 +466,9 @@ func unmanagedProviderFactory(provider addrs.Provider, reattach *plugin.Reattach
460466
// go-plugin), so client.NegotiatedVersion() always returns 0. We
461467
// assume that an unmanaged provider reporting protocol version 0 is
462468
// actually using proto v5 for backwards compatibility.
463-
p := raw.(*tfplugin.GRPCProvider)
464-
p.PluginClient = client
465-
return p, nil
469+
return finalizeFactoryPlugin(raw, 5, provider, client), nil
466470
case 6:
467-
p := raw.(*tfplugin6.GRPCProvider)
468-
p.PluginClient = client
469-
return p, nil
471+
return finalizeFactoryPlugin(raw, 6, provider, client), nil
470472
default:
471473
return nil, fmt.Errorf("unsupported protocol version %d", protoVer)
472474
}

0 commit comments

Comments
 (0)