Skip to content

Commit 9797880

Browse files
authored
[Fix] Do not send run_as when updating databricks_pipeline when not specified (#4470)
## Changes A recent change to add support for `run_as` in pipelines causes pipeline update requests to include the `run_as` field. The Get Pipeline always returns the `run_as_user_name` for a pipeline, even for workspaces not in the private preview. Some users may have `run_as` in their TF state now, even if they did not specify it in their configuration. As we are using SDKv2 for this resource, it isn't straightforward to see whether the user actually included `run_as` in their configuration or if it is only in the state because of the change to the `Read` method. This PR addresses this by only sending `run_as` if there is a planned change in the `run_as` field. If the user doesn't set `run_as` explicitly (as in existing customers not in the private preview), or if it is set to the same value as the `run_as_user_name` field, the provider does not need to set `run_as`, so it can be removed from the request. Resolves #4469. ## Tests - [x] Created & updated a pipeline in a workspace without run_as preview enabled; succeeded. - [x] Created & updated a pipeline in a workspace with run_as preview enabled; succeeded.
1 parent 8889b7f commit 9797880

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

NEXT_CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# NEXT CHANGELOG
22

3-
## Release v1.66.0
3+
## Release v1.65.1
44

55
### New Features and Improvements
66

77
### Bug Fixes
88

9+
* Do not send `run_as` when updating `databricks_pipeline` resource if no change is planned.
10+
911
### Documentation
1012

1113
### Exporter

pipelines/pipeline_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func TestAccPipelineResource_CreatePipeline(t *testing.T) {
9696
}
9797

9898
func pipelineRunAsTemplate(runAs string) string {
99+
if runAs != "" {
100+
runAs = `run_as { ` + runAs + ` }`
101+
}
99102
return `
100103
data "databricks_current_user" "me" {}
101104
@@ -135,9 +138,7 @@ func pipelineRunAsTemplate(runAs string) string {
135138
136139
continuous = false
137140
138-
run_as {
139-
` + runAs + `
140-
}
141+
` + runAs + `
141142
}
142143
` + dltNotebookResource
143144
}
@@ -180,6 +181,10 @@ func TestUcAccPipelineRunAsMutations(t *testing.T) {
180181
acceptance.Step{
181182
Template: pipelineRunAsTemplate(`service_principal_name = "` + spId + `"`),
182183
},
184+
// Remove run_as, and there should be no change.
185+
acceptance.Step{
186+
Template: pipelineRunAsTemplate(""),
187+
},
183188
)
184189
}
185190

pipelines/resource_pipeline.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func Update(w *databricks.WorkspaceClient, ctx context.Context, d *schema.Resour
7171
common.DataToStructPointer(d, pipelineSchema, &updatePipelineRequest)
7272
updatePipelineRequest.EditPipeline.PipelineId = d.Id()
7373
adjustForceSendFields(&updatePipelineRequest.Clusters)
74+
// Workspaces not enrolled in the private preview must not send run_as in the update request.
75+
// If run_as was persisted in state because of a `terraform refresh`, there will not be a planned change
76+
// as long as the user hasn't specified a value.
77+
if !d.HasChange("run_as") {
78+
updatePipelineRequest.RunAs = nil
79+
}
7480

7581
err := w.Pipelines.Update(ctx, updatePipelineRequest.EditPipeline)
7682
if err != nil {

0 commit comments

Comments
 (0)