pulumi/pulumi · error

could not import deployment: %w

Error message

could not import deployment: %w

What it means

After building the deployment, `pulumi stack import` calls `backend.ImportStackDeployment` to upload and apply it. If the backend rejects or fails the import, the error is wrapped as "could not import deployment: %w". This surfaces server-side or backend-specific failures (authentication, stack state locks, size limits, server errors) to the CLI user.

Source

Thrown at pkg/cmd/pulumi/stack/io.go:574

	if snapshot.PendingOperations != nil {
		for _, op := range snapshot.PendingOperations {
			msg := fmt.Sprintf(
				"removing pending operation '%s' on '%s' from snapshot", op.Type, op.Resource.URN,
			)
			cmdutil.Diag().Warningf(diag.Message(op.Resource.URN, msg))
		}

		snapshot.PendingOperations = nil
	}

	dep, err := stack.SerializeUntypedDeployment(ctx, snapshot, nil /*opts*/)
	if err != nil {
		return fmt.Errorf("constructing deployment for upload: %w", err)
	}

	// Now perform the deployment.
	if err = backend.ImportStackDeployment(ctx, s, dep); err != nil {
		return fmt.Errorf("could not import deployment: %w", err)
	}
	return nil
}

// RequireCloudStack resolves the named stack (or the current stack when empty), requires that
// it lives on the Pulumi Cloud backend, and returns the cloud API client along with the
// StackIdentifier needed to address the stack via REST API endpoints.
func RequireCloudStack(
	ctx context.Context, sink diag.Sink, ws pkgWorkspace.Context, lm cmdBackend.LoginManager,
	stackName string,
) (*client.Client, client.StackIdentifier, error) {
	opts := display.Options{Color: cmdutil.GetGlobalColorization()}

	s, err := RequireStack(ctx, sink, ws, lm, stackName, LoadOnly, opts, "")
	if err != nil {
		return nil, client.StackIdentifier{}, fmt.Errorf("resolving stack: %w", err)
	}
	cloudStack, ok := s.(httpstate.Stack)

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Inspect the wrapped `%w` message; if it is auth-related, re-authenticate with `pulumi login`.
  2. If a state lock is reported, wait for/abort the concurrent operation (e.g. `pulumi cancel` or clear the lock per backend guidance).
  3. Retry after network errors; the upload is idempotent until accepted.
  4. Check the Pulumi Cloud status/HTTP details for server-side 5xx and retry later.

Example fix

// before
pulumi stack import --file export.json
// error: could not import deployment: getting stack: 401 unauthorized
// after
pulumi logout && pulumi login
pulumi stack import --file export.json
Defensive patterns

Strategy: retry

Validate before calling

# Ensure you are authenticated and the stack is reachable before importing
pulumi whoami
pulumi stack select <target>   # fails fast if stack is missing/inaccessible

Try / catch

# Inspect the wrapped cause and retry only on transient errors
try:
    import_stack(deployment)
except BackendError as e:
    if is_auth_error(e):
        run(['pulumi', 'login'])
        import_stack(deployment)
    elif is_transient(e):  # 5xx / network
        retry_with_backoff(import_stack, deployment, attempts=3)
    else:
        raise  # state lock, validation, etc.

Prevention

When it happens

Trigger: `pulumi stack import --file ...` where `ImportStackDeployment` errors: expired/missing `pulumi login` credentials, the stack is locked by another operation, the Pulumi Cloud service returns 4xx/5xx, or a local/diy backend fails writing the state blob.

Common situations: Stale login token (`pulumi logout`/`pulumi login` needed); concurrent operations holding a state lock on the stack; importing a very large deployment hitting service size limits; network outage mid-upload.

Related errors


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