forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmachine_learning_synapse_spark_resource_test.go
318 lines (279 loc) · 10.3 KB
/
machine_learning_synapse_spark_resource_test.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package machinelearning_test
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/machinelearning/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
type SynapseSparkResource struct{}
func TestAccSynapseSpark_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_machine_learning_synapse_spark", "test")
r := SynapseSparkResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}
func TestAccSynapseSpark_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_machine_learning_synapse_spark", "test")
r := SynapseSparkResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}
func TestAccSynapseSpark_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_machine_learning_synapse_spark", "test")
r := SynapseSparkResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.RequiresImportErrorStep(r.requiresImport),
})
}
func TestAccSynapseSpark_identity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_machine_learning_synapse_spark", "test")
r := SynapseSparkResource{}
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.identitySystemAssignedUserAssigned(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("identity.0.principal_id").MatchesRegex(validate.UUIDRegExp),
check.That(data.ResourceName).Key("identity.0.tenant_id").Exists(),
),
},
data.ImportStep(),
{
Config: r.identityUserAssigned(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.identitySystemAssigned(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("identity.0.principal_id").MatchesRegex(validate.UUIDRegExp),
check.That(data.ResourceName).Key("identity.0.tenant_id").Exists(),
),
},
data.ImportStep(),
})
}
func (r SynapseSparkResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
computeClient := client.MachineLearning.MachineLearningComputeClient
id, err := parse.ComputeID(state.ID)
if err != nil {
return nil, err
}
computeResource, err := computeClient.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.Name)
if err != nil {
if utils.ResponseWasNotFound(computeResource.Response) {
return utils.Bool(false), nil
}
return nil, fmt.Errorf("retrieving Machine Learning Compute Cluster %q: %+v", state.ID, err)
}
return utils.Bool(computeResource.Properties != nil), nil
}
func (r SynapseSparkResource) basic(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_machine_learning_synapse_spark" "test" {
name = "acctest%d"
machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id
location = azurerm_resource_group.test.location
synapse_spark_pool_id = azurerm_synapse_spark_pool.test.id
local_auth_enabled = false
}
`, template, data.RandomIntOfLength(8))
}
func (r SynapseSparkResource) complete(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_machine_learning_synapse_spark" "test" {
name = "acctest%d"
machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id
location = azurerm_resource_group.test.location
synapse_spark_pool_id = azurerm_synapse_spark_pool.test.id
description = "this is desc changed"
identity {
type = "SystemAssigned"
}
tags = {
Ke1y = "Val1ue"
}
}
`, template, data.RandomIntOfLength(8))
}
func (r SynapseSparkResource) requiresImport(data acceptance.TestData) string {
template := r.basic(data)
return fmt.Sprintf(`
%s
resource "azurerm_machine_learning_synapse_spark" "import" {
name = azurerm_machine_learning_synapse_spark.test.name
location = azurerm_machine_learning_synapse_spark.test.location
machine_learning_workspace_id = azurerm_machine_learning_synapse_spark.test.machine_learning_workspace_id
synapse_spark_pool_id = azurerm_machine_learning_synapse_spark.test.synapse_spark_pool_id
}
`, template)
}
func (r SynapseSparkResource) identitySystemAssigned(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_machine_learning_synapse_spark" "test" {
name = "acctest%d"
machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id
location = azurerm_resource_group.test.location
synapse_spark_pool_id = azurerm_synapse_spark_pool.test.id
identity {
type = "SystemAssigned"
}
}
`, template, data.RandomIntOfLength(8))
}
func (r SynapseSparkResource) identityUserAssigned(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_user_assigned_identity" "test" {
name = "acctestUAI-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_machine_learning_synapse_spark" "test" {
name = "acctest%d"
machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id
location = azurerm_resource_group.test.location
synapse_spark_pool_id = azurerm_synapse_spark_pool.test.id
identity {
type = "UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id,
]
}
}
`, template, data.RandomInteger, data.RandomIntOfLength(8))
}
func (r SynapseSparkResource) identitySystemAssignedUserAssigned(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_user_assigned_identity" "test" {
name = "acctestUAI-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_machine_learning_synapse_spark" "test" {
name = "acctest%d"
machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id
location = azurerm_resource_group.test.location
synapse_spark_pool_id = azurerm_synapse_spark_pool.test.id
identity {
type = "SystemAssigned,UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id,
]
}
}
`, template, data.RandomInteger, data.RandomIntOfLength(8))
}
func (r SynapseSparkResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "test" {
name = "acctestRG-ml-%[1]d"
location = "%[2]s"
tags = {
"stage" = "test"
}
}
resource "azurerm_application_insights" "test" {
name = "acctestai-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
application_type = "web"
}
resource "azurerm_key_vault" "test" {
name = "acctestvault%[3]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
purge_protection_enabled = true
}
resource "azurerm_storage_account" "test" {
name = "acctestsa%[4]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_machine_learning_workspace" "test" {
name = "acctest-MLW%[5]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
application_insights_id = azurerm_application_insights.test.id
key_vault_id = azurerm_key_vault.test.id
storage_account_id = azurerm_storage_account.test.id
identity {
type = "SystemAssigned"
}
}
resource "azurerm_storage_data_lake_gen2_filesystem" "test" {
name = "acc%d"
storage_account_id = azurerm_storage_account.test.id
}
resource "azurerm_synapse_workspace" "test" {
name = "acctestsw%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
storage_data_lake_gen2_filesystem_id = azurerm_storage_data_lake_gen2_filesystem.test.id
sql_administrator_login = "sqladminuser"
sql_administrator_login_password = "H@Sh1CoR3!"
}
resource "azurerm_synapse_spark_pool" "test" {
name = "acc%d"
synapse_workspace_id = azurerm_synapse_workspace.test.id
node_size_family = "MemoryOptimized"
node_size = "Small"
node_count = 3
}
`, data.RandomInteger, data.Locations.Primary,
data.RandomIntOfLength(12), data.RandomIntOfLength(15), data.RandomIntOfLength(16),
data.RandomIntOfLength(8), data.RandomIntOfLength(8), data.RandomIntOfLength(8), data.RandomIntOfLength(8))
}