Skip to content

Commit

Permalink
fix empty map for options
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong committed Jan 31, 2024
1 parent 014ebed commit 384d318
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
4 changes: 4 additions & 0 deletions catalog/resource_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func ResourceConnection() *schema.Resource {
// We need to preserve original sensitive options as API doesn't return them
var cOrig catalog.CreateConnection
common.DataToStructPointer(d, s, &cOrig)
// If there are no options returned, need to initialize the map
if conn.Options == nil {
conn.Options = map[string]string{}
}
for key, element := range cOrig.Options {
if slices.Contains(sensitiveOptions, key) {
conn.Options[key] = element
Expand Down
35 changes: 23 additions & 12 deletions internal/acceptance/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,31 @@ func connectionTemplateWithOwner(host string, owner string) string {
`, host, owner)
}

func connectionTemplateWithoutOwner(host string) string {
return fmt.Sprintf(`
func connectionTemplateWithoutOwner() string {
return `
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"
connection_type = "BIGQUERY"
comment = "test"
options = {
GoogleServiceAccountKeyJson = <<-EOT
{
"type": "service_account",
"project_id": "PROJECT_ID",
"private_key_id": "KEY_ID",
"private_key": "-----BEGIN PRIVATE KEY-----\nPRIVATE_KEY\n-----END PRIVATE KEY-----\n",
"client_email": "SERVICE_ACCOUNT_EMAIL",
"client_id": "CLIENT_ID",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL",
"universe_domain": "googleapis.com"
}
EOT
}
}
`, host)
`
}
func TestUcAccConnectionsResourceFullLifecycle(t *testing.T) {
unityWorkspaceLevel(t, step{
Expand All @@ -49,8 +60,8 @@ func TestUcAccConnectionsResourceFullLifecycle(t *testing.T) {

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

0 comments on commit 384d318

Please sign in to comment.