Skip to content

Commit a3e2e6f

Browse files
authored
direct: Handle data_security_mode aliases for clusters (#3839)
## Changes Handle data_security_mode aliases for clusters ## Why To be in line with TF provider behaviour, we skip diff if it's just a change of the alias https://github.com/databricks/terraform-provider-databricks/blob/main/clusters/resource_cluster.go#L109-L117 ## Tests Added an acceptance test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 6f453bd commit a3e2e6f

File tree

7 files changed

+34
-39
lines changed

7 files changed

+34
-39
lines changed

acceptance/bundle/resources/clusters/deploy/data_security_mode/out.direct.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

acceptance/bundle/resources/clusters/deploy/data_security_mode/out.plan.direct.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

acceptance/bundle/resources/clusters/deploy/data_security_mode/out.plan.terraform.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

acceptance/bundle/resources/clusters/deploy/data_security_mode/out.terraform.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

acceptance/bundle/resources/clusters/deploy/data_security_mode/output.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11

2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> [CLI] bundle plan
9+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
10+
11+
>>> [CLI] bundle deploy
12+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
13+
Deploying resources...
14+
Updating deployment state...
15+
Deployment complete!
16+
217
>>> [CLI] bundle destroy --auto-approve
318
The following resources will be deleted:
419
delete cluster test_cluster

acceptance/bundle/resources/clusters/deploy/data_security_mode/script

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ cleanup() {
55
}
66
trap cleanup EXIT
77

8-
trace $CLI bundle deploy > out.$DATABRICKS_BUNDLE_ENGINE.txt 2>&1
9-
10-
trace $CLI bundle plan >> out.plan.$DATABRICKS_BUNDLE_ENGINE.txt 2>&1
11-
12-
trace errcode $CLI bundle deploy >> out.$DATABRICKS_BUNDLE_ENGINE.txt 2>&1
8+
trace $CLI bundle deploy
9+
trace $CLI bundle plan
10+
trace $CLI bundle deploy

bundle/direct/dresources/cluster.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,27 @@ func (r *ResourceCluster) DoDelete(ctx context.Context, id string) error {
120120
return r.client.Clusters.PermanentDeleteByClusterId(ctx, id)
121121
}
122122

123-
func (r *ResourceCluster) ClassifyChange(change structdiff.Change, remoteState *compute.ClusterDetails, _ bool) (deployplan.ActionType, error) {
123+
func (r *ResourceCluster) ClassifyChange(change structdiff.Change, remoteState *compute.ClusterDetails, isLocal bool) (deployplan.ActionType, error) {
124+
changedPath := change.Path.String()
125+
if changedPath == "data_security_mode" && !isLocal {
126+
// We do change skip here in the same way TF provider does suppress diff if the alias is used.
127+
// https://github.com/databricks/terraform-provider-databricks/blob/main/clusters/resource_cluster.go#L109-L117
128+
if change.Old == compute.DataSecurityModeDataSecurityModeStandard && change.New == compute.DataSecurityModeUserIsolation {
129+
return deployplan.ActionTypeSkip, nil
130+
}
131+
if change.Old == compute.DataSecurityModeDataSecurityModeDedicated && change.New == compute.DataSecurityModeSingleUser {
132+
return deployplan.ActionTypeSkip, nil
133+
}
134+
if change.Old == compute.DataSecurityModeDataSecurityModeAuto && (change.New == compute.DataSecurityModeSingleUser || change.New == compute.DataSecurityModeUserIsolation) {
135+
return deployplan.ActionTypeSkip, nil
136+
}
137+
}
138+
124139
// Always update if the cluster is not running.
125140
if remoteState.State != compute.StateRunning {
126141
return deployplan.ActionTypeUpdate, nil
127142
}
128143

129-
changedPath := change.Path.String()
130144
if changedPath == "num_workers" || strings.HasPrefix(changedPath, "autoscale") {
131145
return deployplan.ActionTypeResize, nil
132146
}

0 commit comments

Comments
 (0)