Skip to content

Commit bf89540

Browse files
Merge pull request hashicorp#14158 from hashicorp/pandora-datalake-swap
datalake - switching to use an embedded sdk
2 parents d042f29 + f4f13a2 commit bf89540

39 files changed

+343
-12052
lines changed
+18-12
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
11
package client
22

33
import (
4-
analytics "github.com/Azure/azure-sdk-for-go/services/datalake/analytics/mgmt/2016-11-01/account"
54
"github.com/Azure/azure-sdk-for-go/services/datalake/store/2016-11-01/filesystem"
6-
store "github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account"
75
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
6+
analyticsaccount "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/accounts"
7+
analyticsfirewallrules "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/firewallrules"
8+
storeaccount "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/accounts"
9+
storefirewallrules "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/firewallrules"
10+
storevirtualnetworkrules "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/virtualnetworkrules"
811
)
912

1013
type Client struct {
1114
// Data Lake Store
12-
StoreAccountsClient *store.AccountsClient
13-
StoreFirewallRulesClient *store.FirewallRulesClient
14-
VirtualNetworkRulesClient *store.VirtualNetworkRulesClient
15+
StoreAccountsClient *storeaccount.AccountsClient
16+
StoreFirewallRulesClient *storefirewallrules.FirewallRulesClient
17+
VirtualNetworkRulesClient *storevirtualnetworkrules.VirtualNetworkRulesClient
1518
StoreFilesClient *filesystem.Client
1619

1720
// Data Lake Analytics
18-
AnalyticsAccountsClient *analytics.AccountsClient
19-
AnalyticsFirewallRulesClient *analytics.FirewallRulesClient
21+
AnalyticsAccountsClient *analyticsaccount.AccountsClient
22+
AnalyticsFirewallRulesClient *analyticsfirewallrules.FirewallRulesClient
23+
24+
SubscriptionId string
2025
}
2126

2227
func NewClient(o *common.ClientOptions) *Client {
23-
StoreAccountsClient := store.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
28+
StoreAccountsClient := storeaccount.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint)
2429
o.ConfigureClient(&StoreAccountsClient.Client, o.ResourceManagerAuthorizer)
2530

26-
StoreFirewallRulesClient := store.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
31+
StoreFirewallRulesClient := storefirewallrules.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint)
2732
o.ConfigureClient(&StoreFirewallRulesClient.Client, o.ResourceManagerAuthorizer)
2833

29-
VirtualNetworkRulesClient := store.NewVirtualNetworkRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
34+
VirtualNetworkRulesClient := storevirtualnetworkrules.NewVirtualNetworkRulesClientWithBaseURI(o.ResourceManagerEndpoint)
3035
o.ConfigureClient(&VirtualNetworkRulesClient.Client, o.ResourceManagerAuthorizer)
3136

3237
StoreFilesClient := filesystem.NewClient()
3338
o.ConfigureClient(&StoreFilesClient.Client, o.ResourceManagerAuthorizer)
3439

35-
AnalyticsAccountsClient := analytics.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
40+
AnalyticsAccountsClient := analyticsaccount.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint)
3641
o.ConfigureClient(&AnalyticsAccountsClient.Client, o.ResourceManagerAuthorizer)
3742

38-
AnalyticsFirewallRulesClient := analytics.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
43+
AnalyticsFirewallRulesClient := analyticsfirewallrules.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint)
3944
o.ConfigureClient(&AnalyticsFirewallRulesClient.Client, o.ResourceManagerAuthorizer)
4045

4146
return &Client{
@@ -45,5 +50,6 @@ func NewClient(o *common.ClientOptions) *Client {
4550
StoreFilesClient: &StoreFilesClient,
4651
AnalyticsAccountsClient: &AnalyticsAccountsClient,
4752
AnalyticsFirewallRulesClient: &AnalyticsFirewallRulesClient,
53+
SubscriptionId: o.SubscriptionId,
4854
}
4955
}

internal/services/datalake/data_lake_analytics_account_resource.go

+59-70
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import (
55
"log"
66
"time"
77

8-
"github.com/Azure/azure-sdk-for-go/services/datalake/analytics/mgmt/2016-11-01/account"
8+
"github.com/hashicorp/go-azure-helpers/lang/response"
99
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
1010
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
1111
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
1212
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse"
13+
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/accounts"
1314
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate"
1415
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
1516
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
1617
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
1718
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
1819
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
19-
"github.com/hashicorp/terraform-provider-azurerm/utils"
2020
)
2121

2222
func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource {
@@ -53,18 +53,18 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource {
5353
"tier": {
5454
Type: pluginsdk.TypeString,
5555
Optional: true,
56-
Default: string(account.Consumption),
56+
Default: string(accounts.TierTypeConsumption),
5757
DiffSuppressFunc: suppress.CaseDifference,
5858
ValidateFunc: validation.StringInSlice([]string{
59-
string(account.Consumption),
60-
string(account.Commitment100000AUHours),
61-
string(account.Commitment10000AUHours),
62-
string(account.Commitment1000AUHours),
63-
string(account.Commitment100AUHours),
64-
string(account.Commitment500000AUHours),
65-
string(account.Commitment50000AUHours),
66-
string(account.Commitment5000AUHours),
67-
string(account.Commitment500AUHours),
59+
string(accounts.TierTypeConsumption),
60+
string(accounts.TierTypeCommitmentOneZeroZeroZeroZeroZeroAUHours),
61+
string(accounts.TierTypeCommitmentOneZeroZeroZeroZeroAUHours),
62+
string(accounts.TierTypeCommitmentOneZeroZeroZeroAUHours),
63+
string(accounts.TierTypeCommitmentOneZeroZeroAUHours),
64+
string(accounts.TierTypeCommitmentFiveZeroZeroZeroZeroZeroAUHours),
65+
string(accounts.TierTypeCommitmentFiveZeroZeroZeroZeroAUHours),
66+
string(accounts.TierTypeCommitmentFiveZeroZeroZeroAUHours),
67+
string(accounts.TierTypeCommitmentFiveZeroZeroAUHours),
6868
}, true),
6969
},
7070

@@ -82,51 +82,46 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource {
8282

8383
func resourceArmDateLakeAnalyticsAccountCreate(d *pluginsdk.ResourceData, meta interface{}) error {
8484
client := meta.(*clients.Client).Datalake.AnalyticsAccountsClient
85-
subscriptionId := meta.(*clients.Client).Datalake.AnalyticsAccountsClient.SubscriptionID
85+
subscriptionId := meta.(*clients.Client).Datalake.SubscriptionId
8686
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
8787
defer cancel()
8888

89-
id := parse.NewAnalyticsAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
89+
id := accounts.NewAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
9090

91-
existing, err := client.Get(ctx, id.ResourceGroup, id.AccountName)
91+
existing, err := client.Get(ctx, id)
9292
if err != nil {
93-
if !utils.ResponseWasNotFound(existing.Response) {
93+
if !response.WasNotFound(existing.HttpResponse) {
9494
return fmt.Errorf("checking for presence of existing Data Lake Analytics Account %s: %+v", id, err)
9595
}
9696
}
9797

98-
if existing.ID != nil && *existing.ID != "" {
99-
return tf.ImportAsExistsError("azurerm_data_lake_analytics_account", *existing.ID)
98+
if !response.WasNotFound(existing.HttpResponse) {
99+
return tf.ImportAsExistsError("azurerm_data_lake_analytics_account", id.ID())
100100
}
101101

102102
location := azure.NormalizeLocation(d.Get("location").(string))
103103
storeAccountName := d.Get("default_store_account_name").(string)
104-
tier := d.Get("tier").(string)
104+
tier := accounts.TierType(d.Get("tier").(string))
105105
t := d.Get("tags").(map[string]interface{})
106106

107107
log.Printf("[INFO] preparing arguments for Azure ARM Date Lake Store creation %s", id)
108108

109-
dateLakeAnalyticsAccount := account.CreateDataLakeAnalyticsAccountParameters{
110-
Location: &location,
111-
Tags: tags.Expand(t),
112-
CreateDataLakeAnalyticsAccountProperties: &account.CreateDataLakeAnalyticsAccountProperties{
113-
NewTier: account.TierType(tier),
114-
DefaultDataLakeStoreAccount: &storeAccountName,
115-
DataLakeStoreAccounts: &[]account.AddDataLakeStoreWithAccountParameters{
109+
dateLakeAnalyticsAccount := accounts.CreateDataLakeAnalyticsAccountParameters{
110+
Location: location,
111+
Tags: expandTags(t),
112+
Properties: accounts.CreateDataLakeAnalyticsAccountProperties{
113+
NewTier: &tier,
114+
DefaultDataLakeStoreAccount: storeAccountName,
115+
DataLakeStoreAccounts: []accounts.AddDataLakeStoreWithAccountParameters{
116116
{
117-
Name: &storeAccountName,
117+
Name: storeAccountName,
118118
},
119119
},
120120
},
121121
}
122122

123-
future, err := client.Create(ctx, id.ResourceGroup, id.AccountName, dateLakeAnalyticsAccount)
124-
if err != nil {
125-
return fmt.Errorf("issuing create request for Data Lake Analytics Account %s: %+v", id, err)
126-
}
127-
128-
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
129-
return fmt.Errorf("creating Data Lake Analytics Account %s: %+v", id, err)
123+
if err := client.CreateThenPoll(ctx, id, dateLakeAnalyticsAccount); err != nil {
124+
return fmt.Errorf("creating %s: %+v", id, err)
130125
}
131126

132127
d.SetId(id.ID())
@@ -139,34 +134,29 @@ func resourceArmDateLakeAnalyticsAccountUpdate(d *pluginsdk.ResourceData, meta i
139134
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
140135
defer cancel()
141136

142-
id, err := parse.AnalyticsAccountID(d.Id())
137+
id, err := accounts.ParseAccountID(d.Id())
143138
if err != nil {
144139
return err
145140
}
146141

147142
storeAccountName := d.Get("default_store_account_name").(string)
148-
newTier := d.Get("tier").(string)
143+
newTier := accounts.TierType(d.Get("tier").(string))
149144
newTags := d.Get("tags").(map[string]interface{})
150145

151-
props := &account.UpdateDataLakeAnalyticsAccountParameters{
152-
Tags: tags.Expand(newTags),
153-
UpdateDataLakeAnalyticsAccountProperties: &account.UpdateDataLakeAnalyticsAccountProperties{
154-
NewTier: account.TierType(newTier),
155-
DataLakeStoreAccounts: &[]account.UpdateDataLakeStoreWithAccountParameters{
146+
props := accounts.UpdateDataLakeAnalyticsAccountParameters{
147+
Tags: expandTags(newTags),
148+
Properties: &accounts.UpdateDataLakeAnalyticsAccountProperties{
149+
NewTier: &newTier,
150+
DataLakeStoreAccounts: &[]accounts.UpdateDataLakeStoreWithAccountParameters{
156151
{
157-
Name: &storeAccountName,
152+
Name: storeAccountName,
158153
},
159154
},
160155
},
161156
}
162157

163-
future, err := client.Update(ctx, id.ResourceGroup, id.AccountName, props)
164-
if err != nil {
165-
return fmt.Errorf("issuing update request for Data Lake Analytics Account %s: %+v", id, err)
166-
}
167-
168-
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
169-
return fmt.Errorf("waiting for the update of Data Lake Analytics Account %s to complete: %+v", id, err)
158+
if err := client.UpdateThenPoll(ctx, *id, props); err != nil {
159+
return fmt.Errorf("updating %s: %+v", id, err)
170160
}
171161

172162
return resourceArmDateLakeAnalyticsAccountRead(d, meta)
@@ -177,52 +167,51 @@ func resourceArmDateLakeAnalyticsAccountRead(d *pluginsdk.ResourceData, meta int
177167
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
178168
defer cancel()
179169

180-
id, err := parse.AnalyticsAccountID(d.Id())
170+
id, err := accounts.ParseAccountID(d.Id())
181171
if err != nil {
182172
return err
183173
}
184174

185-
resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName)
175+
resp, err := client.Get(ctx, *id)
186176
if err != nil {
187-
if utils.ResponseWasNotFound(resp.Response) {
177+
if response.WasNotFound(resp.HttpResponse) {
188178
log.Printf("[WARN] DataLakeAnalyticsAccountAccount '%s'", id)
189179
d.SetId("")
190180
return nil
191181
}
192-
return fmt.Errorf("making Read request on Azure Data Lake Analytics Account %s: %+v", id, err)
182+
return fmt.Errorf("reading %s: %+v", id, err)
193183
}
194184

195-
d.Set("name", id.AccountName)
185+
d.Set("name", id.Name)
196186
d.Set("resource_group_name", id.ResourceGroup)
197-
if location := resp.Location; location != nil {
198-
d.Set("location", azure.NormalizeLocation(*location))
199-
}
200187

201-
if properties := resp.DataLakeAnalyticsAccountProperties; properties != nil {
202-
d.Set("tier", string(properties.CurrentTier))
203-
d.Set("default_store_account_name", properties.DefaultDataLakeStoreAccount)
204-
}
188+
if model := resp.Model; model != nil {
189+
if location := model.Location; location != nil {
190+
d.Set("location", azure.NormalizeLocation(*location))
191+
}
192+
193+
if properties := model.Properties; properties != nil {
194+
d.Set("tier", properties.CurrentTier)
195+
d.Set("default_store_account_name", properties.DefaultDataLakeStoreAccount)
196+
}
205197

206-
return tags.FlattenAndSet(d, resp.Tags)
198+
return tags.FlattenAndSet(d, flattenTags(model.Tags))
199+
}
200+
return nil
207201
}
208202

209203
func resourceArmDateLakeAnalyticsAccountDelete(d *pluginsdk.ResourceData, meta interface{}) error {
210204
client := meta.(*clients.Client).Datalake.AnalyticsAccountsClient
211205
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
212206
defer cancel()
213207

214-
id, err := parse.AnalyticsAccountID(d.Id())
208+
id, err := accounts.ParseAccountID(d.Id())
215209
if err != nil {
216210
return err
217211
}
218212

219-
future, err := client.Delete(ctx, id.ResourceGroup, id.AccountName)
220-
if err != nil {
221-
return fmt.Errorf("deleting Data Lake Analytics Account %s: %+v", id, err)
222-
}
223-
224-
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
225-
return fmt.Errorf("waiting for the deletion of Data Lake Analytics Account %s: %+v", id, err)
213+
if err := client.DeleteThenPoll(ctx, *id); err != nil {
214+
return fmt.Errorf("deleting %s: %+v", id, err)
226215
}
227216

228217
return nil

internal/services/datalake/data_lake_analytics_account_resource_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"strconv"
77
"testing"
88

9+
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/accounts"
10+
911
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
1012
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
1113
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
12-
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse"
1314
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
1415
"github.com/hashicorp/terraform-provider-azurerm/utils"
1516
)
@@ -88,17 +89,17 @@ func TestAccDataLakeAnalyticsAccount_withTags(t *testing.T) {
8889
}
8990

9091
func (t DataLakeAnalyticsAccountResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
91-
id, err := parse.AnalyticsAccountID(state.ID)
92+
id, err := accounts.ParseAccountID(state.ID)
9293
if err != nil {
9394
return nil, err
9495
}
9596

96-
resp, err := clients.Datalake.AnalyticsAccountsClient.Get(ctx, id.ResourceGroup, id.AccountName)
97+
resp, err := clients.Datalake.AnalyticsAccountsClient.Get(ctx, *id)
9798
if err != nil {
98-
return nil, fmt.Errorf("retrieving Date Lake Analytics Account %s: %+v", id, err)
99+
return nil, fmt.Errorf("retrieving %s: %+v", id, err)
99100
}
100101

101-
return utils.Bool(resp.DataLakeAnalyticsAccountProperties != nil), nil
102+
return utils.Bool(resp.Model != nil), nil
102103
}
103104

104105
func (DataLakeAnalyticsAccountResource) basic(data acceptance.TestData) string {

0 commit comments

Comments
 (0)