Skip to content

Commit

Permalink
fix connection creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong committed Jan 30, 2024
1 parent 8fca518 commit 014ebed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
19 changes: 9 additions & 10 deletions catalog/resource_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,19 @@ func ResourceConnection() *schema.Resource {
}
var createConnectionRequest catalog.CreateConnection
common.DataToStructPointer(d, s, &createConnectionRequest)
_, err = w.Connections.Create(ctx, createConnectionRequest)
conn, err := w.Connections.Create(ctx, createConnectionRequest)
if err != nil {
return err
}
// Update owner if it is provided
if d.Get("owner") == "" {
return nil
}
var updateConnectionRequest catalog.UpdateConnection
common.DataToStructPointer(d, s, &updateConnectionRequest)
updateConnectionRequest.NameArg = updateConnectionRequest.Name
conn, err := w.Connections.Update(ctx, updateConnectionRequest)
if err != nil {
return err
if d.Get("owner") != "" {
var updateConnectionRequest catalog.UpdateConnection
common.DataToStructPointer(d, s, &updateConnectionRequest)
updateConnectionRequest.NameArg = updateConnectionRequest.Name
conn, err = w.Connections.Update(ctx, updateConnectionRequest)
if err != nil {
return err
}
}
d.Set("metastore_id", conn.MetastoreId)
pi.Pack(d)
Expand Down
24 changes: 24 additions & 0 deletions internal/acceptance/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ func connectionTemplateWithOwner(host string, owner string) string {
}
`, host, owner)
}

func connectionTemplateWithoutOwner(host string) string {
return fmt.Sprintf(`
resource "databricks_connection" "this" {
name = "name-{var.STICKY_RANDOM}"
connection_type = "MYSQL"
comment = "this is a connection to mysql db"
options = {
host = "%s"
port = "3306"
user = "user"
password = "password"
}
}
`, host)
}
func TestUcAccConnectionsResourceFullLifecycle(t *testing.T) {
unityWorkspaceLevel(t, step{
Template: connectionTemplateWithOwner("test.mysql.database.azure.com", "account users"),
Expand All @@ -30,3 +46,11 @@ func TestUcAccConnectionsResourceFullLifecycle(t *testing.T) {
Template: connectionTemplateWithOwner("test.mysql.database.azure.com", "{env.TEST_METASTORE_ADMIN_GROUP_NAME}"),
})
}

func TestUcAccConnectionsWithoutOwnerResourceFullLifecycle(t *testing.T) {
unityWorkspaceLevel(t, step{
Template: connectionTemplateWithoutOwner("test.mysql.database.azure.com"),
}, step{
Template: connectionTemplateWithoutOwner("test.mysql.database.aws.com"),
})
}

0 comments on commit 014ebed

Please sign in to comment.