Skip to content

Commit 9fd06c1

Browse files
authored
Send a resolver target to providers during handshake (#23654)
Add a package-resolver service address to the provider handshake, mirroring the loader and mapper targets. The host serves a workspace-scoped package resolver (`packageworkspace.NewResolverServer`) and threads its address to providers as the `ProviderHandshakeRequest.ResolverTarget` field, so a provider can resolve a package specification to a concrete dependency the same way the CLI does. The resolver is wired into the production CLI commands that construct a plugin host. An end-to-end test boots a real provider, confirms it receives a usable resolver target at handshake time, and verifies a `Create` round-trips a resolved dependency back through the engine's resolver.
1 parent 1091491 commit 9fd06c1

71 files changed

Lines changed: 1521 additions & 248 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
component: engine
2+
kind: feat
3+
body: Send the address of a package resolver service to resource providers as part of the provider handshake
4+
time: 2026-06-18T00:00:00+00:00

‎pkg/backend/diy/backend.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ func (b *diyBackend) apply(
13071307
}
13081308

13091309
if op.Opts.Engine.HostFactory == nil {
1310-
op.Opts.Engine.HostFactory = backend.DefaultHostFactory
1310+
op.Opts.Engine.HostFactory = backend.DefaultHostFactory(b.GetReadOnlyCloudRegistry())
13111311
}
13121312

13131313
// Perform the update

‎pkg/backend/host.go‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,33 @@ package backend
1717
import (
1818
"context"
1919

20+
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/packageworkspace"
2021
"github.com/pulumi/pulumi/pkg/v3/codegen/convert"
2122
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
2223
"github.com/pulumi/pulumi/pkg/v3/engine"
2324
pkghost "github.com/pulumi/pulumi/pkg/v3/host"
2425
pkgWorkspace "github.com/pulumi/pulumi/pkg/v3/workspace"
2526
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
27+
"github.com/pulumi/pulumi/sdk/v3/go/common/registry"
2628
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
2729
)
2830

29-
// DefaultHostFactory is the production engine.HostFactory: it builds the standard plugin host
30-
// with language installation and the schema-loader and conversion-mapper services. The engine
31-
// supplies the diagnostic sinks and debug context so plugin logs surface in the UI as events.
32-
func DefaultHostFactory(
33-
ctx context.Context, d, statusD diag.Sink, debug plugin.DebugContext,
34-
) (plugin.Host, error) {
35-
return pkghost.New(ctx, d, statusD, debug,
36-
pkgWorkspace.EnsureLanguageInstalled,
37-
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
31+
// DefaultHostFactory builds the production engine.HostFactory: the standard plugin host with
32+
// language installation and the schema-loader, conversion-mapper, and package-resolver services.
33+
// The engine supplies the diagnostic sinks and debug context so plugin logs surface in the UI as
34+
// events. The package resolver resolves against reg, which the caller derives from the active
35+
// backend so a logged-in user resolves against their authenticated registry.
36+
func DefaultHostFactory(reg registry.Registry) engine.HostFactory {
37+
resolver := packageworkspace.NewResolverServer(reg)
38+
return func(
39+
ctx context.Context, d, statusD diag.Sink, debug plugin.DebugContext,
40+
) (plugin.Host, error) {
41+
return pkghost.New(ctx, d, statusD, debug,
42+
pkgWorkspace.EnsureLanguageInstalled,
43+
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
44+
resolver)
45+
}
3846
}
3947

40-
// Assert DefaultHostFactory satisfies the engine's factory type.
41-
var _ engine.HostFactory = DefaultHostFactory
48+
// Assert DefaultHostFactory builds the engine's factory type.
49+
var _ func(registry.Registry) engine.HostFactory = DefaultHostFactory

‎pkg/backend/httpstate/backend.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ func (b *cloudBackend) runEngineAction(
21342134
}
21352135

21362136
if op.Opts.Engine.HostFactory == nil {
2137-
op.Opts.Engine.HostFactory = backend.DefaultHostFactory
2137+
op.Opts.Engine.HostFactory = backend.DefaultHostFactory(b.GetReadOnlyCloudRegistry())
21382138
}
21392139

21402140
var plan *deploy.Plan

‎pkg/cmd/pulumi/about/about.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import (
3434
"github.com/pulumi/pulumi/pkg/v3/backend/secrets"
3535
"github.com/pulumi/pulumi/pkg/v3/backend/state"
3636
cmdBackend "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/backend"
37+
cmdCmd "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/cmd"
3738
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/constrictor"
39+
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/packageworkspace"
3840
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/ui"
3941
"github.com/pulumi/pulumi/pkg/v3/codegen/convert"
4042
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
@@ -45,6 +47,7 @@ import (
4547
pkgWorkspace "github.com/pulumi/pulumi/pkg/v3/workspace"
4648
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
4749
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
50+
cmdEnv "github.com/pulumi/pulumi/sdk/v3/go/common/env"
4851
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
4952
"github.com/pulumi/pulumi/sdk/v3/go/common/slice"
5053
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
@@ -152,9 +155,11 @@ func getSummaryAbout(
152155
addError(err, "Failed to read project")
153156
} else {
154157
projinfo := &engine.Projinfo{Proj: proj, Root: pwd}
158+
reg := cmdCmd.NewDefaultRegistry(ctx, lm, ws, proj, cmdutil.Diag(), cmdEnv.Global())
155159
pluginHost, hostErr := pkghost.New(
156160
context.WithoutCancel(ctx), cmdutil.Diag(), cmdutil.Diag(), nil, pkgWorkspace.EnsureLanguageInstalled,
157-
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
161+
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
162+
packageworkspace.NewResolverServer(reg))
158163
if hostErr != nil {
159164
addError(hostErr, "Failed to create plugin host")
160165
} else if pwd, program, pluginContext, err := engine.ProjectInfoContext(

‎pkg/cmd/pulumi/convert/convert.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ func runConvert(
215215
name = filepath.Base(cwd)
216216
}
217217

218+
reg := cmdCmd.NewDefaultRegistry(ctx, lm, ws, nil, cmdutil.Diag(), e)
219+
218220
// the plugin context uses the output directory as the working directory
219221
// of the generated program because in general, where Pulumi.yaml lives is
220222
// the root of the project.
221-
pCtx, err := packages.NewPluginContext(outDir)
223+
pCtx, err := packages.NewPluginContext(outDir, reg)
222224
if err != nil {
223225
return fmt.Errorf("create plugin host: %w", err)
224226
}
@@ -337,7 +339,6 @@ func runConvert(
337339
pCtx.Diag.Logf(sev, diag.RawMessage("", msg))
338340
}
339341

340-
reg := cmdCmd.NewDefaultRegistry(ctx, lm, ws, nil, cmdutil.Diag(), e)
341342
installCtx := packageworkspace.New(pluginstorage.Instance, ws, pCtx, stderr, stderr,
342343
nil, packageworkspace.Options{})
343344

@@ -505,7 +506,8 @@ func runConvert(
505506
projinfo := &engine.Projinfo{Proj: proj, Root: root}
506507
pluginHost, err := pkghost.New(
507508
context.WithoutCancel(ctx), cmdutil.Diag(), cmdutil.Diag(), nil, pkgWorkspace.EnsureLanguageInstalled,
508-
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
509+
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
510+
packageworkspace.NewResolverServer(reg))
509511
if err != nil {
510512
return err
511513
}
@@ -606,6 +608,7 @@ func generateAndLinkSdksForPackages(
606608

607609
diags, err := packages.GenSDK(
608610
pctx.Request(),
611+
registry,
609612
language,
610613
tempOut,
611614
pkgSchema,

‎pkg/cmd/pulumi/do/do.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
cmdCmd "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/cmd"
3636
cmdConvert "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/convert"
3737
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/packages"
38+
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/packageworkspace"
3839
"github.com/pulumi/pulumi/pkg/v3/codegen/convert"
3940
"github.com/pulumi/pulumi/pkg/v3/codegen/pcl"
4041
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
@@ -75,9 +76,11 @@ func NewDoCmd(
7576
// uncancellable. Plugin logs route through the command's diagnostics sinks, so a
7677
// provider's output reaches the command's stdout/stderr the same way it does without a
7778
// pre-constructed host.
79+
reg := cmdCmd.NewDefaultRegistry(ctx, lm, ws, nil, d, env.Global())
7880
return pkghost.New(
7981
context.WithoutCancel(ctx), d, statusD, nil, pkgWorkspace.EnsureLanguageInstalled,
80-
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
82+
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
83+
packageworkspace.NewResolverServer(reg))
8184
}
8285
}
8386
if loadConverterPlugin == nil {

‎pkg/cmd/pulumi/install/install.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ func NewInstallCmd(ws pkgWorkspace.Context) *cobra.Command {
129129

130130
span := opentracing.SpanFromContext(ctx)
131131
projinfo := &engine.Projinfo{Proj: proj, Root: root}
132+
reg := cmdCmd.NewDefaultRegistry(
133+
cmd.Context(), cmdBackend.DefaultLoginManager, pkgWorkspace.Instance, proj, cmdutil.Diag(), env.Global())
132134
pluginHost, err := pkghost.New(
133135
context.WithoutCancel(ctx), cmdutil.Diag(), cmdutil.Diag(), nil, pkgWorkspace.EnsureLanguageInstalled,
134-
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
136+
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
137+
packageworkspace.NewResolverServer(reg))
135138
if err != nil {
136139
return err
137140
}

‎pkg/cmd/pulumi/metadata/metadata.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ import (
3232
git "github.com/go-git/go-git/v6"
3333

3434
"github.com/pulumi/pulumi/pkg/v3/backend"
35+
cmdBackend "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/backend"
36+
cmdCmd "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/cmd"
37+
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/packageworkspace"
3538
"github.com/pulumi/pulumi/pkg/v3/codegen/convert"
3639
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
3740
"github.com/pulumi/pulumi/pkg/v3/engine"
3841
pkghost "github.com/pulumi/pulumi/pkg/v3/host"
3942
pkgWorkspace "github.com/pulumi/pulumi/pkg/v3/workspace"
4043
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
4144
"github.com/pulumi/pulumi/sdk/v3/go/common/constant"
45+
cmdEnv "github.com/pulumi/pulumi/sdk/v3/go/common/env"
4246
"github.com/pulumi/pulumi/sdk/v3/go/common/promise"
4347
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
4448
"github.com/pulumi/pulumi/sdk/v3/go/common/util/agentdetect"
@@ -81,9 +85,12 @@ func GetLanguageRuntimeMetadata(
8185
}
8286

8387
projinfo := &engine.Projinfo{Proj: proj, Root: root}
88+
reg := cmdCmd.NewDefaultRegistry(
89+
ctx, cmdBackend.DefaultLoginManager, pkgWorkspace.Instance, proj, cmdutil.Diag(), cmdEnv.Global())
8490
pluginHost, err := pkghost.New(
8591
context.WithoutCancel(ctx), cmdutil.Diag(), cmdutil.Diag(), nil, pkgWorkspace.EnsureLanguageInstalled,
86-
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
92+
schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
93+
packageworkspace.NewResolverServer(reg))
8794
if err != nil {
8895
return nil, err
8996
}

‎pkg/cmd/pulumi/operations/import.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ import (
3737
"github.com/pulumi/pulumi/pkg/v3/backend/display"
3838
"github.com/pulumi/pulumi/pkg/v3/backend/secrets"
3939
cmdBackend "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/backend"
40+
cmdCmd "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/cmd"
4041
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/config"
4142
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/constrictor"
4243
cmdConvert "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/convert"
4344
cmdDiag "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/diag"
4445
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/metadata"
46+
"github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/packageworkspace"
4547
cmdStack "github.com/pulumi/pulumi/pkg/v3/cmd/pulumi/stack"
4648
"github.com/pulumi/pulumi/pkg/v3/codegen/convert"
4749
"github.com/pulumi/pulumi/pkg/v3/codegen/pcl"
@@ -731,8 +733,10 @@ func NewImportCmd() *cobra.Command {
731733
return fmt.Errorf("get working directory: %w", err)
732734
}
733735
sink := cmdutil.Diag()
736+
reg := cmdCmd.NewDefaultRegistry(ctx, cmdBackend.DefaultLoginManager, ws, proj, sink, env.Global())
734737
pluginHost, err := pkghost.New(context.WithoutCancel(ctx), sink, sink, nil,
735-
pkgWorkspace.EnsureLanguageInstalled, schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
738+
pkgWorkspace.EnsureLanguageInstalled, schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
739+
packageworkspace.NewResolverServer(reg))
736740
if err != nil {
737741
return fmt.Errorf("create plugin host: %w", err)
738742
}
@@ -962,8 +966,10 @@ func NewImportCmd() *cobra.Command {
962966
}
963967
sink := cmdutil.Diag()
964968

969+
innerReg := cmdCmd.NewDefaultRegistry(ctx, cmdBackend.DefaultLoginManager, ws, proj, sink, env.Global())
965970
innerHost, err := pkghost.New(context.WithoutCancel(ctx), sink, sink, nil,
966-
pkgWorkspace.EnsureLanguageInstalled, schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext)
971+
pkgWorkspace.EnsureLanguageInstalled, schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
972+
packageworkspace.NewResolverServer(innerReg))
967973
if err != nil {
968974
return nil, nil, err
969975
}

0 commit comments

Comments
 (0)