pulumi/pulumi · error

opening environment: %w

Error message

opening environment: %w

What it means

getStackConfigurationFromProjectStack wraps any failure from openStackEnv with 'opening environment: %w'. It means the Pulumi Cloud/ESC environment referenced by the stack (via `environment:` in Pulumi.yaml or --env overrides) could not be opened — org not resolvable, backend lacks environment support, or the environment definition failed to load/compile.

Source

Thrown at pkg/cmd/pulumi/config/io.go:140

	config, err := getStackConfigurationFromProjectStack(ctx, s, project, sm, workspaceStack, envOverrides)
	if err != nil {
		return backend.StackConfiguration{}, nil, err
	}
	return config, sm, nil
}

func getStackConfigurationFromProjectStack(
	ctx context.Context,
	stack backend.Stack,
	project *workspace.Project,
	sm secrets.Manager,
	workspaceStack *workspace.ProjectStack,
	envOverrides []string,
) (backend.StackConfiguration, error) {
	env, diags, err := openStackEnv(ctx, stack, workspaceStack, envOverrides)
	if err != nil {
		return backend.StackConfiguration{}, fmt.Errorf("opening environment: %w", err)
	}
	if len(diags) != 0 {
		// This is a non-command helper; we don't have a *cobra.Command writer
		// to thread through here. Writes go to the process streams directly.
		printESCDiagnostics(os.Stderr, diags) //nolint:forbidigo
		return backend.StackConfiguration{}, errors.New("opening environment: too many errors")
	}

	var pulumiEnv esc.Value
	if env != nil {
		warnOnNoEnvironmentEffects(os.Stdout, env) //nolint:forbidigo

		pulumiEnv = env.Properties["pulumiConfig"]

		_, environ, secrets, _, err := cli.PrepareEnvironment(env, nil)
		if err != nil {
			return backend.StackConfiguration{}, fmt.Errorf("preparing environment: %w", err)
		}

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Check the `environment:` entry in Pulumi.yaml points to an existing ESC environment in the correct org (`pulumi env ls` in the org)
  2. Verify you are logged into the Pulumi Cloud backend — ESC environments require it
  3. Confirm the org the stack belongs to is correct; re-create or re-select the stack if OrgName cannot be determined
  4. Inspect stderr diagnostics printed by printESCDiagnostics for the underlying ESC error

Example fix

// before (Pulumi.yaml)
environment:
  my-env-prod
// after
environment:
  myorg/my-env-prod
Defensive patterns

Strategy: validation

Validate before calling

# before running config commands
pulumi env ls --org myorg            # environment exists?
grep -A2 'environment:' Pulumi.yaml  # reference matches org/name

Type guard

func supportsEnvs(b backend.Backend) bool {
    _, ok := b.(backend.EnvironmentsBackend)
    return ok
}

Try / catch

cfg, err := getStackConfigurationFromProjectStack(...)
if err != nil && strings.HasPrefix(err.Error(), "opening environment:") {
    return fmt.Errorf("check `environment:` in Pulumi.yaml and ESC access: %w", err)
}

Prevention

When it happens

Trigger: getStackConfigurationWithFallback → getStackConfigurationFromProjectStack with a stack whose workspaceStack defines an ESC environment: the stack's backend does not implement EnvironmentsBackend, the stack has no OrgName, the referenced YAML environment doesn't exist, or it fails YAML/ESC evaluation at open time.

Common situations: Using `pulumi config` commands against a stack in a backend (e.g. some self-hosted setups) without ESC environment support; typo'd or removed environment name in Pulumi.yaml; running against a stack not associated with an organization; network/permission failures fetching the environment from Pulumi Cloud.

Related errors


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