forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
101 lines (82 loc) · 4.17 KB
/
client.go
File metadata and controls
101 lines (82 loc) · 4.17 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright IBM Corp. 2014, 2025
// SPDX-License-Identifier: MPL-2.0
package client
import (
"fmt"
storage "github.com/hashicorp/go-azure-sdk/resource-manager/storage/2025-06-01"
"github.com/hashicorp/go-azure-sdk/resource-manager/storagesync/2020-03-01/cloudendpointresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/storagesync/2020-03-01/registeredserverresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/storagesync/2020-03-01/serverendpointresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/storagesync/2020-03-01/storagesyncservicesresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/storagesync/2020-03-01/syncgroupresource"
"github.com/hashicorp/go-azure-sdk/sdk/auth"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
// StorageDomainSuffix is used by validation functions
var StorageDomainSuffix *string
type Client struct {
StorageDomainSuffix string
ResourceManager *storage.Client
// TODO: import the Storage Sync Meta Client and use that
SyncCloudEndpointsClient *cloudendpointresource.CloudEndpointResourceClient
SyncGroupsClient *syncgroupresource.SyncGroupResourceClient
SyncRegisteredServerClient *registeredserverresource.RegisteredServerResourceClient
SyncServerEndpointsClient *serverendpointresource.ServerEndpointResourceClient
SyncServiceClient *storagesyncservicesresource.StorageSyncServicesResourceClient
authConfigForAzureAD *auth.Credentials
}
func NewClient(o *common.ClientOptions) (*Client, error) {
storageSuffix, ok := o.Environment.Storage.DomainSuffix()
if !ok {
return nil, fmt.Errorf("determining domain suffix for storage in environment: %s", o.Environment.Name)
}
// Set global variable for post-configure validation
StorageDomainSuffix = storageSuffix
resourceManager, err := storage.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
o.Configure(c, o.Authorizers.ResourceManager)
})
if err != nil {
return nil, fmt.Errorf("building ResourceManager clients: %+v", err)
}
syncCloudEndpointsClient, err := cloudendpointresource.NewCloudEndpointResourceClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building CloudEndpoint client: %+v", err)
}
o.Configure(syncCloudEndpointsClient.Client, o.Authorizers.ResourceManager)
syncRegisteredServersClient, err := registeredserverresource.NewRegisteredServerResourceClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building StorageRegisteredServer client: %+v", err)
}
o.Configure(syncRegisteredServersClient.Client, o.Authorizers.ResourceManager)
syncServerEndpointClient, err := serverendpointresource.NewServerEndpointResourceClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building StorageSyncServerEndpoint client: %+v", err)
}
o.Configure(syncServerEndpointClient.Client, o.Authorizers.ResourceManager)
syncServiceClient, err := storagesyncservicesresource.NewStorageSyncServicesResourceClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building StorageSyncService client: %+v", err)
}
o.Configure(syncServiceClient.Client, o.Authorizers.ResourceManager)
syncGroupsClient, err := syncgroupresource.NewSyncGroupResourceClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building StorageSyncGroups client: %+v", err)
}
o.Configure(syncGroupsClient.Client, o.Authorizers.ResourceManager)
// TODO: switch Storage Containers to using the storage.BlobContainersClient
// (which should fix #2977) when the storage clients have been moved in here
client := Client{
ResourceManager: resourceManager,
SyncCloudEndpointsClient: syncCloudEndpointsClient,
SyncRegisteredServerClient: syncRegisteredServersClient,
SyncServerEndpointsClient: syncServerEndpointClient,
SyncServiceClient: syncServiceClient,
SyncGroupsClient: syncGroupsClient,
StorageDomainSuffix: *storageSuffix,
}
if o.StorageUseAzureAD {
client.authConfigForAzureAD = o.AuthConfig
}
return &client, nil
}