Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions internal/command/meta_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,20 +378,26 @@ func providerFactory(meta *providercache.CachedProvider) providers.Factory {

// store the client so that the plugin can kill the child process
protoVer := client.NegotiatedVersion()
switch protoVer {
case 5:
p := raw.(*tfplugin.GRPCProvider)
p.PluginClient = client
p.Addr = meta.Provider
return p, nil
case 6:
p := raw.(*tfplugin6.GRPCProvider)
p.PluginClient = client
p.Addr = meta.Provider
return p, nil
default:
panic("unsupported protocol version")
}
return finalizeFactoryPlugin(raw, protoVer, meta.Provider, client), nil
}
}

// finalizeFactoryPlugin completes the setup of a plugin dispensed by the rpc
// client to be returned by the plugin factory.
func finalizeFactoryPlugin(rawPlugin any, protoVersion int, addr addrs.Provider, client *plugin.Client) providers.Interface {
switch protoVersion {
case 5:
p := rawPlugin.(*tfplugin.GRPCProvider)
p.PluginClient = client
p.Addr = addr
return p
case 6:
p := rawPlugin.(*tfplugin6.GRPCProvider)
p.PluginClient = client
p.Addr = addr
return p
default:
panic("unsupported protocol version")
}
}

Expand Down Expand Up @@ -460,13 +466,9 @@ func unmanagedProviderFactory(provider addrs.Provider, reattach *plugin.Reattach
// go-plugin), so client.NegotiatedVersion() always returns 0. We
// assume that an unmanaged provider reporting protocol version 0 is
// actually using proto v5 for backwards compatibility.
p := raw.(*tfplugin.GRPCProvider)
p.PluginClient = client
return p, nil
return finalizeFactoryPlugin(raw, 5, provider, client), nil
case 6:
p := raw.(*tfplugin6.GRPCProvider)
p.PluginClient = client
return p, nil
return finalizeFactoryPlugin(raw, 6, provider, client), nil
default:
return nil, fmt.Errorf("unsupported protocol version %d", protoVer)
}
Expand Down