Skip to content

azd init should fail fast when --environment is missing in non-interactive mode #6775

Description

@spboyer

Problem

When running azd init --template <url> without --environment in a non-interactive context (--no-prompt or non-TTY), azd downloads the entire template repository before failing at the environment name prompt. This leaves a half-initialized directory that must be manually cleaned up before retrying.

Current execution order:

  1. initializeTemplate() — downloads and copies template files ✅ (expensive, succeeds)
  2. initializeEnv() — prompts for environment name ❌ (fails in non-interactive mode)

This is the worst outcome for automated workflows: do expensive work, then fail.

Proposed Solution

Add an early validation check in cli/azd/cmd/init.go before initializeTemplate() is called:

  • If running non-interactively (--no-prompt flag or non-TTY stdin) and --environment is not provided, return a clear error immediately:
    --environment is required when running non-interactively. Use: azd init --template <url> --environment <name>

Scope

  • Only affects non-interactive mode — interactive users still get the prompt as before
  • No changes to template download logic
  • Targeted guard, minimal code change

Impact

Prevents the frustrating download-then-fail-then-cleanup cycle for agents and CI/CD pipelines.

Metadata

Metadata

Assignees

Labels

area/core-cliCLI commands, cmd/, internal/cmd/area/error-handlingError suggestions, error framework

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions