@@ -5,18 +5,18 @@ import (
5
5
"log"
6
6
"time"
7
7
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 "
9
9
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
10
10
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
11
11
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
12
12
"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"
13
14
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate"
14
15
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
15
16
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
16
17
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
17
18
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
18
19
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
19
- "github.com/hashicorp/terraform-provider-azurerm/utils"
20
20
)
21
21
22
22
func resourceDataLakeAnalyticsAccount () * pluginsdk.Resource {
@@ -53,18 +53,18 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource {
53
53
"tier" : {
54
54
Type : pluginsdk .TypeString ,
55
55
Optional : true ,
56
- Default : string (account . Consumption ),
56
+ Default : string (accounts . TierTypeConsumption ),
57
57
DiffSuppressFunc : suppress .CaseDifference ,
58
58
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 ),
68
68
}, true ),
69
69
},
70
70
@@ -82,51 +82,46 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource {
82
82
83
83
func resourceArmDateLakeAnalyticsAccountCreate (d * pluginsdk.ResourceData , meta interface {}) error {
84
84
client := meta .(* clients.Client ).Datalake .AnalyticsAccountsClient
85
- subscriptionId := meta .(* clients.Client ).Datalake .AnalyticsAccountsClient . SubscriptionID
85
+ subscriptionId := meta .(* clients.Client ).Datalake .SubscriptionId
86
86
ctx , cancel := timeouts .ForCreate (meta .(* clients.Client ).StopContext , d )
87
87
defer cancel ()
88
88
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 ))
90
90
91
- existing , err := client .Get (ctx , id . ResourceGroup , id . AccountName )
91
+ existing , err := client .Get (ctx , id )
92
92
if err != nil {
93
- if ! utils . ResponseWasNotFound (existing .Response ) {
93
+ if ! response . WasNotFound (existing .HttpResponse ) {
94
94
return fmt .Errorf ("checking for presence of existing Data Lake Analytics Account %s: %+v" , id , err )
95
95
}
96
96
}
97
97
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 () )
100
100
}
101
101
102
102
location := azure .NormalizeLocation (d .Get ("location" ).(string ))
103
103
storeAccountName := d .Get ("default_store_account_name" ).(string )
104
- tier := d .Get ("tier" ).(string )
104
+ tier := accounts . TierType ( d .Get ("tier" ).(string ) )
105
105
t := d .Get ("tags" ).(map [string ]interface {})
106
106
107
107
log .Printf ("[INFO] preparing arguments for Azure ARM Date Lake Store creation %s" , id )
108
108
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 {
116
116
{
117
- Name : & storeAccountName ,
117
+ Name : storeAccountName ,
118
118
},
119
119
},
120
120
},
121
121
}
122
122
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 )
130
125
}
131
126
132
127
d .SetId (id .ID ())
@@ -139,34 +134,29 @@ func resourceArmDateLakeAnalyticsAccountUpdate(d *pluginsdk.ResourceData, meta i
139
134
ctx , cancel := timeouts .ForUpdate (meta .(* clients.Client ).StopContext , d )
140
135
defer cancel ()
141
136
142
- id , err := parse . AnalyticsAccountID (d .Id ())
137
+ id , err := accounts . ParseAccountID (d .Id ())
143
138
if err != nil {
144
139
return err
145
140
}
146
141
147
142
storeAccountName := d .Get ("default_store_account_name" ).(string )
148
- newTier := d .Get ("tier" ).(string )
143
+ newTier := accounts . TierType ( d .Get ("tier" ).(string ) )
149
144
newTags := d .Get ("tags" ).(map [string ]interface {})
150
145
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 {
156
151
{
157
- Name : & storeAccountName ,
152
+ Name : storeAccountName ,
158
153
},
159
154
},
160
155
},
161
156
}
162
157
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 )
170
160
}
171
161
172
162
return resourceArmDateLakeAnalyticsAccountRead (d , meta )
@@ -177,52 +167,51 @@ func resourceArmDateLakeAnalyticsAccountRead(d *pluginsdk.ResourceData, meta int
177
167
ctx , cancel := timeouts .ForRead (meta .(* clients.Client ).StopContext , d )
178
168
defer cancel ()
179
169
180
- id , err := parse . AnalyticsAccountID (d .Id ())
170
+ id , err := accounts . ParseAccountID (d .Id ())
181
171
if err != nil {
182
172
return err
183
173
}
184
174
185
- resp , err := client .Get (ctx , id . ResourceGroup , id . AccountName )
175
+ resp , err := client .Get (ctx , * id )
186
176
if err != nil {
187
- if utils . ResponseWasNotFound (resp .Response ) {
177
+ if response . WasNotFound (resp .HttpResponse ) {
188
178
log .Printf ("[WARN] DataLakeAnalyticsAccountAccount '%s'" , id )
189
179
d .SetId ("" )
190
180
return nil
191
181
}
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 )
193
183
}
194
184
195
- d .Set ("name" , id .AccountName )
185
+ d .Set ("name" , id .Name )
196
186
d .Set ("resource_group_name" , id .ResourceGroup )
197
- if location := resp .Location ; location != nil {
198
- d .Set ("location" , azure .NormalizeLocation (* location ))
199
- }
200
187
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
+ }
205
197
206
- return tags .FlattenAndSet (d , resp .Tags )
198
+ return tags .FlattenAndSet (d , flattenTags (model .Tags ))
199
+ }
200
+ return nil
207
201
}
208
202
209
203
func resourceArmDateLakeAnalyticsAccountDelete (d * pluginsdk.ResourceData , meta interface {}) error {
210
204
client := meta .(* clients.Client ).Datalake .AnalyticsAccountsClient
211
205
ctx , cancel := timeouts .ForDelete (meta .(* clients.Client ).StopContext , d )
212
206
defer cancel ()
213
207
214
- id , err := parse . AnalyticsAccountID (d .Id ())
208
+ id , err := accounts . ParseAccountID (d .Id ())
215
209
if err != nil {
216
210
return err
217
211
}
218
212
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 )
226
215
}
227
216
228
217
return nil
0 commit comments