Skip to content

Commit 7b745c6

Browse files
committed
Make azsp tests more stable
1 parent 180b3b3 commit 7b745c6

File tree

8 files changed

+56
-49
lines changed

8 files changed

+56
-49
lines changed

common/azure_auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (aa *AzureAuth) getAzureEnvironment() (azure.Environment, error) {
8989

9090
func (aa *AzureAuth) resourceID() string {
9191
if aa.ResourceID != "" {
92-
if aa.SubscriptionID == "" {
92+
if aa.SubscriptionID == "" || aa.ResourceGroup == "" {
9393
res, err := azure.ParseResourceID(aa.ResourceID)
9494
if err != nil {
9595
log.Printf("[ERROR] %s", err)

common/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
"com.databricks.backend.manager.util.UnknownWorkerEnvironmentException",
2626
"does not have any associated worker environments",
2727
"There is no worker environment with id",
28+
"Unknown worker environment",
2829
"ClusterNotReadyException",
2930
"connection reset by peer",
3031
"connection refused",

identity/acceptance/resource_group_member_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
func TestAccComplexValueResource(t *testing.T) {
14+
func TestAccGroupMemberResource(t *testing.T) {
1515
acceptance.Test(t, []acceptance.Step{
1616
{
1717
Template: `

mws/resource_workspace_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,22 @@ func TestResourceWorkspaceCreateGcp(t *testing.T) {
121121
Method: "POST",
122122
Resource: "/api/2.0/accounts/abc/workspaces",
123123
// retreating to raw JSON, as certain fields don't work well together
124-
ExpectedRequest: map[string]interface {}{
125-
"account_id":"abc",
126-
"cloud":"gcp",
127-
"cloud_resource_bucket":map[string]interface {}{
128-
"gcp":map[string]interface {}{
129-
"project_id":"def",
124+
ExpectedRequest: map[string]interface{}{
125+
"account_id": "abc",
126+
"cloud": "gcp",
127+
"cloud_resource_bucket": map[string]interface{}{
128+
"gcp": map[string]interface{}{
129+
"project_id": "def",
130130
},
131131
},
132-
"location":"bcd",
133-
"workspace_name":"labdata",
132+
"location": "bcd",
133+
"workspace_name": "labdata",
134134
},
135135
Response: Workspace{
136136
WorkspaceID: 1234,
137137
AccountID: "abc",
138138
DeploymentName: "900150983cd24fb0",
139-
WorkspaceName: "labdata",
139+
WorkspaceName: "labdata",
140140
},
141141
},
142142
{
@@ -148,7 +148,7 @@ func TestResourceWorkspaceCreateGcp(t *testing.T) {
148148
WorkspaceID: 1234,
149149
WorkspaceStatus: WorkspaceStatusRunning,
150150
DeploymentName: "900150983cd24fb0",
151-
WorkspaceName: "labdata",
151+
WorkspaceName: "labdata",
152152
},
153153
},
154154
},

scripts/modules/az-common/main.tf

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,47 @@ locals {
3838
}
3939
}
4040

41-
resource "azurerm_resource_group" "example" {
41+
resource "azurerm_resource_group" "this" {
4242
name = "${local.prefix}-rg"
4343
location = var.region
4444
tags = local.tags
4545
}
4646

4747
output "azure_region" {
48-
value = azurerm_resource_group.example.location
48+
value = azurerm_resource_group.this.location
4949
}
5050

5151
output "test_resource_group" {
52-
value = azurerm_resource_group.example.name
52+
value = azurerm_resource_group.this.name
5353
}
5454

55-
resource "azurerm_databricks_workspace" "example" {
55+
output "test_resource_group_id" {
56+
value = azurerm_resource_group.this.id
57+
}
58+
59+
resource "azurerm_databricks_workspace" "this" {
5660
name = "${local.prefix}-workspace"
57-
resource_group_name = azurerm_resource_group.example.name
58-
location = azurerm_resource_group.example.location
61+
resource_group_name = azurerm_resource_group.this.name
62+
location = azurerm_resource_group.this.location
5963
sku = "premium"
6064
managed_resource_group_name = "${local.prefix}-workspace-rg"
6165
tags = local.tags
6266
}
6367

6468
output "databricks_azure_workspace_resource_id" {
6569
// The ID of the Databricks Workspace in the Azure management plane.
66-
value = azurerm_databricks_workspace.example.id
70+
value = azurerm_databricks_workspace.this.id
6771
}
6872

6973
output "databricks_host" {
70-
value = "https://${azurerm_databricks_workspace.example.workspace_url}/"
74+
value = "https://${azurerm_databricks_workspace.this.workspace_url}/"
7175
}
7276

7377
// ADLSv1 resource
7478
resource "azurerm_data_lake_store" "gen1" {
7579
name = "${local.prefix}adlsv1"
76-
resource_group_name = azurerm_resource_group.example.name
77-
location = azurerm_resource_group.example.location
80+
resource_group_name = azurerm_resource_group.this.name
81+
location = azurerm_resource_group.this.location
7882
}
7983

8084
output "test_data_lake_store_name" {
@@ -84,8 +88,8 @@ output "test_data_lake_store_name" {
8488
# Create container in storage acc and container for use by blob mount tests
8589
resource "azurerm_storage_account" "v2" {
8690
name = "${local.prefix}adlsv2"
87-
resource_group_name = azurerm_resource_group.example.name
88-
location = azurerm_resource_group.example.location
91+
resource_group_name = azurerm_resource_group.this.name
92+
location = azurerm_resource_group.this.location
8993
account_tier = "Standard"
9094
account_replication_type = "LRS"
9195
account_kind = "StorageV2"
@@ -111,7 +115,7 @@ output "test_storage_v2_wasbs" {
111115
value = azurerm_storage_container.wasbs.name
112116
}
113117

114-
data "azurerm_storage_account_blob_container_sas" "example" {
118+
data "azurerm_storage_account_blob_container_sas" "this" {
115119
connection_string = azurerm_storage_account.v2.primary_connection_string
116120
container_name = azurerm_storage_container.wasbs.name
117121
https_only = true
@@ -128,64 +132,63 @@ data "azurerm_storage_account_blob_container_sas" "example" {
128132
}
129133

130134
output "test_storage_v2_wasbs_sas" {
131-
value = data.azurerm_storage_account_blob_container_sas.example.sas
135+
value = data.azurerm_storage_account_blob_container_sas.this.sas
132136
sensitive = true
133137
}
134138

135-
resource "azurerm_storage_blob" "example" {
139+
resource "azurerm_storage_blob" "this" {
136140
name = "main.tf"
137141
storage_account_name = azurerm_storage_account.v2.name
138142
storage_container_name = azurerm_storage_container.wasbs.name
139143
type = "Block"
140144
source = "${path.module}/main.tf"
141145
}
142146

143-
resource "azurerm_key_vault" "example" {
147+
resource "azurerm_key_vault" "this" {
144148
name = "${local.prefix}-kv"
145-
location = azurerm_resource_group.example.location
146-
resource_group_name = azurerm_resource_group.example.name
149+
location = azurerm_resource_group.this.location
150+
resource_group_name = azurerm_resource_group.this.name
147151
tenant_id = data.azurerm_client_config.current.tenant_id
148152
purge_protection_enabled = false
149153
sku_name = "standard"
150154
tags = local.tags
155+
}
151156

152-
access_policy {
153-
tenant_id = data.azurerm_client_config.current.tenant_id
154-
object_id = data.azurerm_client_config.current.object_id
155-
secret_permissions = [
156-
"delete", "get", "list", "set"
157-
]
158-
}
157+
resource "azurerm_key_vault_access_policy" "this" {
158+
key_vault_id = azurerm_key_vault.this.id
159+
tenant_id = data.azurerm_client_config.current.tenant_id
160+
object_id = data.azurerm_client_config.current.object_id
161+
secret_permissions = ["Delete", "Get", "List", "Set"]
159162
}
160163

161164
output "test_key_vault_name" {
162-
value = azurerm_key_vault.example.name
165+
value = azurerm_key_vault.this.name
163166
}
164167

165168
output "test_key_vault_resource_id" {
166-
value = azurerm_key_vault.example.id
169+
value = azurerm_key_vault.this.id
167170
}
168171

169172
output "test_key_vault_dns_name" {
170-
value = azurerm_key_vault.example.vault_uri
173+
value = azurerm_key_vault.this.vault_uri
171174
}
172175

173176
// "Key Vault Administrator" role required for SP
174-
resource "azurerm_key_vault_secret" "example" {
177+
resource "azurerm_key_vault_secret" "this" {
175178
name = "answer"
176179
value = "42"
177-
key_vault_id = azurerm_key_vault.example.id
180+
key_vault_id = azurerm_key_vault.this.id
178181
tags = local.tags
179182
}
180183

181184
output "test_key_vault_secret" {
182-
value = azurerm_key_vault_secret.example.name
185+
value = azurerm_key_vault_secret.this.name
183186
}
184187

185188
output "test_key_vault_secret_value" {
186189
// this is for testing purposes only.
187190
// must not be a practice for production.
188-
value = azurerm_key_vault_secret.example.value
191+
value = azurerm_key_vault_secret.this.value
189192
sensitive = true
190193
}
191194

storage/adls_gen1_mount.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ func (m AzureADLSGen1Mount) Source() string {
2626

2727
// Config ...
2828
func (m AzureADLSGen1Mount) Config(client *common.DatabricksClient) map[string]string {
29+
aadEndpoint := client.AzureAuth.AzureEnvironment.ActiveDirectoryEndpoint
2930
return map[string]string{
3031
m.PrefixType + ".oauth2.access.token.provider.type": "ClientCredential",
31-
m.PrefixType + ".oauth2.client.id": m.ClientID,
32-
m.PrefixType + ".oauth2.credential": fmt.Sprintf("{secrets/%s/%s}", m.SecretScope, m.SecretKey),
33-
m.PrefixType + ".oauth2.refresh.url": fmt.Sprintf("%s/%s/oauth2/token", client.AzureAuth.AzureEnvironment.ActiveDirectoryEndpoint, m.TenantID),
32+
33+
m.PrefixType + ".oauth2.client.id": m.ClientID,
34+
m.PrefixType + ".oauth2.credential": fmt.Sprintf("{secrets/%s/%s}", m.SecretScope, m.SecretKey),
35+
m.PrefixType + ".oauth2.refresh.url": fmt.Sprintf("%s/%s/oauth2/token", aadEndpoint, m.TenantID),
3436
}
3537
}
3638

storage/adls_gen2_mount.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ func (m AzureADLSGen2Mount) Source() string {
2727

2828
// Config returns mount configurations
2929
func (m AzureADLSGen2Mount) Config(client *common.DatabricksClient) map[string]string {
30+
aadEndpoint := client.AzureAuth.AzureEnvironment.ActiveDirectoryEndpoint
3031
return map[string]string{
3132
"fs.azure.account.auth.type": "OAuth",
3233
"fs.azure.account.oauth.provider.type": "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider",
3334
"fs.azure.account.oauth2.client.id": m.ClientID,
3435
"fs.azure.account.oauth2.client.secret": fmt.Sprintf("{secrets/%s/%s}", m.SecretScope, m.SecretKey),
35-
"fs.azure.account.oauth2.client.endpoint": fmt.Sprintf("%s/%s/oauth2/token", client.AzureAuth.AzureEnvironment.ActiveDirectoryEndpoint, m.TenantID),
36+
"fs.azure.account.oauth2.client.endpoint": fmt.Sprintf("%s/%s/oauth2/token", aadEndpoint, m.TenantID),
3637
"fs.azure.createRemoteFileSystemDuringInitialization": fmt.Sprintf("%t", m.InitializeFileSystem),
3738
}
3839
}

workspace/acceptance/global_init_script_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestAccGlobalInitScriptResource_Create(t *testing.T) {
1212
Template: `
1313
resource "databricks_global_init_script" "this" {
1414
name = "init-{var.RANDOM}"
15-
enabled = false
15+
enabled = true
1616
content_base64 = "ZWNobyBoZWxsbw=="
1717
}`,
1818
},

0 commit comments

Comments
 (0)