Skip to content

Commit 501e14d

Browse files
authored
[Fix] Suppress options.pem_private_key_expiration_epoch_sec attribute for databricks_connection (#4474)
Suppress `options.pem_private_key_expiration_epoch_sec` attribute from API to prevent drift when creating a Snowflake connection using `pem_private_key`. Resolves #4471 ## Changes Add `suppressPemPrivateKeyExpiration` function. When `options.pem_private_key_expiration_epoch_sec` exists, we suppress for `options.pem_private_key_expiration_epoch_sec`. ## Tests Tested in my local environment. First run: ``` > terraform apply Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # databricks_connection.this will be created + resource "databricks_connection" "this" { + connection_type = "SNOWFLAKE" + id = (known after apply) + metastore_id = (known after apply) + name = "<REDACTED>" + options = (sensitive value) + owner = (known after apply) + read_only = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes databricks_connection.this: Creating... databricks_connection.this: Creation complete after 1s [id=<REDACTED>|<REDACTED>] Apply complete! Resources: 1 added, 0 changed, 0 destroyed. ``` Subsequent run: ``` > terraform apply databricks_connection.this: Refreshing state... [id=<REDACTED>|<REDACTED>] No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. Apply complete! Resources: 0 added, 0 changed, 0 destroyed. ``` Changing another variable within `options` inside Terraform code: ``` > terraform apply databricks_connection.this: Refreshing state... [id=<REDACTED>|<REDACTED>] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place Terraform will perform the following actions: # databricks_connection.this will be updated in-place ~ resource "databricks_connection" "this" { id = "<REDACTED>|<REDACTED>" name = "<REDACTED>" ~ options = (sensitive value) # (4 unchanged attributes hidden) } Plan: 0 to add, 1 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes databricks_connection.this: Modifying... [id=<REDACTED>|<REDACTED>] databricks_connection.this: Modifications complete after 1s [id=<REDACTED>|<REDACTED>] Apply complete! Resources: 0 added, 1 changed, 0 destroyed. ``` - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework
1 parent bd38f68 commit 501e14d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
### Bug Fixes
1111
* Fixed an issue where reordering objects in a (pluginfw) Share wouldn’t update properly unless other changes were made ([#4481](https://github.com/databricks/terraform-provider-databricks/pull/4481)).
1212

13+
* Suppress `options.pem_private_key_expiration_epoch_sec` attribute for databricks_connection ([#4474](https://github.com/databricks/terraform-provider-databricks/pull/4474)).
14+
1315
### Documentation
1416

1517
* Add an example for Databricks Apps permissions ([#4475](https://github.com/databricks/terraform-provider-databricks/pull/4475)).

catalog/resource_connection.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package catalog
22

33
import (
44
"context"
5+
"log"
56

67
"github.com/databricks/databricks-sdk-go/service/catalog"
78
"github.com/databricks/terraform-provider-databricks/common"
@@ -34,12 +35,21 @@ type ConnectionInfo struct {
3435
ReadOnly bool `json:"read_only,omitempty" tf:"force_new,computed"`
3536
}
3637

37-
var sensitiveOptions = []string{"user", "password", "personalAccessToken", "access_token", "client_secret", "OAuthPvtKey", "GoogleServiceAccountKeyJson"}
38+
var sensitiveOptions = []string{"user", "password", "personalAccessToken", "access_token", "client_secret", "pem_private_key", "OAuthPvtKey", "GoogleServiceAccountKeyJson"}
39+
40+
func suppressPemPrivateKeyExpiration(k, old, new string, d *schema.ResourceData) bool {
41+
if k == "options.pem_private_key_expiration_epoch_sec" {
42+
log.Printf("[INFO] Suppressing diff on %s", k)
43+
return true
44+
}
45+
return false
46+
}
3847

3948
func ResourceConnection() common.Resource {
4049
s := common.StructToSchema(ConnectionInfo{},
4150
func(m map[string]*schema.Schema) map[string]*schema.Schema {
4251
m["name"].DiffSuppressFunc = common.EqualFoldDiffSuppress
52+
m["options"].DiffSuppressFunc = suppressPemPrivateKeyExpiration
4353
return m
4454
})
4555
pi := common.NewPairID("metastore_id", "name").Schema(
@@ -132,6 +142,7 @@ func ResourceConnection() common.Resource {
132142
}
133143

134144
updateConnectionRequest.Owner = ""
145+
delete(updateConnectionRequest.Options, "pem_private_key_expiration_epoch_sec")
135146
_, err = w.Connections.Update(ctx, updateConnectionRequest)
136147
if err != nil {
137148
if d.HasChange("owner") {

0 commit comments

Comments
 (0)