{"record":{"id":"18a3052921e63b4e","repo":"pulumi/pulumi","slug":"could-not-load-existing-project-stack-to-update-se","errorCode":null,"errorMessage":"could not load existing project stack to update secrets manager configuration: %w","messagePattern":"could not load existing project stack to update secrets manager configuration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/stack/stack_import.go","lineNumber":121,"sourceCode":"\t\t\t\t\tps, loadErr = LoadProjectStack(ctx, diag, project, s, \"\")\n\t\t\t\t}\n\t\t\t\tif loadErr != nil {\n\t\t\t\t\t// Default to an empty ProjectStack if we fail to load the existing one\n\t\t\t\t\tps = &workspace.ProjectStack{}\n\t\t\t\t}\n\t\t\t\toldConfig := deepcopy.Copy(ps).(*workspace.ProjectStack)\n\n\t\t\t\tsm, err := s.DefaultSecretManager(ctx, ps)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"could not create service secrets manager for stack %q: %w\",\n\t\t\t\t\t\ts.Ref().String(), err)\n\t\t\t\t}\n\t\t\t\tsnapshot.SecretsManager = sm\n\n\t\t\t\t// Handle if the configuration changed any of EncryptedKey, etc\n\t\t\t\tif needsSaveProjectStackAfterSecretManger(oldConfig, ps) {\n\t\t\t\t\tif loadErr != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"could not load existing project stack to update secrets manager configuration: %w\", loadErr)\n\t\t\t\t\t}\n\t\t\t\t\tif err = SaveProjectStack(ctx, s, ps, \"\"); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"saving stack config: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif err := SaveSnapshot(ctx, s, snapshot, force); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tfmt.Fprintln(cmd.OutOrStdout(), \"Import complete.\")\n\t\t\treturn nil\n\t\t},\n\t}\n\n\tconstrictor.AttachArguments(cmd, constrictor.NoArgs)\n\n\tcmd.PersistentFlags().StringVarP(","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/stack/stack_import.go#L103-L139","documentation":"During `pulumi stack import`, after a snapshot is imported the command may need to persist secrets-manager-related fields (e.g. EncryptedKey) to the existing Pulumi.<stack>.yaml. This error is thrown when that save is required but the project stack file failed to load earlier, so the updated configuration cannot be reliably written. It wraps the original load error with %w, so the root cause (parse error, missing file, permissions) is preserved in the message.","triggerScenarios":"Running `pulumi stack import` into a stack whose Pulumi.<stack>.yaml cannot be loaded (corrupt YAML, file deleted between load attempts, permission denied), while the imported snapshot changes secrets-manager configuration such that needsSaveProjectStackAfterSecretManger returns true.","commonSituations":"Importing into a stack whose config file was hand-edited into invalid YAML; running in a CI container where the stack config file is read-only or missing; the stack file was moved/renamed while the import was running.","solutions":["Inspect the wrapped loadErr at the end of the message and fix the underlying Pulumi.<stack>.yaml problem (invalid YAML, permissions).","Run `pulumi stack select <name>` (or verify Pulumi.<stack>.yaml exists in the project dir) before re-running stack import.","If the file is corrupt, restore it from version control or a backup, then re-run the import.","Re-run with proper file permissions (writable project directory) if running in CI."],"exampleFix":"# before: stack file missing/corrupt\n$ pulumi stack import -s prod -f backup.json\nerror: could not load existing project stack to update secrets manager configuration: reading Pulumi.prod.yaml: no such file\n// after: ensure the stack config exists\n$ pulumi stack select prod   # recreates/selects the stack file context\n$ pulumi stack import -s prod -f backup.json","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(\"Pulumi.\"+stackName+\".yaml\"); err != nil {\n\treturn fmt.Errorf(\"stack config missing/unreadable before import: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := pulumiStackImport(stack, snapshotFile); err != nil {\n\tvar loadErr error\n\tif strings.Contains(err.Error(), \"could not load existing project stack\") {\n\t\tloadErr = fixStackConfigAndRetry(stack)\n\t}\n\treturn err\n}","preventionTips":["Confirm Pulumi.<stack>.yaml exists and parses (pulumi config) before stack import","Keep stack config files under version control for recovery","Run imports from a writable project checkout","Avoid hand-editing stack YAML right before an import"],"tags":["cli","stack","secrets","configuration"],"backgroundTag":"stack-config-load-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}