pulumi/pulumi · error

getting environment draft definition: %w

Error message

getting environment draft definition: %w

What it means

With `--draft=<change-request-id>`, `esc env set` fetches the draft's current definition via GetEnvironmentDraft before applying the change. If that API call fails (network issue, bad draft ID, insufficient permissions, deleted draft), the error is wrapped with this message.

Source

Thrown at pkg/cmd/esc/cli/env_set.go:163

				}
				if err = yaml.Unmarshal(bytes, &yamlValue); err != nil {
					return fmt.Errorf("internal error: marshaling secret: %w", err)
				}
				yamlValue = *yamlValue.Content[0]
			}

			var def []byte
			var tag string
			if draft != "" && draft != "new" {
				def, tag, err = env.esc.client.GetEnvironmentDraft(
					ctx,
					ref.orgName,
					ref.projectName,
					ref.envName,
					draft,
				)
				if err != nil {
					return fmt.Errorf("getting environment draft definition: %w", err)
				}
			} else {
				def, tag, _, err = env.esc.client.GetEnvironment(ctx, ref.orgName, ref.projectName, ref.envName, "", false)
				if err != nil {
					return fmt.Errorf("getting environment definition: %w", err)
				}
			}

			var docNode yaml.Node
			if err := yaml.Unmarshal(def, &docNode); err != nil {
				return fmt.Errorf("unmarshaling environment definition: %w", err)
			}
			if docNode.Kind != yaml.DocumentNode {
				docNode = yaml.Node{
					Kind:    yaml.DocumentNode,
					Content: []*yaml.Node{{}},
				}
			}

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Verify the draft/change-request ID exists with `esc env draft list` (or the web UI)
  2. Run `esc login` / `pulumi login` to refresh credentials and check org access
  3. Check network connectivity/VPN/proxy to the Pulumi Cloud API
  4. Drop `--draft` to set the value directly against the current environment

Example fix

// before
esc env set my-org/my-env/k v --draft 42   // draft already merged
// after
esc env set my-org/my-env/k v              // set against current environment
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check draft existence before mutating
_, _, err := escClient.GetEnvironmentDraft(ctx, org, project, env, draftID)
if err != nil { return fmt.Errorf("draft %s unavailable: %w", draftID, err) }

Try / catch

out, err := runEscCmd("env", "set", env, path, value, "--draft", id)
if err != nil && strings.Contains(err.Error(), "getting environment draft definition") {
    return runEscCmd("env", "set", env, path, value) // fall back to direct set
}

Prevention

When it happens

Trigger: `esc env set <env> <path> <value> --draft <id>` where the Pulumi Cloud API returns an error for GetEnvironmentDraft: nonexistent or already-merged change request ID, expired/invalid auth token, or connectivity failure.

Common situations: Referencing a draft that was merged or deleted by a teammate; running in CI with a token lacking access to the org/project; offline or behind a proxy.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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