Skip to content

Commit

Permalink
down: idempotent delete (#4627)
Browse files Browse the repository at this point in the history
This addresses the incorrect behavior of: when deleting a resource group in `azd down`, azd currently fails.

A delete on a resource group that does not exist should result in a no-opt.

Fixes #4628
  • Loading branch information
weikanglim authored Dec 30, 2024
1 parent ef05268 commit 9b60cbc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli/azd/pkg/azapi/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package azapi

import (
"context"
"errors"
"fmt"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/azure/azure-dev/cli/azd/pkg/account"
Expand Down Expand Up @@ -194,6 +196,11 @@ func (rs *ResourceService) DeleteResourceGroup(ctx context.Context, subscription
}

poller, err := client.BeginDelete(ctx, resourceGroupName, nil)
var respErr *azcore.ResponseError
if errors.As(err, &respErr) && respErr.StatusCode == 404 { // Resource group is already deleted
return nil
}

if err != nil {
return fmt.Errorf("beginning resource group deletion: %w", err)
}
Expand Down

0 comments on commit 9b60cbc

Please sign in to comment.