pulumi/pulumi · error

could not load existing project stack to update secrets…

Error message

could not load existing project stack to update secrets manager configuration: %w

What it means

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.

Solutions

  1. Inspect the wrapped loadErr at the end of the message and fix the underlying Pulumi.<stack>.yaml problem (invalid YAML, permissions).
  2. Run `pulumi stack select <name>` (or verify Pulumi.<stack>.yaml exists in the project dir) before re-running stack import.
  3. If the file is corrupt, restore it from version control or a backup, then re-run the import.
  4. Re-run with proper file permissions (writable project directory) if running in CI.

Example fix

# before: stack file missing/corrupt
$ pulumi stack import -s prod -f backup.json
error: could not load existing project stack to update secrets manager configuration: reading Pulumi.prod.yaml: no such file
// after: ensure the stack config exists
$ pulumi stack select prod   # recreates/selects the stack file context
$ pulumi stack import -s prod -f backup.json
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat("Pulumi."+stackName+".yaml"); err != nil {
	return fmt.Errorf("stack config missing/unreadable before import: %w", err)
}

Try / catch

if err := pulumiStackImport(stack, snapshotFile); err != nil {
	var loadErr error
	if strings.Contains(err.Error(), "could not load existing project stack") {
		loadErr = fixStackConfigAndRetry(stack)
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at pkg/cmd/pulumi/stack/stack_import.go:121

					ps, loadErr = LoadProjectStack(ctx, diag, project, s, "")
				}
				if loadErr != nil {
					// Default to an empty ProjectStack if we fail to load the existing one
					ps = &workspace.ProjectStack{}
				}
				oldConfig := deepcopy.Copy(ps).(*workspace.ProjectStack)

				sm, err := s.DefaultSecretManager(ctx, ps)
				if err != nil {
					return fmt.Errorf("could not create service secrets manager for stack %q: %w",
						s.Ref().String(), err)
				}
				snapshot.SecretsManager = sm

				// Handle if the configuration changed any of EncryptedKey, etc
				if needsSaveProjectStackAfterSecretManger(oldConfig, ps) {
					if loadErr != nil {
						return fmt.Errorf("could not load existing project stack to update secrets manager configuration: %w", loadErr)
					}
					if err = SaveProjectStack(ctx, s, ps, ""); err != nil {
						return fmt.Errorf("saving stack config: %w", err)
					}
				}
			}

			if err := SaveSnapshot(ctx, s, snapshot, force); err != nil {
				return err
			}
			fmt.Fprintln(cmd.OutOrStdout(), "Import complete.")
			return nil
		},
	}

	constrictor.AttachArguments(cmd, constrictor.NoArgs)

	cmd.PersistentFlags().StringVarP(

View on GitHub (pinned to 793f7b2e16)