Skip to content

Commit fe54a55

Browse files
authored
Fix databricks_connection regression when creating without owner (#3186)
* fix connection creation * fix empty map for options
1 parent 1940e1a commit fe54a55

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

catalog/resource_connection.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,19 @@ func ResourceConnection() common.Resource {
5656
}
5757
var createConnectionRequest catalog.CreateConnection
5858
common.DataToStructPointer(d, s, &createConnectionRequest)
59-
_, err = w.Connections.Create(ctx, createConnectionRequest)
59+
conn, err := w.Connections.Create(ctx, createConnectionRequest)
6060
if err != nil {
6161
return err
6262
}
6363
// Update owner if it is provided
64-
if d.Get("owner") == "" {
65-
return nil
66-
}
67-
var updateConnectionRequest catalog.UpdateConnection
68-
common.DataToStructPointer(d, s, &updateConnectionRequest)
69-
updateConnectionRequest.NameArg = updateConnectionRequest.Name
70-
conn, err := w.Connections.Update(ctx, updateConnectionRequest)
71-
if err != nil {
72-
return err
64+
if d.Get("owner") != "" {
65+
var updateConnectionRequest catalog.UpdateConnection
66+
common.DataToStructPointer(d, s, &updateConnectionRequest)
67+
updateConnectionRequest.NameArg = updateConnectionRequest.Name
68+
conn, err = w.Connections.Update(ctx, updateConnectionRequest)
69+
if err != nil {
70+
return err
71+
}
7372
}
7473
d.Set("metastore_id", conn.MetastoreId)
7574
pi.Pack(d)
@@ -91,6 +90,10 @@ func ResourceConnection() common.Resource {
9190
// We need to preserve original sensitive options as API doesn't return them
9291
var cOrig catalog.CreateConnection
9392
common.DataToStructPointer(d, s, &cOrig)
93+
// If there are no options returned, need to initialize the map
94+
if conn.Options == nil {
95+
conn.Options = map[string]string{}
96+
}
9497
for key, element := range cOrig.Options {
9598
if slices.Contains(sensitiveOptions, key) {
9699
conn.Options[key] = element

internal/acceptance/connection_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ func connectionTemplateWithOwner(host string, owner string) string {
2121
}
2222
`, host, owner)
2323
}
24+
25+
func connectionTemplateWithoutOwner() string {
26+
return `
27+
resource "databricks_connection" "this" {
28+
name = "name-{var.STICKY_RANDOM}"
29+
connection_type = "BIGQUERY"
30+
comment = "test"
31+
options = {
32+
GoogleServiceAccountKeyJson = <<-EOT
33+
{
34+
"type": "service_account",
35+
"project_id": "PROJECT_ID",
36+
"private_key_id": "KEY_ID",
37+
"private_key": "-----BEGIN PRIVATE KEY-----\nPRIVATE_KEY\n-----END PRIVATE KEY-----\n",
38+
"client_email": "SERVICE_ACCOUNT_EMAIL",
39+
"client_id": "CLIENT_ID",
40+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
41+
"token_uri": "https://accounts.google.com/o/oauth2/token",
42+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
43+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL",
44+
"universe_domain": "googleapis.com"
45+
}
46+
EOT
47+
}
48+
}
49+
`
50+
}
2451
func TestUcAccConnectionsResourceFullLifecycle(t *testing.T) {
2552
unityWorkspaceLevel(t, step{
2653
Template: connectionTemplateWithOwner("test.mysql.database.azure.com", "account users"),
@@ -30,3 +57,11 @@ func TestUcAccConnectionsResourceFullLifecycle(t *testing.T) {
3057
Template: connectionTemplateWithOwner("test.mysql.database.azure.com", "{env.TEST_METASTORE_ADMIN_GROUP_NAME}"),
3158
})
3259
}
60+
61+
func TestUcAccConnectionsWithoutOwnerResourceFullLifecycle(t *testing.T) {
62+
unityWorkspaceLevel(t, step{
63+
Template: connectionTemplateWithoutOwner(),
64+
}, step{
65+
Template: connectionTemplateWithoutOwner(),
66+
})
67+
}

0 commit comments

Comments
 (0)