-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c8fc36
commit 78e4e1d
Showing
4 changed files
with
147 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" | ||
) | ||
|
||
func run() error { | ||
cred, err := azidentity.NewDefaultAzureCredential(nil) | ||
if err != nil { | ||
return fmt.Errorf("creating Azure credential: %w", err) | ||
} | ||
client, err := armresources.NewResourceGroupsClient("faa080af-c1d8-40ad-9cce-e1a450ca5b57", cred, nil) | ||
if err != nil { | ||
return fmt.Errorf("creating ResourceGroup client: %w", err) | ||
} | ||
|
||
ctx := context.Background() | ||
poller, err := client.BeginDelete(ctx, "doesnotexist", 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) | ||
} | ||
|
||
_, err = poller.PollUntilDone(ctx, nil) | ||
if err != nil { | ||
return fmt.Errorf("deleting resource group: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
err := run() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters