diff --git a/cli/azd/pkg/environment/environment.go b/cli/azd/pkg/environment/environment.go index b3b4218d1c7..793a69c6ce6 100644 --- a/cli/azd/pkg/environment/environment.go +++ b/cli/azd/pkg/environment/environment.go @@ -46,6 +46,9 @@ const ResourceGroupEnvVarName = "AZURE_RESOURCE_GROUP" // PlatformTypeEnvVarName is the name of the key used to store the current azd platform type const PlatformTypeEnvVarName = "AZD_PLATFORM_TYPE" +// DisablePreflightName is used to allow users to skip the preflight validation check +const DisablePreflightName = "AZURE_PROVISION_SKIP_VALIDATE" + // The zero value of an Environment is not valid. Use [New] to create one. When writing tests, // [Ephemeral] and [EphemeralWithValues] are useful to create environments which are not persisted to disk. type Environment struct { diff --git a/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go b/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go index 99dafee3bbc..f875385a73c 100644 --- a/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go +++ b/cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go @@ -23,6 +23,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices" + "github.com/azure/azure-dev/cli/azd/internal" "github.com/azure/azure-dev/cli/azd/pkg/account" "github.com/azure/azure-dev/cli/azd/pkg/async" "github.com/azure/azure-dev/cli/azd/pkg/azapi" @@ -611,16 +612,27 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*provisioning.DeployResult, return nil, err } - err = p.validatePreflight( - ctx, - bicepDeploymentData.Target, - bicepDeploymentData.CompiledBicep.RawArmTemplate, - bicepDeploymentData.CompiledBicep.Parameters, - deploymentTags, - optionsMap, - ) - if err != nil { - return nil, err + if strings.ToLower(p.env.Getenv(environment.DisablePreflightName)) != "true" { + err = p.validatePreflight( + ctx, + bicepDeploymentData.Target, + bicepDeploymentData.CompiledBicep.RawArmTemplate, + bicepDeploymentData.CompiledBicep.Parameters, + deploymentTags, + optionsMap, + ) + if err != nil { + return nil, &internal.ErrorWithSuggestion{ + Err: err, + Suggestion: fmt.Sprintf("To skip provision validation, please run %s.", + output.WithHighLightFormat("`azd env set %s true`", environment.DisablePreflightName)), + } + } + } else { + warningMessage := fmt.Sprintf("WARNING: Provision validation is skipped. "+ + "To enable it, please run `azd env set %s false` or remove %s from your .env file.\n", + environment.DisablePreflightName, environment.DisablePreflightName) + p.console.Message(ctx, output.WithWarningFormat(warningMessage)) } cancelProgress := make(chan bool)