{"record":{"id":"9f24f107c97e8a3a","repo":"pulumi/pulumi","slug":"could-not-import-deployment-w","errorCode":null,"errorMessage":"could not import deployment: %w","messagePattern":"could not import deployment: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/stack/io.go","lineNumber":574,"sourceCode":"\tif snapshot.PendingOperations != nil {\n\t\tfor _, op := range snapshot.PendingOperations {\n\t\t\tmsg := fmt.Sprintf(\n\t\t\t\t\"removing pending operation '%s' on '%s' from snapshot\", op.Type, op.Resource.URN,\n\t\t\t)\n\t\t\tcmdutil.Diag().Warningf(diag.Message(op.Resource.URN, msg))\n\t\t}\n\n\t\tsnapshot.PendingOperations = nil\n\t}\n\n\tdep, err := stack.SerializeUntypedDeployment(ctx, snapshot, nil /*opts*/)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"constructing deployment for upload: %w\", err)\n\t}\n\n\t// Now perform the deployment.\n\tif err = backend.ImportStackDeployment(ctx, s, dep); err != nil {\n\t\treturn fmt.Errorf(\"could not import deployment: %w\", err)\n\t}\n\treturn nil\n}\n\n// RequireCloudStack resolves the named stack (or the current stack when empty), requires that\n// it lives on the Pulumi Cloud backend, and returns the cloud API client along with the\n// StackIdentifier needed to address the stack via REST API endpoints.\nfunc RequireCloudStack(\n\tctx context.Context, sink diag.Sink, ws pkgWorkspace.Context, lm cmdBackend.LoginManager,\n\tstackName string,\n) (*client.Client, client.StackIdentifier, error) {\n\topts := display.Options{Color: cmdutil.GetGlobalColorization()}\n\n\ts, err := RequireStack(ctx, sink, ws, lm, stackName, LoadOnly, opts, \"\")\n\tif err != nil {\n\t\treturn nil, client.StackIdentifier{}, fmt.Errorf(\"resolving stack: %w\", err)\n\t}\n\tcloudStack, ok := s.(httpstate.Stack)","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/stack/io.go#L556-L592","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Inspect the wrapped `%w` message; if it is auth-related, re-authenticate with `pulumi login`.","If a state lock is reported, wait for/abort the concurrent operation (e.g. `pulumi cancel` or clear the lock per backend guidance).","Retry after network errors; the upload is idempotent until accepted.","Check the Pulumi Cloud status/HTTP details for server-side 5xx and retry later."],"exampleFix":"// before\npulumi stack import --file export.json\n// error: could not import deployment: getting stack: 401 unauthorized\n// after\npulumi logout && pulumi login\npulumi stack import --file export.json","handlingStrategy":"retry","validationCode":"# Ensure you are authenticated and the stack is reachable before importing\npulumi whoami\npulumi stack select <target>   # fails fast if stack is missing/inaccessible","typeGuard":null,"tryCatchPattern":"# Inspect the wrapped cause and retry only on transient errors\ntry:\n    import_stack(deployment)\nexcept BackendError as e:\n    if is_auth_error(e):\n        run(['pulumi', 'login'])\n        import_stack(deployment)\n    elif is_transient(e):  # 5xx / network\n        retry_with_backoff(import_stack, deployment, attempts=3)\n    else:\n        raise  # state lock, validation, etc.","preventionTips":["Run `pulumi login` / refresh tokens before long CI import jobs.","Avoid concurrent operations on the same stack; check for state locks first.","Monitor api.pulumi.com status for outages before bulk imports."],"tags":["backend","import","upload"],"backgroundTag":"backend-import-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}