Skip to content

When AZURE_SUBSCRIPTION_ID is set, AZURE_SUBSCRIPTION_ID isn't saved in the environment #2423

@weikanglim

Description

@weikanglim

Repro:

  1. cd <empty>
  2. azd init -> Pick minimal
  3. AZURE_SUBSCRIPTION_ID='<sub>' azd provision
  4. azd env get-values

Expected:
AZURE_SUBSCRIPTION_ID should be saved

Actual:
AZURE_SUBSCRIPTION_ID is not saved

Example:

⋊> ~/r/p/minimal on main ⨯ azd env get-values                                                                   10:36:50
AZURE_ENV_NAME="weilim-min-dev-1"
⋊> ~/r/p/minimal on main ⨯ AZURE_SUBSCRIPTION_ID='faa080af-c1d8-40ad-9cce-e1a450ca5b57' azd provision           10:36:51

Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time

? Please select an Azure location to use: 42. (US) East US 2 (eastus2)
  You can view detailed progress in the Azure Portal:
  https://portal.azure.com/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/%2Fsubscriptions%2Ffaa080af-c1d8-40ad-9cce-e1a450ca5b57%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Fweilim-min-dev-1-1686850623

  (✓) Done: Resource group: rg-weilim-min-dev-1

SUCCESS: Your application was provisioned in Azure in 39 seconds.
You can view the resources created under the resource group rg-weilim-min-dev-1 in Azure Portal:
https://portal.azure.com/#@/resource/subscriptions/faa080af-c1d8-40ad-9cce-e1a450ca5b57/resourceGroups/rg-weilim-min-dev-1/overview
⋊> ~/r/p/minimal on main ⨯ azd env get-values                                                                   10:38:41
AZURE_ENV_NAME="weilim-min-dev-1"
AZURE_LOCATION="eastus2"

This seems to be because in prompter.go, EnsureEnv calls p.env.GetSubscriptionId(), to decide whether to prompt and save the value. The implementation relies of GetSubscriptionId relies on os.Env as a fallback, which skips prompting and saving.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions