Skip to content
Merged
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
15 changes: 15 additions & 0 deletions cli/azd/pkg/azapi/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ func (rs *ResourceService) GetResource(
}, nil
}

func (rs *ResourceService) CheckExistenceByID(
ctx context.Context, resourceId arm.ResourceID, apiVersion string) (bool, error) {
client, err := rs.createResourcesClient(ctx, resourceId.SubscriptionID)
if err != nil {
return false, err
}

response, err := client.CheckExistenceByID(ctx, resourceId.String(), apiVersion, nil)
if err != nil {
return false, fmt.Errorf("checking resource existence by id: %w", err)
}

return response.Success, nil
}

func (rs *ResourceService) GetRawResource(
ctx context.Context, resourceId arm.ResourceID, apiVersion string) (string, error) {
client, err := rs.createResourcesClient(ctx, resourceId.SubscriptionID)
Expand Down
27 changes: 24 additions & 3 deletions cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,29 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*provisioning.DeployResult,
}

if !p.ignoreDeploymentState && parametersHashErr == nil {
deploymentState, err := p.deploymentState(ctx, planned, deployment, currentParamsHash)
if err == nil {
deploymentState, stateErr := p.deploymentState(ctx, planned, deployment, currentParamsHash)
if stateErr == nil {
// As a heuristic, we also check the existence of all resource groups
// created by the deployment to validate the deployment state.
// This handles the scenario of resource group(s) being deleted outside of azd,
// which is quite common.
// This check adds ~100ms per resource group to the deployment time.
for _, res := range deploymentState.Resources {
if res != nil && res.ID != nil {
resId, err := arm.ParseResourceID(*res.ID)
if err == nil && resId.ResourceType.Type == arm.ResourceGroupResourceType.Type {
exists, err := p.resourceService.CheckExistenceByID(ctx, *resId, "2025-03-01")
if err == nil && !exists {
stateErr = fmt.Errorf(
"resource group %s no longer exists, invalidating deployment state", resId.ResourceGroupName)
break
}
}
}
}
}

if stateErr == nil {
result.Outputs = provisioning.OutputParametersFromArmOutputs(
planned.Template.Outputs,
azapi.CreateDeploymentOutput(deploymentState.Outputs),
Expand All @@ -600,7 +621,7 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*provisioning.DeployResult,
SkippedReason: provisioning.DeploymentStateSkipped,
}, nil
}
logDS("%s", err.Error())
logDS("%s", stateErr.Error())
}

deploymentTags := map[string]*string{
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/test/recording/recording.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func Start(t *testing.T, opts ...Options) *Session {
return
}

t.Fatal("recorderProxy: " + msg)
t.Log("recorderProxy: " + msg)
},
Recorder: vcr,
},
Expand Down
Loading