pulumi/pulumi · error

creating temporary directory for template: %w

Error message

creating temporary directory for template: %w

What it means

Thrown when `pulumi new` runs non-interactively without a template, so it creates a temporary directory (os.MkdirTemp) to hold a minimal Pulumi.yaml, and that call fails. This typically indicates the OS temp directory is missing, unwritable, or TMPDIR points somewhere invalid.

Source

Thrown at pkg/cmd/pulumi/project/newcmd/new.go:211

	if args.offline {
		scope = cmdTemplates.ScopeLocal
	}
	templateSource := cmdTemplates.New(ctx,
		args.templateNameOrURL, scope, cmdTemplates.TemplateKindPulumiProject, env.Global())
	defer contract.IgnoreClose(templateSource)

	cmdTemplate, err := resolveTemplate(templateSource, args, opts, args.selectOne)
	if err != nil {
		return err
	}

	var template cmdTemplates.ProjectTemplate
	if cmdTemplate == nil {
		// Template might be nil if we're running in non-interactive mode and didn't pass a template to choose. In
		// that case we'll write a minimal Pulumi.yaml.
		temp, err := os.MkdirTemp("", "pulumi-new")
		if err != nil {
			return fmt.Errorf("creating temporary directory for template: %w", err)
		}
		// Write the minimal template to the temp directory
		err = os.WriteFile(filepath.Join(temp, "Pulumi.yaml"), []byte(`name: ${PROJECT}`), 0o600)
		if err != nil {
			return fmt.Errorf("writing minimal Pulumi.yaml: %w", err)
		}

		template = cmdTemplates.ProjectTemplate{
			Dir:         temp,
			ProjectName: "${PROJECT}",
		}
	} else {
		template, err = cmdTemplate.Download(ctx)
		if err != nil {
			return err
		}
	}

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Verify TMPDIR (or /tmp) exists and is writable: `ls -ld /tmp; touch /tmp/probe`
  2. Fix the TMPDIR environment variable to a valid writable path and rerun
  3. Free disk space if the filesystem is full
  4. Pass an explicit template (`pulumi new typescript`) so the temp-dir fallback is not needed

Example fix

// before
TMPDIR=/nonexistent pulumi new --yes
// after
TMPDIR=/tmp pulumi new --yes
Defensive patterns

Strategy: validation

Validate before calling

test -d "${TMPDIR:-/tmp}" && touch "${TMPDIR:-/tmp}/.pulumi-probe" || export TMPDIR=/tmp

Prevention

When it happens

Trigger: Running `pulumi new --yes` (non-interactive) with no template argument, when os.MkdirTemp("", "pulumi-new") fails due to a bad TMPDIR, full disk, or missing /tmp.

Common situations: TMPDIR set to a non-existent path in CI; read-only or full /tmp in a container; sandboxed environment blocking temp directory creation.

Related errors


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