-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.go
54 lines (44 loc) · 1.45 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package resourcegroups
import (
"fmt"
"net/http"
"net/url"
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/api"
)
// DeleteResourceGroup deletes an Azure resource group.
// From: https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups/delete
func (c *Client) DeleteResourceGroup(resourceGroup string) error {
urlParams := url.Values{
"api-version": []string{apiVersion},
}
// Create the url.
uri := api.ResolveRelative(BaseURI, resourceGroupURLPath)
uri += "?" + url.Values(urlParams).Encode()
// Create the request.
req, err := http.NewRequest("DELETE", uri, nil)
if err != nil {
return fmt.Errorf("Creating delete resource group uri request failed: %v", err)
}
// Add the parameters to the url.
if err := api.ExpandURL(req.URL, map[string]string{
"subscriptionId": c.auth.SubscriptionID,
"resourceGroupName": resourceGroup,
}); err != nil {
return fmt.Errorf("Expanding URL with parameters failed: %v", err)
}
// Send the request.
resp, err := c.hc.Do(req)
if err != nil {
return fmt.Errorf("Sending delete resource group request failed: %v", err)
}
defer resp.Body.Close()
// 200 (OK) and 202 (Accepted) are successful responses.
if err := api.CheckResponse(resp); err != nil {
return err
}
// 204 No Content means the specified resource group was not found.
if resp.StatusCode == http.StatusNoContent {
return fmt.Errorf("Resource group with name %q was not found", resourceGroup)
}
return nil
}