Skip to content

allow user to disable provision preflight #4947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli/azd/pkg/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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 {
Expand Down
32 changes: 22 additions & 10 deletions cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.Getenv() falls back to check the system environment (not only the values from azd's .env file)

Do we want to make it only for azd's .env file?

In the warningMessage below we are telling folks they can run azd env set XXXXX false or remove the value from the .env; If the env var is set on system environment, should we re-word the error?

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)
Expand Down