forked from hashicorp/terraform-provider-azurerm
/
batch_account_data_source_test.go
203 lines (171 loc) · 6.48 KB
/
batch_account_data_source_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
package batch_test
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
)
func TestAccBatchAccountDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccBatchAccountDataSource_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)),
resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)),
resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"),
),
},
},
})
}
func TestAccBatchAccountDataSource_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccBatchAccountDataSource_complete(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)),
resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)),
resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"),
),
},
},
})
}
func TestAccBatchAccountDataSource_userSubscription(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test")
tenantID := os.Getenv("ARM_TENANT_ID")
subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccBatchAccountDataSource_userSubscription(data, tenantID, subscriptionID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)),
resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)),
resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "UserSubscription"),
resource.TestCheckResourceAttr(data.ResourceName, "key_vault_reference.#", "1"),
),
},
},
})
}
func testAccBatchAccountDataSource_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "testaccRG-%d-batch"
location = "%s"
}
resource "azurerm_batch_account" "test" {
name = "testaccbatch%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
pool_allocation_mode = "BatchService"
}
data "azurerm_batch_account" "test" {
name = azurerm_batch_account.test.name
resource_group_name = azurerm_resource_group.test.name
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}
func testAccBatchAccountDataSource_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "testaccRG-%d-batch"
location = "%s"
}
resource "azurerm_storage_account" "test" {
name = "testaccsa%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_batch_account" "test" {
name = "testaccbatch%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
pool_allocation_mode = "BatchService"
storage_account_id = azurerm_storage_account.test.id
tags = {
env = "test"
}
}
data "azurerm_batch_account" "test" {
name = azurerm_batch_account.test.name
resource_group_name = azurerm_resource_group.test.name
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString)
}
func testAccBatchAccountDataSource_userSubscription(data acceptance.TestData, tenantID string, subscriptionID string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
data "azuread_service_principal" "test" {
display_name = "Microsoft Azure Batch"
}
resource "azurerm_resource_group" "test" {
name = "testaccRG-%d-batchaccount"
location = "%s"
}
resource "azurerm_key_vault" "test" {
name = "batchkv%s"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
enabled_for_disk_encryption = true
enabled_for_deployment = true
enabled_for_template_deployment = true
tenant_id = "%s"
sku_name = "standard"
access_policy {
tenant_id = "%s"
object_id = "${data.azuread_service_principal.test.object_id}"
secret_permissions = [
"get",
"list",
"set",
"delete"
]
}
}
resource "azurerm_role_assignment" "contribrole" {
scope = "/subscriptions/%s"
role_definition_name = "Contributor"
principal_id = "${data.azuread_service_principal.test.object_id}"
}
resource "azurerm_batch_account" "test" {
name = "testaccbatch%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
pool_allocation_mode = "UserSubscription"
key_vault_reference {
id = "${azurerm_key_vault.test.id}"
url = "${azurerm_key_vault.test.vault_uri}"
}
}
data "azurerm_batch_account" "test" {
name = "${azurerm_batch_account.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID, tenantID, subscriptionID, data.RandomString)
}