forked from Azure/aks-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupsclient.go
52 lines (42 loc) · 1.44 KB
/
groupsclient.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package azurestack
import (
"context"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
"github.com/Azure/go-autorest/autorest"
)
// EnsureResourceGroup ensures the named resource group exists in the given location.
func (az *AzureClient) EnsureResourceGroup(ctx context.Context, name, location string, managedBy *string) (resourceGroup *resources.Group, err error) {
var tags map[string]*string
group, err := az.groupsClient.Get(ctx, name)
if err == nil {
tags = group.Tags
}
response, err := az.groupsClient.CreateOrUpdate(ctx, name, resources.Group{
Name: &name,
Location: &location,
ManagedBy: managedBy,
Tags: tags,
})
if err != nil {
return &response, err
}
return &response, nil
}
// CheckResourceGroupExistence return if the resource group exists
func (az *AzureClient) CheckResourceGroupExistence(ctx context.Context, name string) (result autorest.Response, err error) {
return az.groupsClient.CheckExistence(ctx, name)
}
// DeleteResourceGroup delete the named resource group
func (az *AzureClient) DeleteResourceGroup(ctx context.Context, name string) error {
future, err := az.groupsClient.Delete(ctx, name)
if err != nil {
return err
}
if err = future.WaitForCompletionRef(ctx, az.groupsClient.Client); err != nil {
return err
}
_, err = future.Result(az.groupsClient)
return err
}