pulumi/pulumi · error

create plugin context: %w

Error message

create plugin context: %w

What it means

The `pulumi import` command creates a plugin context (host + gRPC plumbing) before reading resources. `plugin.NewContext` failing is wrapped with "create plugin context: %w". This is an internal setup failure that prevents any import work from starting.

Source

Thrown at pkg/cmd/pulumi/operations/import.go:917

			ssml := cmdStack.NewStackSecretsManagerLoaderFromEnv()

			cwd, err := os.Getwd()
			if err != nil {
				return fmt.Errorf("get working directory: %w", err)
			}
			sink := cmdutil.Diag()
			reg := cmdCmd.NewDefaultRegistry(ctx, cmdBackend.DefaultLoginManager, ws, proj, sink, env.Global())
			pluginHost, err := pkghost.New(context.WithoutCancel(ctx), sink, sink, nil,
				pkgWorkspace.EnsureLanguageInstalled, schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,
				packageworkspace.NewResolverServer(reg))
			if err != nil {
				return fmt.Errorf("create plugin host: %w", err)
			}
			// host is owned here, closed after the context
			defer contract.IgnoreClose(pluginHost)
			pCtx, err := plugin.NewContext(ctx, sink, sink, pluginHost, nil, cwd, nil, true, nil)
			if err != nil {
				return fmt.Errorf("create plugin context: %w", err)
			}
			defer contract.IgnoreClose(pCtx)

			var importFile importFile
			if importFilePath != "" {
				if len(args) != 0 || parentSpec != "" || providerSpec != "" || len(properties) != 0 {
					contract.IgnoreError(cmd.Help())
					return errors.New("an inline resource may not be specified in conjunction with an import file")
				}
				if from != "" {
					contract.IgnoreError(cmd.Help())
					return errors.New("a converter may not be specified in conjunction with an import file")
				}
				f, err := readImportFile(importFilePath)
				if err != nil {
					return fmt.Errorf("could not read import file: %w", err)
				}
				importFile = f

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Re-run the command from an existing directory (cd to your project root).
  2. Check PULUMI_HOME/plugin cache permissions and disk space.
  3. Update the pulumi CLI and retry; include the wrapped inner error in a bug report if it persists.

Example fix

// before: run in a shell whose cwd was deleted
pulumi import ...
// after
cd /path/to/project && pulumi import ...
Defensive patterns

Strategy: retry

Validate before calling

// ensure cwd exists before invoking the CLI
if [ ! -d "$PWD" ]; then echo "cwd missing"; fi; pulumi about

Try / catch

try {
  execSync('pulumi import ...', { cwd: projectRoot })
} catch (e) {
  if (/create plugin context/.test(e.message)) retry from a valid cwd or report bug with wrapped cause
}

Prevention

When it happens

Trigger: Running `pulumi import` when plugin.NewContext(ctx, sink, sink, pluginHost, nil, cwd, nil, true, nil) fails — typically because the current working directory is invalid (deleted cwd), or plugin host startup/connection failed.

Common situations: Running the CLI from a deleted directory; corrupted PULUMI_HOME plugin cache; environment or Go plugin loading issues on the machine.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/5635ceae09ffb734. Report an issue: GitHub.