Skip to content
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

add Preflight Validate API support #4329

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
apply options with deployment stack updates
  • Loading branch information
hemarina committed Oct 14, 2024
commit e17c1db58a88596941b8998936338b34b1098ec4
2 changes: 2 additions & 0 deletions cli/azd/pkg/azapi/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ type DeploymentService interface {
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error
ValidatePreflightToResourceGroup(
ctx context.Context,
Expand All @@ -184,6 +185,7 @@ type DeploymentService interface {
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error
WhatIfDeployToSubscription(
ctx context.Context,
Expand Down
44 changes: 20 additions & 24 deletions cli/azd/pkg/azapi/stack_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ func (d *StackDeployments) ValidatePreflightToResourceGroup(
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error {
client, err := d.createClient(ctx, subscriptionId)
if err != nil {
Expand All @@ -773,22 +774,19 @@ func (d *StackDeployments) ValidatePreflightToResourceGroup(
}
}

deleteBehavior := armdeploymentstacks.DeploymentStacksDeleteDetachEnumDelete
deploymentStackOptions, err := parseDeploymentStackOptions(options)
if err != nil {
return err
}

stack := armdeploymentstacks.DeploymentStack{
Tags: clonedTags,
Properties: &armdeploymentstacks.DeploymentStackProperties{
BypassStackOutOfSyncError: to.Ptr(false),
ActionOnUnmanage: &armdeploymentstacks.ActionOnUnmanage{
Resources: &deleteBehavior,
ManagementGroups: &deleteBehavior,
ResourceGroups: &deleteBehavior,
},
DenySettings: &armdeploymentstacks.DenySettings{
Mode: to.Ptr(armdeploymentstacks.DenySettingsModeNone),
},
Parameters: stackParams,
Template: armTemplate,
BypassStackOutOfSyncError: deploymentStackOptions.BypassStackOutOfSyncError,
ActionOnUnmanage: deploymentStackOptions.ActionOnUnmanage,
DenySettings: deploymentStackOptions.DenySettings,
Parameters: stackParams,
Template: armTemplate,
},
}
poller, err := client.BeginValidateStackAtResourceGroup(ctx, resourceGroup, deploymentName, stack, nil)
Expand All @@ -812,6 +810,7 @@ func (d *StackDeployments) ValidatePreflightToSubscription(
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error {
client, err := d.createClient(ctx, subscriptionId)
if err != nil {
Expand All @@ -833,23 +832,20 @@ func (d *StackDeployments) ValidatePreflightToSubscription(
}
}

deleteBehavior := armdeploymentstacks.DeploymentStacksDeleteDetachEnumDelete
deploymentStackOptions, err := parseDeploymentStackOptions(options)
if err != nil {
return err
}

stack := armdeploymentstacks.DeploymentStack{
Location: &location,
Tags: clonedTags,
Properties: &armdeploymentstacks.DeploymentStackProperties{
BypassStackOutOfSyncError: to.Ptr(false),
ActionOnUnmanage: &armdeploymentstacks.ActionOnUnmanage{
Resources: &deleteBehavior,
ManagementGroups: &deleteBehavior,
ResourceGroups: &deleteBehavior,
},
DenySettings: &armdeploymentstacks.DenySettings{
Mode: to.Ptr(armdeploymentstacks.DenySettingsModeNone),
},
Parameters: stackParams,
Template: armTemplate,
BypassStackOutOfSyncError: deploymentStackOptions.BypassStackOutOfSyncError,
ActionOnUnmanage: deploymentStackOptions.ActionOnUnmanage,
DenySettings: deploymentStackOptions.DenySettings,
Parameters: stackParams,
Template: armTemplate,
},
}
poller, err := client.BeginValidateStackAtSubscription(ctx, deploymentName, stack, nil)
Expand Down
2 changes: 2 additions & 0 deletions cli/azd/pkg/azapi/standard_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ func (ds *StandardDeployments) ValidatePreflightToSubscription(
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error {
deploymentClient, err := ds.createDeploymentsClient(ctx, subscriptionId)
if err != nil {
Expand Down Expand Up @@ -782,6 +783,7 @@ func (ds *StandardDeployments) ValidatePreflightToResourceGroup(
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error {
deploymentClient, err := ds.createDeploymentsClient(ctx, subscriptionId)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,18 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*provisioning.DeployResult,
deploymentTags[azure.TagKeyAzdDeploymentStateParamHashName] = to.Ptr(currentParamsHash)
}

optionsMap, err := convert.ToMap(p.options)
if err != nil {
return nil, err
}

err = p.validatePreflight(
ctx,
bicepDeploymentData.Target,
bicepDeploymentData.CompiledBicep.RawArmTemplate,
bicepDeploymentData.CompiledBicep.Parameters,
deploymentTags,
optionsMap,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -611,11 +617,6 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*provisioning.DeployResult,
// Start the deployment
p.console.ShowSpinner(ctx, "Creating/Updating resources", input.Step)

optionsMap, err := convert.ToMap(p.options)
if err != nil {
return nil, err
}

deployResult, err := p.deployModule(
ctx,
bicepDeploymentData.Target,
Expand Down Expand Up @@ -1735,8 +1736,9 @@ func (p *BicepProvider) validatePreflight(
armTemplate azure.RawArmTemplate,
armParameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error {
return target.ValidatePreflight(ctx, armTemplate, armParameters, tags)
return target.ValidatePreflight(ctx, armTemplate, armParameters, tags, options)
}

// Deploys the specified Bicep module and parameters with the selected provisioning scope (subscription vs resource group)
Expand Down
19 changes: 14 additions & 5 deletions cli/azd/pkg/infra/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Deployment interface {
template azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error
// Deploy a given template with a set of parameters.
Deploy(
Expand Down Expand Up @@ -73,10 +74,14 @@ func (s *ResourceGroupDeployment) Name() string {
}

func (s *ResourceGroupDeployment) ValidatePreflight(
ctx context.Context, template azure.RawArmTemplate, parameters azure.ArmParameters, tags map[string]*string,
ctx context.Context,
template azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error {
return s.deploymentService.ValidatePreflightToResourceGroup(
ctx, s.subscriptionId, s.resourceGroupName, s.name, template, parameters, tags)
ctx, s.subscriptionId, s.resourceGroupName, s.name, template, parameters, tags, options)
}

func (s *ResourceGroupDeployment) Deploy(
Expand Down Expand Up @@ -271,10 +276,14 @@ func (s *SubscriptionDeployment) DeploymentUrl(ctx context.Context) (string, err
}

func (s *SubscriptionDeployment) ValidatePreflight(
ctx context.Context, template azure.RawArmTemplate, parameters azure.ArmParameters, tags map[string]*string,
ctx context.Context,
template azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
options map[string]any,
) error {
return s.deploymentService.ValidatePreflightToSubscription(ctx, s.subscriptionId, s.location,
s.name, template, parameters, tags)
return s.deploymentService.ValidatePreflightToSubscription(ctx, s.subscriptionId, s.location,
s.name, template, parameters, tags, options)
}

// Deploy a given template with a set of parameters.
Expand Down