fix: SWA deployment fails with BadRequest "default" environment name — add configurable environment support#8588
fix: SWA deployment fails with BadRequest "default" environment name — add configurable environment support#8588Copilot wants to merge 7 commits into
Conversation
… error Co-authored-by: jongio <2163001+jongio@users.noreply.github.com>
|
@copilot - You did a quick fix. You need to go deeper an analyze swa deployment mechanics and create a better fix that allows us to specify environments when needed and default to the right ones. |
Working on a deeper fix. The proper solution adds a services:
web:
host: staticwebapp
staticwebapp:
environment: staging # optional; omit for production
The |
Co-authored-by: jongio <2163001+jongio@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates azd’s Azure Static Web Apps (SWA) deployment flow to avoid the newly-invalid explicit "default" environment name and adds azure.yaml support for targeting named preview environments.
Changes:
- SWA CLI deploy now conditionally includes
--envonly when a non-empty environment name is provided (production deploys omit--env). azure.yamlgains astaticwebapp.environmentservice option, and the SWA target uses it consistently for deploy + REST API polling/endpoints.- Tests and docs are updated to cover/describe the new behavior.
Show a summary per file
| File | Description |
|---|---|
| docs/reference/azure-yaml-schema.md | Documents new staticwebapp.environment service option and examples. |
| cli/azd/pkg/tools/swa/swa.go | Omits --env for production (empty environment) and preserves named environment support. |
| cli/azd/pkg/tools/swa/swa_test.go | Updates deploy arg assertions and adds coverage for named environments. |
| cli/azd/pkg/project/service_target_staticwebapp.go | Introduces StaticWebAppOptions + API environment mapping and threads configured environment through deploy/endpoints/verification. |
| cli/azd/pkg/project/service_target_staticwebapp_test.go | Adds unit tests for environment mapping and YAML parsing behavior. |
| cli/azd/pkg/project/service_config.go | Adds staticwebapp options to ServiceConfig for YAML configuration. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 6
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
|
@rajeshkamal5050 @kristenwomack Please prioritize the review, swa deploys are broken. |
…ing --env The SWA CLI treats "production"/"prod" as special values that deploy to the production environment. Omitting --env deploys to "preview" which is a behavioral regression. This fix passes --env production for production deploys and normalizes the "default" API identifier to "production" for the CLI. Addresses review feedback from JeffreyCA on PR #8588. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thanks @JeffreyCA - you're absolutely right. Omitting
Verified against SWA CLI source: https://github.com/Azure/static-web-apps-cli/blob/2400910265443a8adf9c93f1c19c557b93794381/src/cli/commands/deploy/deploy.ts#L257-L259 |
|
The changes look good to me. Left a nit. However, we should get confirmation from SWA team that this is an intentional breaking change. I didn't find any communication to the public that the deployment service will start rejecting "default" as the environment name. If the change is more than just rejecting "default" as the environment name, maybe azd can do more validation locally. |
7049960 to
f0e6908
Compare
Adds the staticwebapp configuration object with its environment property to both schemas/alpha and schemas/v1.0. Also adds a conditional rule so the staticwebapp key is only valid when host is staticwebapp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f0e6908 to
23e15fd
Compare
…t mappings - apiEnvironmentName() now normalizes 'production'/'prod' to 'default' for the Azure REST API (which doesn't recognize those as production identifiers) - swaCliEnvironment() now also normalizes 'prod' to 'production' for the CLI - Tests use swaCliProductionEnvironment constant instead of literal strings - Added test cases for 'prod' shorthand Addresses review feedback from JasonYeMSFT and copilot-pull-request-reviewer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run azure-dev - cli |
JeffreyCA
left a comment
There was a problem hiding this comment.
Thanks for fixing this!
|
Azure Pipelines successfully started running 1 pipeline(s). |
vhvb1989
left a comment
There was a problem hiding this comment.
Review: Potential conflict with swa-cli.config.json and new azure.yaml field
Environment override concern
The SWA CLI supports setting env in swa-cli.config.json (either top-level or nested under deploy:). The CLI merges options with this precedence: CLI flags > config file > defaults.
Since azd always passes --env as an explicit CLI flag (swa.go:87), it unconditionally overrides any env value in swa-cli.config.json. This was already broken before this PR (--env default), and remains broken after (--env production). If a user sets env: "staging" in their config file for a preview environment deploy, azd silently overrides it.
Three sources of truth
Adding staticwebapp.environment to azure.yaml creates three potential sources for the same value:
azure.yaml → staticwebapp.environmentswa-cli.config.json → env(ordeploy.env)- The SWA CLI's own default (
"preview")
The PR always passes the azure.yaml value (or "production" if empty) as --env, which means in config-file mode the env setting in swa-cli.config.json is effectively dead.
Suggestion
I'd prefer to avoid introducing a new field in azure.yaml for SWA-specific configuration without a broader team discussion. Users with SWA services typically rely on swa-cli.config.json as their source of truth, and adding a parallel config surface creates confusion about which one wins.
For the core fix ("default" → "production"), consider:
- Opinionated mode (no
swa-cli.config.json): pass--env production(as the PR does today). - Config-file mode (
swa-cli.config.jsonpresent): omit--enventirely and let the SWA CLI resolveenvfrom its own config. This respects the existing contract that the config file is the source of truth when present.
This avoids the breaking change fix while keeping the two modes consistent with their design intent. The azure.yaml field can be discussed separately with the team if there's a need for it.
d620872 to
c308b1e
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
154a046 to
4cf38cb
Compare
…ield Per vhvb1989's review, simplify the approach: - When swa-cli.config.json is present (config-file mode): omit --env entirely and let the SWA CLI resolve the environment from its own config - When no config file (opinionated mode): pass --env production to fix the BadRequest caused by the old --env default Remove the StaticWebAppOptions struct and azure.yaml staticwebapp field - the team will discuss whether to add a parallel config surface separately. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4cf38cb to
517f463
Compare
|
Thanks @vhvb1989, great call. I've updated the approach:
Removed the \StaticWebAppOptions\ struct and \�zure.yaml\ \staticwebapp\ field. We can discuss adding a parallel config surface separately if there's a need for it. The latest push reflects this simplified approach. |
Summary
Fixes SWA deployment failure caused by passing
--env defaultto the SWA CLI, which triggers a BadRequest error.Root Cause
The Azure REST API uses
defaultto identify the production environment, but the SWA CLI does NOT recognizedefaultas a valid environment name. The SWA CLI instead treatsproductionandprodas special values that deploy to the production environment.Fix
--env productionfor production deploys (instead of the old--env default). Named preview environments pass--env <name>as before.defaultfor production when querying deployment status/endpoints. Normalizeproduction/prodtodefaultfor API calls.StaticWebAppOptionstoazure.yamlwith an optionalenvironmentfield for targeting named preview environments.Changes
cli/azd/pkg/tools/swa/swa.go: Always pass--env(caller provides correct value)cli/azd/pkg/project/service_target_staticwebapp.go: AddedswaCliEnvironment()and updatedapiEnvironmentName()with normalizationcli/azd/pkg/project/service_target_staticwebapp_test.go: Tests for both methodscli/azd/pkg/tools/swa/swa_test.go: Updated for production deploy testsdocs/reference/azure-yaml-schema.md: Documented staticwebapp configurationschemas/alpha/azure.yaml.jsonandschemas/v1.0/azure.yaml.json: Added schemaFixes #8583