Repository: Azure/azure-dev
Pull request #5061: Update parameters resolution for bicep provider
Author: login: vhvb1989
Created: 2025-04-08T20:47:40Z | Merged: 2025-04-18T00:42:43Z

fix: https://github.com/Azure/azure-dev/issues/5059

This change corrects a bug after #5010 where we changed the way `location` works.

- Making AZD to auto-detect any parameter mapped to AZURE_LOCATION (in parameters.json) to be considered a location parameter and prompt for it with the list of locations.
- Making AZD to ignore parameters mapped to ENV VARS when the ENV VAR is not defined. In the past AZD was taking empty string as a value for these mappings.
- Making AZD to ignore if parameters.json is missing. AZD will consider this the same as a parameter.json with no parameters defined.


Diff:
diff --git a/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go b/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
index 3a7bb6f19fb..407c2aa643d 100644
--- a/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
+++ b/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
@@ -142,36 +142,11 @@ func (p *BicepProvider) EnsureEnv(ctx context.Context) error {
 			return err
 		}
 
-		// We only want to prompt for a location if the location is actually a parameter.
-		// But if the AZURE_LOCATION is set in system env, we want to set if in the AZD .env, just like the prompt
-		// for location used to do in the past (after prompting or finding the location in system env).
-		_, locationInAzdEnv := p.env.Dotenv()[environment.LocationEnvVarName]
-		if !locationInAzdEnv {
-			if location, locationInSystemEnv := os.LookupEnv(environment.LocationEnvVarName); locationInSystemEnv {
-				p.env.SetLocation(location)
-				if err := p.envManager.Save(ctx, p.env); err != nil {
-					return fmt.Errorf("saving location: %w", err)
-				}
-			}
-		}
-
-		// if location is a parameter and is not in system env, ensureParameters() will prompt for it, supporting all the
-		// metadata and settings as any other bicep parameter.
-		deploymentParams, err := p.ensureParameters(ctx, compileResult.Template)
+		_, err = p.ensureParameters(ctx, compileResult.Template)
 		if err != nil {
 			return err
 		}
 
-		// Check if location is a parameter and if it is not set in the AZD env
-		// If it is not set, we need to prompt for it.
-		if locParam, hasLocationParam := deploymentParams["location"]; hasLocationParam {
-			if _, locationInAzdEnv := p.env.Dotenv()[environment.LocationEnvVarName]; !locationInAzdEnv {
-				p.env.SetLocation(locParam.Value.(string))
-				if err := p.envManager.Save(ctx, p.env); err != nil {
-					return fmt.Errorf("saving location to env: %w", err)
-				}
-			}
-		}
 	}
 
 	scope, err := compileResult.Template.TargetScope()
@@ -181,6 +156,8 @@ func (p *BicepProvider) EnsureEnv(ctx context.Context) error {
 
 	if scope == azure.DeploymentScopeResourceGroup {
 		if p.env.Getenv(environment.ResourceGroupEnvVarName) == "" {
+			// Prompt Resource Group supports creating a new resource group
+			// And prompts for a location as part of creating a new resource group
 			rgName, err := p.prompters.PromptResourceGroup(ctx, prompt.PromptResourceOptions{})
 			if err != nil {
 				return err
@@ -1544,9 +1521,14 @@ func (p *BicepProvider) createOutputParameters(
 	return outputParams
 }
 
+type loadParametersResult struct {
+	parameters     map[string]azure.ArmParameter
+	locationParams []string
+}
+
 // loadParameters reads the parameters file template for environment/module specified by Options,
 // doing environment and command substitutions, and returns the values.
-func (p *BicepProvider) loadParameters(ctx context.Context) (map[string]azure.ArmParameter, error) {
+func (p *BicepProvider) loadParameters(ctx context.Context) (loadParametersResult, error) {
 	parametersFilename := fmt.Sprintf("%s.parameters.json", p.options.Module)
 	parametersRoot := p.options.Path
 
@@ -1556,40 +1538,103 @@ func (p *BicepProvider) loadParameters(ctx context.Context) (map[string]azure.Ar
 
 	paramFilePath := filepath.Join(parametersRoot, parametersFilename)
 	parametersBytes, err := os.ReadFile(paramFilePath)
+	// if the file does not exist, we return an empty parameters map
+	// This makes AZD to support deploying bicep modules without parameters file, assuming AZD prompts for all required
+	// parameters.
+	if os.IsNotExist(err) {
+		log.Printf("parameters file %s does not exist, using empty parameters", paramFilePath)
+		return loadParametersResult{}, nil
+	}
 	if err != nil {
-		return nil, fmt.Errorf("reading parameters.json: %w", err)
+		return loadParametersResult{}, fmt.Errorf("reading parameters.json: %w", err)
 	}
 
 	principalId, err := p.curPrincipal.CurrentPrincipalId(ctx)
 	if err != nil {
-		return nil, fmt.Errorf("fetching current principal id: %w", err)
+		return loadParametersResult{}, fmt.Errorf("fetching current principal id: %w", err)
 	}
 
-	replaced, err := envsubst.Eval(string(parametersBytes), func(name string) string {
-		if name == environment.PrincipalIdEnvVarName {
-			return principalId
-		}
-
-		return p.env.Getenv(name)
-	})
-	if err != nil {
-		return nil, fmt.Errorf("substituting environment variables inside parameter file: %w", err)
+	var decodedParamsFile azure.ArmParameterFile
+	if err := json.Unmarshal(parametersBytes, &decodedParamsFile); err != nil {
+		return loadParametersResult{}, fmt.Errorf("error unmarshalling Bicep template parameters: %w", err)
 	}
 
-	if cmdsubst.ContainsCommandInvocation(replaced, cmdsubst.SecretOrRandomPasswordCommandName) {
-		cmdExecutor := cmdsubst.NewSecretOrRandomPasswordExecutor(p.keyvaultService, p.env.GetSubscriptionId())
-		replaced, err = cmdsubst.Eval(ctx, replaced, cmdExecutor)
+	parametersMappedToAzureLocation := []string{}
+	resolvedParams := map[string]azure.ArmParameter{}
+
+	// resolving each parameter to keep track of the name during the resolution.
+	// We used to resolve all the file before, supporting env var substitution at any part of the file.
+	// We want to support substitution only for the parameter value.
+	// We also need to identify which parameters are mapped to AZURE_LOCATION (if any).
+	// We also want to exclude parameters mapped to env vars which env var is not set (instead of using empty string).
+	for paramName, param := range decodedParamsFile.Parameters {
+		paramBytes, err := json.Marshal(param)
 		if err != nil {
-			return nil, fmt.Errorf("substituting command output inside parameter file: %w", err)
+			return loadParametersResult{}, fmt.Errorf("error decoding deployment parameter %s: %w", paramName, err)
+		}
+		var hasUnsetEnvVar bool
+		// envsubst.Eval handles env var substitution and default values like ${VAR=default}
+		replaced, err := envsubst.Eval(string(paramBytes), func(name string) string {
+			if name == environment.PrincipalIdEnvVarName {
+				return principalId
+			}
+			if name == environment.LocationEnvVarName {
+				parametersMappedToAzureLocation = append(parametersMappedToAzureLocation, paramName)
+			}
+			if _, isDefined := p.env.LookupEnv(name); !isDefined {
+				hasUnsetEnvVar = true
+			}
+			return p.env.Getenv(name)
+		})
+		if err != nil {
+			return loadParametersResult{}, fmt.Errorf("substituting environment variables for %s: %w", paramName, err)
+		}
+		// resolve `secretOrRandomPassword` -> this is a way to ask AZD to generate a password for the user and
+		// store it in a Key Vault. But if the Key Vault and secret exists, AZD just takes the secret from there.
+		if cmdsubst.ContainsCommandInvocation(replaced, cmdsubst.SecretOrRandomPasswordCommandName) {
+			cmdExecutor := cmdsubst.NewSecretOrRandomPasswordExecutor(p.keyvaultService, p.env.GetSubscriptionId())
+			replaced, err = cmdsubst.Eval(ctx, replaced, cmdExecutor)
+			if err != nil {
+				return loadParametersResult{}, fmt.Errorf("substituting command output inside parameter file: %w", err)
+			}
 		}
-	}
 
-	var armParameters azure.ArmParameterFile
-	if err := json.Unmarshal([]byte(replaced), &armParameters); err != nil {
-		return nil, fmt.Errorf("error unmarshalling Bicep template parameters: %w", err)
+		var resolvedParam azure.ArmParameter
+		if err := json.Unmarshal([]byte(replaced), &resolvedParam); err != nil {
+			return loadParametersResult{}, fmt.Errorf("error unmarshalling Bicep template parameters: %w", err)
+		}
+		if resolvedParam.Value == nil && resolvedParam.KeyVaultReference == nil {
+			// ignore parameters that are not set
+			continue
+		}
+		if resolvedParam.Value != nil && resolvedParam.KeyVaultReference != nil {
+			return loadParametersResult{}, fmt.Errorf(
+				"parameter %s has both a value and a keyvault reference: %w", paramName, err)
+		}
+		if resolvedParam.KeyVaultReference != nil {
+			// parameter defined using a key vault reference. AZD does not validate the key vault reference
+			// if there is an issue with it, the deployment will fail.
+			resolvedParams[paramName] = resolvedParam
+			continue
+		}
+		stringValue, isString := resolvedParam.Value.(string)
+		if !isString {
+			continue
+		}
+
+		// After previous checks, we know resolvedParam.Value is not nil
+		if stringValue == "" && hasUnsetEnvVar {
+			// parameter is empty and has an unset env var
+			continue
+		}
+		// all other cases here represent a valid resolved parameter
+		resolvedParams[paramName] = resolvedParam
 	}
 
-	return armParameters.Parameters, nil
+	return loadParametersResult{
+		parameters:     resolvedParams,
+		locationParams: parametersMappedToAzureLocation,
+	}, nil
 }
 
 type compiledBicepParamResult struct {
@@ -1872,15 +1917,38 @@ func inputsParameter(
 	}, wroteNewInput, nil
 }
 
-// Ensures the provisioning parameters are valid and prompts the user for input as needed
+// ensureParameters validates that all parameters from the template are defined.
+// Parameters values can be defined in the parameters file (main.parameters.json). This file supports mapping values to
+// environment variables.
+// If a parameter is not defined in the parameters file AND there is not a default value defined in the template for it,
+// AZD will prompt the user for a value.
+// Parameters mapped to env var ${AZURE_LOCATION} are identified as location parameters for AZD during prompting. AZD will
+// prompt just for one location and save the value in AZD's .env file as AZURE_LOCATION and the value is used for all
+// parameters mapped to that env var.
+// AZD supports resolving env vars with a default value defined in the parameters file using the syntax
+// ${AZURE_LOCATION=defaultValue}. If the env var is not set, the default value will be used.
 func (p *BicepProvider) ensureParameters(
 	ctx context.Context,
 	template azure.ArmTemplate,
 ) (azure.ArmParameters, error) {
-	parameters, err := p.loadParameters(ctx)
+	//snapshot the AZURE_LOCATIOn in azd env if it is set in System env
+	locationSystemEnv, hasLocation := os.LookupEnv(environment.LocationEnvVarName)
+	_, hasAzdLocation := p.env.Dotenv()[environment.LocationEnvVarName]
+	if hasLocation && !hasAzdLocation && locationSystemEnv != "" {
+		p.env.SetLocation(locationSystemEnv)
+		if err := p.envManager.Save(ctx, p.env); err != nil {
+			return nil, fmt.Errorf("saving location to .env: %w", err)
+		}
+	}
+	// using loadParameters to resolve the parameters file (usually main.parameters.json)
+	// parameters with a mapping to env vars are resolved.
+	// Parameters mapped to env vars that are not set in the environment are removed from the parameters file
+	parametersResult, err := p.loadParameters(ctx)
 	if err != nil {
 		return nil, fmt.Errorf("resolving bicep parameters file: %w", err)
 	}
+	parameters := parametersResult.parameters
+	locationParameters := parametersResult.locationParams
 
 	if len(template.Parameters) == 0 {
 		return azure.ArmParameters{}, nil
@@ -1896,6 +1964,39 @@ func (p *BicepProvider) ensureParameters(
 		param azure.ArmTemplateParameterDefinition
 	}
 
+	// make all parameters mapped to AZURE_LOCATION env var to be location parameters
+	for _, key := range sortedKeys {
+		param := template.Parameters[key]
+		if slices.Contains(locationParameters, key) {
+			azdMetadata, hasAzdMetadata := param.AzdMetadata()
+			if !hasAzdMetadata {
+				azdMetadata = azure.AzdMetadata{
+					Type: to.Ptr(azure.AzdMetadataTypeLocation),
+				}
+			}
+			if azdMetadata.Type == nil {
+				azdMetadata.Type = to.Ptr(azure.AzdMetadataTypeLocation)
+			}
+			if azdMetadata.Type != nil && *azdMetadata.Type != azure.AzdMetadataTypeLocation {
+				return nil, fmt.Errorf(
+					"parameter %s is mapped to AZURE_LOCATION but has a different azd metadata type: %s."+
+						"Parameters mapped to AZURE_LOCATION can only be typed as location",
+					key,
+					*azdMetadata.Type)
+			}
+			mdBytes, err := json.Marshal(azdMetadata)
+			if err != nil {
+				return nil, fmt.Errorf("marshalling azd metadata: %w", err)
+			}
+			if param.Metadata == nil {
+				param.Metadata = map[string]json.RawMessage{"azd": mdBytes}
+			} else {
+				param.Metadata["azd"] = mdBytes
+			}
+			template.Parameters[key] = param
+		}
+	}
+
 	for _, key := range sortedKeys {
 		param := template.Parameters[key]
 		parameterType := p.mapBicepTypeToInterfaceType(param.Type)
@@ -2032,7 +2133,7 @@ func (p *BicepProvider) ensureParameters(
 				key := prompt.key
 
 				// Otherwise, prompt for the value.
-				value, err := p.promptForParameter(ctx, key, prompt.param)
+				value, err := p.promptForParameter(ctx, key, prompt.param, locationParameters)
 				if err != nil {
 					return nil, fmt.Errorf("prompting for value: %w", err)
 				}
diff --git a/cli/azd/pkg/infra/provisioning/bicep/prompt.go b/cli/azd/pkg/infra/provisioning/bicep/prompt.go
index bce0d6daf63..06e08b90743 100644
--- a/cli/azd/pkg/infra/provisioning/bicep/prompt.go
+++ b/cli/azd/pkg/infra/provisioning/bicep/prompt.go
@@ -17,6 +17,7 @@ import (
 	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices"
 	"github.com/azure/azure-dev/cli/azd/pkg/account"
 	"github.com/azure/azure-dev/cli/azd/pkg/azure"
+	"github.com/azure/azure-dev/cli/azd/pkg/environment"
 	"github.com/azure/azure-dev/cli/azd/pkg/input"
 	"github.com/azure/azure-dev/cli/azd/pkg/output"
 	"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
@@ -228,6 +229,7 @@ func (p *BicepProvider) promptForParameter(
 	ctx context.Context,
 	key string,
 	param azure.ArmTemplateParameterDefinition,
+	mappedToAzureLocationParams []string,
 ) (any, error) {
 	securedParam := "parameter"
 	isSecuredParam := param.Secure()
@@ -238,25 +240,19 @@ func (p *BicepProvider) promptForParameter(
 	help, _ := param.Description()
 	azdMetadata, _ := param.AzdMetadata()
 	paramType := p.mapBicepTypeToInterfaceType(param.Type)
-	// parameter `location` is a special case for azd, as it can be set in the environment
-	// and its value must be persisted in the .env file as AZURE_LOCATION
-	isLocationParam := key == "location"
 
 	var value any
 
-	if isLocationParam {
-		if paramType != provisioning.ParameterTypeString {
-			return nil, fmt.Errorf("location parameter must be a string")
-		}
-		envLoc := p.env.GetLocation()
-		if envLoc != "" {
-			return envLoc, nil
-		}
-	}
-
 	if paramType == provisioning.ParameterTypeString &&
-		(isLocationParam || (azdMetadata.Type != nil &&
-			*azdMetadata.Type == azure.AzdMetadataTypeLocation)) {
+		azdMetadata.Type != nil && *azdMetadata.Type == azure.AzdMetadataTypeLocation {
+
+		// when more than one parameter is mapped to AZURE_LOCATION and AZURE_LOCATION is not set in the environment,
+		// AZD will prompt just once and immediately set the value in the .env for the next parameter to re-use the value
+		paramIsMappedToAzureLocation := slices.Contains(mappedToAzureLocationParams, key)
+		valueFromEnv, valueDefinedInEnv := p.env.LookupEnv(environment.LocationEnvVarName)
+		if paramIsMappedToAzureLocation && valueDefinedInEnv {
+			return valueFromEnv, nil
+		}
 
 		// location can be combined with allowedValues and with usageName metadata
 		// allowedValues == nil => all locations are allowed
@@ -287,6 +283,14 @@ func (p *BicepProvider) promptForParameter(
 		if err != nil {
 			return nil, err
 		}
+
+		if paramIsMappedToAzureLocation && !valueDefinedInEnv {
+			// set the location in the environment variable
+			p.env.SetLocation(location)
+			if err := p.envManager.Save(ctx, p.env); err != nil {
+				return nil, fmt.Errorf("setting location in environment variable: %w", err)
+			}
+		}
 		value = location
 	} else if paramType == provisioning.ParameterTypeString &&
 		azdMetadata.Type != nil &&
diff --git a/cli/azd/pkg/infra/provisioning/bicep/prompt_test.go b/cli/azd/pkg/infra/provisioning/bicep/prompt_test.go
index 03940d933ae..cb401a9ec72 100644
--- a/cli/azd/pkg/infra/provisioning/bicep/prompt_test.go
+++ b/cli/azd/pkg/infra/provisioning/bicep/prompt_test.go
@@ -67,7 +67,7 @@ func TestPromptForParameter(t *testing.T) {
 
 			value, err := p.promptForParameter(*mockContext.Context, "testParam", azure.ArmTemplateParameterDefinition{
 				Type: tc.paramType,
-			})
+			}, nil)
 
 			require.NoError(t, err)
 			require.Equal(t, tc.expected, value)
@@ -191,7 +191,7 @@ func TestPromptForParameterValidation(t *testing.T) {
 				return ret, nil
 			})
 
-			value, err := p.promptForParameter(*mockContext.Context, "testParam", tc.param)
+			value, err := p.promptForParameter(*mockContext.Context, "testParam", tc.param, nil)
 			require.NoError(t, err)
 			require.Equal(t, tc.expected, value)
 
@@ -227,7 +227,7 @@ func TestPromptForParameterAllowedValues(t *testing.T) {
 	value, err := p.promptForParameter(*mockContext.Context, "testParam", azure.ArmTemplateParameterDefinition{
 		Type:          "string",
 		AllowedValues: to.Ptr([]any{"three", "good", "choices"}),
-	})
+	}, nil)
 
 	require.NoError(t, err)
 	require.Equal(t, "good", value)
@@ -235,7 +235,7 @@ func TestPromptForParameterAllowedValues(t *testing.T) {
 	value, err = p.promptForParameter(*mockContext.Context, "testParam", azure.ArmTemplateParameterDefinition{
 		Type:          "int",
 		AllowedValues: to.Ptr([]any{10, 20, 30}),
-	})
+	}, nil)
 
 	require.NoError(t, err)
 	require.Equal(t, 20, value)
@@ -295,7 +295,7 @@ func TestPromptForParametersLocation(t *testing.T) {
 		Metadata: map[string]json.RawMessage{
 			"azd": json.RawMessage(`{"type": "location"}`),
 		},
-	})
+	}, nil)
 
 	require.NoError(t, err)
 	require.Equal(t, "eastus2", value)
@@ -313,7 +313,7 @@ func TestPromptForParametersLocation(t *testing.T) {
 			"azd": json.RawMessage(`{"type": "location"}`),
 		},
 		AllowedValues: &[]any{"westus"},
-	})
+	}, nil)
 
 	require.NoError(t, err)
 	require.Equal(t, "westus", value)
diff --git a/cli/azd/pkg/prompt/prompter.go b/cli/azd/pkg/prompt/prompter.go
index a73a44bdfa9..7edfb17a1dd 100644
--- a/cli/azd/pkg/prompt/prompter.go
+++ b/cli/azd/pkg/prompt/prompter.go
@@ -190,6 +190,14 @@ func (p *DefaultPrompter) PromptResourceGroupFrom(
 		return groups[choice-1].Name, nil
 	}
 
+	if location == "" {
+		loc, err := p.PromptLocation(ctx, subscriptionId, "Select a location to create the resource group in:", nil, nil)
+		if err != nil {
+			return "", fmt.Errorf("prompting for location: %w", err)
+		}
+		location = loc
+	}
+
 	name, err := p.console.Prompt(ctx, input.ConsoleOptions{
 		Message:      "Enter a name for the new resource group:",
 		DefaultValue: options.DefaultName,


Reviews:
user: login: JeffreyCA
body: I tried deploying the template `microsoft/deploy-your-ai-application-in-production` (mentioned in #5059) to an **existing RG** but it's still failing:

>   (x) Failed: Log Analytics workspace: log-jc-new-loc (1.726s)
  |===    | Creating/Updating resources
ERROR: error executing step command 'provision': deployment failed: error deploying infrastructure: deploying to resource group:

> Deployment Error Details:
> LocationRequired: The location property is required for this definition.
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-08T21:25:45Z
user: login: weikanglim
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-14T21:26:14Z
user: login: vhvb1989
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-17T05:27:33Z
user: login: rajeshkamal5050
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-17T18:16:18Z
user: login: weikanglim
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-17T21:41:19Z
user: login: vhvb1989
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-17T22:04:07Z
user: login: JeffreyCA
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-17T22:07:07Z

Review comments:
diff_hunk: @@ -190,6 +190,22 @@ func (p *DefaultPrompter) PromptResourceGroupFrom(
 		return groups[choice-1].Name, nil
 	}
 
+	// make sure there is a subscription and location
+	if subscriptionId == "" {
+		sub, err := p.PromptSubscription(ctx, "Select a subscription to create the resource group in:")
path: cli/azd/pkg/prompt/prompter.go
user: login: weikanglim
body: I'm curious if we would ever get here. If I'm reading it right, I suspect that if `subscriptionId` was empty, L154 which makes a call to `ListResourceGroup` would have failed:

```golang
	// Get current resource groups
	groups, err := p.resourceService.ListResourceGroup(ctx, subscriptionId, nil)
```
created_at: 2025-04-14T21:26:13Z
author_association: CONTRIBUTOR
diff_hunk: @@ -190,6 +190,22 @@ func (p *DefaultPrompter) PromptResourceGroupFrom(
 		return groups[choice-1].Name, nil
 	}
 
+	// make sure there is a subscription and location
+	if subscriptionId == "" {
+		sub, err := p.PromptSubscription(ctx, "Select a subscription to create the resource group in:")
path: cli/azd/pkg/prompt/prompter.go
user: login: vhvb1989
body: Not right now. But, the same assumption was made for the location before the changes from this PR.
This types of assumptions are hard to validate for future changes. For example, if we ever want to make asking for subscription optional, or use this method somewhere else before the Sub is already requested.

I think this is a better way to let methods to self-protect from future changes, not depending on external assumptions
created_at: 2025-04-17T05:27:33Z
author_association: MEMBER
diff_hunk: @@ -190,6 +190,22 @@ func (p *DefaultPrompter) PromptResourceGroupFrom(
 		return groups[choice-1].Name, nil
 	}
 
+	// make sure there is a subscription and location
+	if subscriptionId == "" {
+		sub, err := p.PromptSubscription(ctx, "Select a subscription to create the resource group in:")
path: cli/azd/pkg/prompt/prompter.go
user: login: weikanglim
body: I see. If that is the intended use-case, does it make sense to move it to the start of this function right before we use `subscriptionId`? 
created_at: 2025-04-17T21:41:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -190,6 +190,22 @@ func (p *DefaultPrompter) PromptResourceGroupFrom(
 		return groups[choice-1].Name, nil
 	}
 
+	// make sure there is a subscription and location
+	if subscriptionId == "" {
+		sub, err := p.PromptSubscription(ctx, "Select a subscription to create the resource group in:")
path: cli/azd/pkg/prompt/prompter.go
user: login: vhvb1989
body: decided to remove it and use `p.resourceService.ListResourceGroup(ctx, subscriptionId, nil)` as the guard here.
tks
created_at: 2025-04-17T22:04:07Z
author_association: MEMBER

PR comments:
user: login: azure-sdk
created_at: 2025-04-17T22:48:41Z
body: <!-- #comment-cli-pr -->
## Azure Dev CLI Install Instructions

### Install scripts

#### MacOS/Linux

> May elevate using `sudo` on some platforms and configurations

bash:
```
curl -fsSL https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/uninstall-azd.sh | bash;
curl -fsSL https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/install-azd.sh | bash -s -- --base-url https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061 --version '' --verbose --skip-verify
```

pwsh:
```
Invoke-RestMethod 'https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/uninstall-azd.ps1' -OutFile uninstall-azd.ps1; ./uninstall-azd.ps1
Invoke-RestMethod 'https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/install-azd.ps1' -OutFile install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061' -Version '' -SkipVerify -Verbose
```


#### Windows

PowerShell install

```
powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/uninstall-azd.ps1' > uninstall-azd.ps1; ./uninstall-azd.ps1;"
powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/install-azd.ps1' > install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061' -Version '' -SkipVerify -Verbose;"
```

MSI install
```
powershell -c "irm 'https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-windows-amd64.msi' -OutFile azd-windows-amd64.msi; msiexec /i azd-windows-amd64.msi /qn"
```

### Standalone Binary

* Linux -
    * x86_64 - https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-linux-amd64.tar.gz
    * ARM64 - https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-linux-arm64.tar.gz
* MacOS -
    * x86_64 - https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-darwin-amd64.zip
    * ARM64 - https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-darwin-arm64.zip
* Windows -
    * x86_64 - https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-windows-amd64.zip
    * ARM64 - https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-windows-arm64-alpha.zip

### MSI

* x86_64 - https://azuresdkartifacts.z5.web.core.windows.net/azd/standalone/pr/5061/azd-windows-amd64.msi

## Documentation

<details>
<summary>learn.microsoft.com documentation</summary>

---
title: Azure Developer CLI reference
description: This article explains the syntax and parameters for the various Azure Developer CLI commands.
author: alexwolfmsft
ms.author: alexwolf
ms.date: 04/17/2025
ms.service: azure-dev-cli
ms.topic: conceptual
ms.custom: devx-track-azdevcli
---

# Azure Developer CLI reference

This article explains the syntax and parameters for the various Azure Developer CLI commands.

## azd

The Azure Developer CLI (`azd`) is an open-source tool that helps onboard and manage your application on Azure

### Options

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --docs         Opens the documentation for azd in your web browser.
  -h, --help         Gets help for azd.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd add](#azd-add): Add a component to your project. (Alpha)
* [azd auth](#azd-auth): Authenticate with Azure.
* [azd config](#azd-config): Manage azd configurations (ex: default Azure subscription, location).
* [azd deploy](#azd-deploy): Deploy the application's code to Azure.
* [azd down](#azd-down): Delete Azure resources for an application.
* [azd env](#azd-env): Manage environments.
* [azd hooks](#azd-hooks): Develop, test and run hooks for an application. (Beta)
* [azd infra](#azd-infra): Manage your Azure infrastructure.
* [azd init](#azd-init): Initialize a new application.
* [azd monitor](#azd-monitor): Monitor a deployed application. (Beta)
* [azd package](#azd-package): Packages the application's code to be deployed to Azure. (Beta)
* [azd pipeline](#azd-pipeline): Manage and configure your deployment pipelines. (Beta)
* [azd provision](#azd-provision): Provision the Azure resources for an application.
* [azd restore](#azd-restore): Restores the application's dependencies. (Beta)
* [azd show](#azd-show): Display information about your app and its resources.
* [azd template](#azd-template): Find and view template details. (Beta)
* [azd up](#azd-up): Provision Azure resources, and deploy your project with a single command.
* [azd version](#azd-version): Print the version number of Azure Developer CLI.

## azd add

Add a component to your project. (Alpha)

```azdeveloper
azd add [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd add in your web browser.
  -h, --help   Gets help for add.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd auth

Authenticate with Azure.

### Options

```azdeveloper
      --docs   Opens the documentation for azd auth in your web browser.
  -h, --help   Gets help for auth.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd auth login](#azd-auth-login): Log in to Azure.
* [azd auth logout](#azd-auth-logout): Log out of Azure.
* [Back to top](#azd)

## azd auth login

Log in to Azure.

### Synopsis

Log in to Azure.

When run without any arguments, log in interactively using a browser. To log in using a device code, pass
--use-device-code.

To log in as a service principal, pass --client-id and --tenant-id as well as one of: --client-secret,
--client-certificate, or --federated-credential-provider.

To log in using a managed identity, pass --managed-identity, which will use the system assigned managed identity.
To use a user assigned managed identity, pass --client-id in addition to --managed-identity with the client id of
the user assigned managed identity you wish to use.


```azdeveloper
azd auth login [flags]
```

### Options

```azdeveloper
      --check-status                           Checks the log-in status instead of logging in.
      --client-certificate string              The path to the client certificate for the service principal to authenticate with.
      --client-id string                       The client id for the service principal to authenticate with.
      --client-secret string                   The client secret for the service principal to authenticate with. Set to the empty string to read the value from the console.
      --docs                                   Opens the documentation for azd auth login in your web browser.
      --federated-credential-provider string   The provider to use to acquire a federated token to authenticate with.
  -h, --help                                   Gets help for login.
      --managed-identity                       Use a managed identity to authenticate.
      --redirect-port int                      Choose the port to be used as part of the redirect URI during interactive login.
      --tenant-id string                       The tenant id or domain name to authenticate with.
      --use-device-code[=true]                 When true, log in by using a device code instead of a browser.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd auth](#azd-auth): Authenticate with Azure.
* [Back to top](#azd)

## azd auth logout

Log out of Azure.

### Synopsis

Log out of Azure

```azdeveloper
azd auth logout [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd auth logout in your web browser.
  -h, --help   Gets help for logout.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd auth](#azd-auth): Authenticate with Azure.
* [Back to top](#azd)

## azd config

Manage azd configurations (ex: default Azure subscription, location).

### Synopsis

Manage the Azure Developer CLI user configuration, which includes your default Azure subscription and location.

Available since `azure-dev-cli_0.4.0-beta.1`.

The easiest way to configure `azd` for the first time is to run [`azd init`](#azd-init). The subscription and location you select will be stored in the `config.json` file located in the config directory. To configure `azd` anytime afterwards, you'll use [`azd config set`](#azd-config-set).

The default value of the config directory is: 
* $HOME/.azd on Linux and macOS
* %USERPROFILE%\.azd on Windows


The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

### Options

```azdeveloper
      --docs   Opens the documentation for azd config in your web browser.
  -h, --help   Gets help for config.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd config get](#azd-config-get): Gets a configuration.
* [azd config list-alpha](#azd-config-list-alpha): Display the list of available features in alpha stage.
* [azd config reset](#azd-config-reset): Resets configuration to default.
* [azd config set](#azd-config-set): Sets a configuration.
* [azd config show](#azd-config-show): Show all the configuration values.
* [azd config unset](#azd-config-unset): Unsets a configuration.
* [Back to top](#azd)

## azd config get

Gets a configuration.

### Synopsis

Gets a configuration in the configuration path.

The default value of the config directory is:
* `$HOME/.azd` on Linux and macOS
* `%USERPROFILE%\.azd` on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

```azdeveloper
azd config get <path> [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd config get in your web browser.
  -h, --help   Gets help for get.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd config](#azd-config): Manage azd configurations (ex: default Azure subscription, location).
* [Back to top](#azd)

## azd config list-alpha

Display the list of available features in alpha stage.

```azdeveloper
azd config list-alpha [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd config list-alpha in your web browser.
  -h, --help   Gets help for list-alpha.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd config](#azd-config): Manage azd configurations (ex: default Azure subscription, location).
* [Back to top](#azd)

## azd config reset

Resets configuration to default.

### Synopsis

Resets all configuration in the configuration path.

The default value of the config directory is:
* `$HOME/.azd` on Linux and macOS
* `%USERPROFILE%\.azd` on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable to the default.

```azdeveloper
azd config reset [flags]
```

### Options

```azdeveloper
      --docs    Opens the documentation for azd config reset in your web browser.
  -f, --force   Force reset without confirmation.
  -h, --help    Gets help for reset.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd config](#azd-config): Manage azd configurations (ex: default Azure subscription, location).
* [Back to top](#azd)

## azd config set

Sets a configuration.

### Synopsis

Sets a configuration in the configuration path.

The default value of the config directory is:
* `$HOME/.azd` on Linux and macOS
* `%USERPROFILE%\.azd` on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

```azdeveloper
azd config set <path> <value> [flags]
```

### Examples

```azdeveloper
azd config set defaults.subscription <yourSubscriptionID>
azd config set defaults.location eastus
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd config set in your web browser.
  -h, --help   Gets help for set.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd config](#azd-config): Manage azd configurations (ex: default Azure subscription, location).
* [Back to top](#azd)

## azd config show

Show all the configuration values.

### Synopsis

Show all configuration values in the configuration path.

The default value of the config directory is:
* `$HOME/.azd` on Linux and macOS
* `%USERPROFILE%\.azd` on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

```azdeveloper
azd config show [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd config show in your web browser.
  -h, --help   Gets help for show.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd config](#azd-config): Manage azd configurations (ex: default Azure subscription, location).
* [Back to top](#azd)

## azd config unset

Unsets a configuration.

### Synopsis

Removes a configuration in the configuration path.

The default value of the config directory is:
* `$HOME/.azd` on Linux and macOS
* `%USERPROFILE%\.azd` on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

```azdeveloper
azd config unset <path> [flags]
```

### Examples

```azdeveloper
azd config unset defaults.location
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd config unset in your web browser.
  -h, --help   Gets help for unset.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd config](#azd-config): Manage azd configurations (ex: default Azure subscription, location).
* [Back to top](#azd)

## azd deploy

Deploy the application's code to Azure.

```azdeveloper
azd deploy <service> [flags]
```

### Options

```azdeveloper
      --all                   Deploys all services that are listed in azure.yaml
      --docs                  Opens the documentation for azd deploy in your web browser.
  -e, --environment string    The name of the environment to use.
      --from-package string   Deploys the packaged service located at the provided path. Supports zipped file packages (file path) or container images (image tag).
  -h, --help                  Gets help for deploy.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd down

Delete Azure resources for an application.

```azdeveloper
azd down [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd down in your web browser.
  -e, --environment string   The name of the environment to use.
      --force                Does not require confirmation before it deletes resources.
  -h, --help                 Gets help for down.
      --purge                Does not require confirmation before it permanently deletes resources that are soft-deleted by default (for example, key vaults).
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd env

Manage environments.

### Options

```azdeveloper
      --docs   Opens the documentation for azd env in your web browser.
  -h, --help   Gets help for env.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env get-value](#azd-env-get-value): Get specific environment value.
* [azd env get-values](#azd-env-get-values): Get all environment values.
* [azd env list](#azd-env-list): List environments.
* [azd env new](#azd-env-new): Create a new environment and set it as the default.
* [azd env refresh](#azd-env-refresh): Refresh environment settings by using information from a previous infrastructure provision.
* [azd env select](#azd-env-select): Set the default environment.
* [azd env set](#azd-env-set): Manage your environment settings.
* [azd env set-secret](#azd-env-set-secret): Set a <name> as a reference to a Key Vault secret in the environment.
* [Back to top](#azd)

## azd env get-value

Get specific environment value.

```azdeveloper
azd env get-value <keyName> [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd env get-value in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for get-value.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd env get-values

Get all environment values.

```azdeveloper
azd env get-values [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd env get-values in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for get-values.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd env list

List environments.

```azdeveloper
azd env list [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd env list in your web browser.
  -h, --help   Gets help for list.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd env new

Create a new environment and set it as the default.

```azdeveloper
azd env new <environment> [flags]
```

### Options

```azdeveloper
      --docs                  Opens the documentation for azd env new in your web browser.
  -h, --help                  Gets help for new.
  -l, --location string       Azure location for the new environment
      --subscription string   Name or ID of an Azure subscription to use for the new environment
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd env refresh

Refresh environment settings by using information from a previous infrastructure provision.

```azdeveloper
azd env refresh <environment> [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd env refresh in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for refresh.
      --hint string          Hint to help identify the environment to refresh
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd env select

Set the default environment.

```azdeveloper
azd env select <environment> [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd env select in your web browser.
  -h, --help   Gets help for select.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd env set

Manage your environment settings.

```azdeveloper
azd env set <key> <value> [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd env set in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for set.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd env set-secret

Set a <name> as a reference to a Key Vault secret in the environment.

### Synopsis

You can either create a new Key Vault secret or select an existing one.
The provided name is the key for the .env file which holds the secret reference to the Key Vault secret.

```azdeveloper
azd env set-secret <name> [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd env set-secret in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for set-secret.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd env](#azd-env): Manage environments.
* [Back to top](#azd)

## azd hooks

Develop, test and run hooks for an application. (Beta)

### Options

```azdeveloper
      --docs   Opens the documentation for azd hooks in your web browser.
  -h, --help   Gets help for hooks.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd hooks run](#azd-hooks-run): Runs the specified hook for the project and services
* [Back to top](#azd)

## azd hooks run

Runs the specified hook for the project and services

```azdeveloper
azd hooks run <name> [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd hooks run in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for run.
      --platform string      Forces hooks to run for the specified platform.
      --service string       Only runs hooks for the specified service.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd hooks](#azd-hooks): Develop, test and run hooks for an application. (Beta)
* [Back to top](#azd)

## azd infra

Manage your Azure infrastructure.

### Options

```azdeveloper
      --docs   Opens the documentation for azd infra in your web browser.
  -h, --help   Gets help for infra.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd infra synth](#azd-infra-synth): Write IaC for your project to disk, allowing you to manage it by hand. (Alpha)
* [Back to top](#azd)

## azd infra synth

Write IaC for your project to disk, allowing you to manage it by hand. (Alpha)

```azdeveloper
azd infra synth [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd infra synth in your web browser.
  -e, --environment string   The name of the environment to use.
      --force                Overwrite any existing files without prompting
  -h, --help                 Gets help for synth.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd infra](#azd-infra): Manage your Azure infrastructure.
* [Back to top](#azd)

## azd init

Initialize a new application.

```azdeveloper
azd init [flags]
```

### Options

```azdeveloper
  -b, --branch string         The template branch to initialize from. Must be used with a template argument (--template or -t).
      --docs                  Opens the documentation for azd init in your web browser.
  -e, --environment string    The name of the environment to use.
  -f, --filter strings        The tag(s) used to filter template results. Supports comma-separated values.
      --from-code             Initializes a new application from your existing code.
  -h, --help                  Gets help for init.
  -l, --location string       Azure location for the new environment
  -s, --subscription string   Name or ID of an Azure subscription to use for the new environment
  -t, --template string       Initializes a new application from a template. You can use Full URI, <owner>/<repository>, or <repository> if it's part of the azure-samples organization.
      --up                    Provision and deploy to Azure after initializing the project from a template.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd monitor

Monitor a deployed application. (Beta)

```azdeveloper
azd monitor [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd monitor in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for monitor.
      --live                 Open a browser to Application Insights Live Metrics. Live Metrics is currently not supported for Python apps.
      --logs                 Open a browser to Application Insights Logs.
      --overview             Open a browser to Application Insights Overview Dashboard.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd package

Packages the application's code to be deployed to Azure. (Beta)

```azdeveloper
azd package <service> [flags]
```

### Options

```azdeveloper
      --all                  Packages all services that are listed in azure.yaml
      --docs                 Opens the documentation for azd package in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for package.
      --output-path string   File or folder path where the generated packages will be saved.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd pipeline

Manage and configure your deployment pipelines. (Beta)

### Options

```azdeveloper
      --docs   Opens the documentation for azd pipeline in your web browser.
  -h, --help   Gets help for pipeline.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd pipeline config](#azd-pipeline-config): Configure your deployment pipeline to connect securely to Azure. (Beta)
* [Back to top](#azd)

## azd pipeline config

Configure your deployment pipeline to connect securely to Azure. (Beta)

```azdeveloper
azd pipeline config [flags]
```

### Options

```azdeveloper
  -m, --applicationServiceManagementReference string   Service Management Reference. References application or service contact information from a Service or Asset Management database. This value must be a Universally Unique Identifier (UUID). You can set this value globally by running azd config set pipeline.config.applicationServiceManagementReference <UUID>.
      --auth-type string                               The authentication type used between the pipeline provider and Azure for deployment (Only valid for GitHub provider). Valid values: federated, client-credentials.
      --docs                                           Opens the documentation for azd pipeline config in your web browser.
  -e, --environment string                             The name of the environment to use.
  -h, --help                                           Gets help for config.
      --principal-id string                            The client id of the service principal to use to grant access to Azure resources as part of the pipeline.
      --principal-name string                          The name of the service principal to use to grant access to Azure resources as part of the pipeline.
      --principal-role stringArray                     The roles to assign to the service principal. By default the service principal will be granted the Contributor and User Access Administrator roles. (default [Contributor,User Access Administrator])
      --provider string                                The pipeline provider to use (github for Github Actions and azdo for Azure Pipelines).
      --remote-name string                             The name of the git remote to configure the pipeline to run on. (default "origin")
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd pipeline](#azd-pipeline): Manage and configure your deployment pipelines. (Beta)
* [Back to top](#azd)

## azd provision

Provision the Azure resources for an application.

```azdeveloper
azd provision [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd provision in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for provision.
      --no-state             Do not use latest Deployment State (bicep only).
      --preview              Preview changes to Azure resources.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd restore

Restores the application's dependencies. (Beta)

```azdeveloper
azd restore <service> [flags]
```

### Options

```azdeveloper
      --all                  Restores all services that are listed in azure.yaml
      --docs                 Opens the documentation for azd restore in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for restore.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd show

Display information about your app and its resources.

```azdeveloper
azd show [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd show in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for show.
      --show-secrets         Unmask secrets in output.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd template

Find and view template details. (Beta)

### Options

```azdeveloper
      --docs   Opens the documentation for azd template in your web browser.
  -h, --help   Gets help for template.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd template list](#azd-template-list): Show list of sample azd templates. (Beta)
* [azd template show](#azd-template-show): Show details for a given template. (Beta)
* [azd template source](#azd-template-source): View and manage template sources. (Beta)
* [Back to top](#azd)

## azd template list

Show list of sample azd templates. (Beta)

```azdeveloper
azd template list [flags]
```

### Options

```azdeveloper
      --docs             Opens the documentation for azd template list in your web browser.
  -f, --filter strings   The tag(s) used to filter template results. Supports comma-separated values.
  -h, --help             Gets help for list.
  -s, --source string    Filters templates by source.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd template](#azd-template): Find and view template details. (Beta)
* [Back to top](#azd)

## azd template show

Show details for a given template. (Beta)

```azdeveloper
azd template show <template> [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd template show in your web browser.
  -h, --help   Gets help for show.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd template](#azd-template): Find and view template details. (Beta)
* [Back to top](#azd)

## azd template source

View and manage template sources. (Beta)

### Options

```azdeveloper
      --docs   Opens the documentation for azd template source in your web browser.
  -h, --help   Gets help for source.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd template](#azd-template): Find and view template details. (Beta)
* [azd template source add](#azd-template-source-add): Adds an azd template source with the specified key. (Beta)
* [azd template source list](#azd-template-source-list): Lists the configured azd template sources. (Beta)
* [azd template source remove](#azd-template-source-remove): Removes the specified azd template source (Beta)
* [Back to top](#azd)

## azd template source add

Adds an azd template source with the specified key. (Beta)

### Synopsis

The key can be any value that uniquely identifies the template source, with well-known values being:
   ・default: Default templates
   ・awesome-azd: Templates from [https://aka.ms/awesome-azd](https://aka.ms/awesome-azd)

```azdeveloper
azd template source add <key> [flags]
```

### Options

```azdeveloper
      --docs              Opens the documentation for azd template source add in your web browser.
  -h, --help              Gets help for add.
  -l, --location string   Location of the template source. Required when using type flag.
  -n, --name string       Display name of the template source.
  -t, --type string       Kind of the template source. Supported types are 'file', 'url' and 'gh'.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd template source](#azd-template-source): View and manage template sources. (Beta)
* [Back to top](#azd)

## azd template source list

Lists the configured azd template sources. (Beta)

```azdeveloper
azd template source list [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd template source list in your web browser.
  -h, --help   Gets help for list.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd template source](#azd-template-source): View and manage template sources. (Beta)
* [Back to top](#azd)

## azd template source remove

Removes the specified azd template source (Beta)

```azdeveloper
azd template source remove <key> [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd template source remove in your web browser.
  -h, --help   Gets help for remove.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [azd template source](#azd-template-source): View and manage template sources. (Beta)
* [Back to top](#azd)

## azd up

Provision Azure resources, and deploy your project with a single command.

```azdeveloper
azd up [flags]
```

### Options

```azdeveloper
      --docs                 Opens the documentation for azd up in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for up.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)

## azd version

Print the version number of Azure Developer CLI.

```azdeveloper
azd version [flags]
```

### Options

```azdeveloper
      --docs   Opens the documentation for azd version in your web browser.
  -h, --help   Gets help for version.
```

### Options inherited from parent commands

```azdeveloper
  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.
```

### See also

* [Back to top](#azd)



</details>

author_association: COLLABORATOR