-
Notifications
You must be signed in to change notification settings - Fork 473
Fix workspace path normalization to prevent inconsistent plan errors #5130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes #4672 This commit addresses the issue where Databricks API may add or remove the /Workspace prefix in paths depending on workspace configuration, causing Terraform to detect false changes and produce 'inconsistent final plan' errors. Changes: - Added NormalizeWorkspacePath() function in workspace/file_resource.go to normalize path returned from API to match configured path - Updated workspace resources (databricks_workspace_file, databricks_notebook, databricks_directory) to use path normalization in Read operations - Updated SQL resources (databricks_query, databricks_alert) to use path normalization for parent_path field - Fixed bugs in sql/resource_query.go and sql/resource_alert.go where wrong variable was used in path normalization - Added comprehensive unit tests (8 test cases) for path normalization - Added integration test for workspace prefix normalization The fix handles both directions: - Strips /Workspace when API adds it but config doesn't have it - Adds /Workspace when config has it but API doesn't have it This ensures the path in state always matches what user configured, preventing Terraform from detecting drift when there is none.
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
| } | ||
|
|
||
| // NormalizeWorkspacePath normalizes the path returned from the API to match the configured path. | ||
| // The Databricks API may add or remove the "/Workspace" prefix depending on the workspace configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @alexott, do you know why this happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw it in cases when user edit a job (even without changing anything)
| // Case 1: API added /Workspace prefix, but config doesn't have it | ||
| if strings.HasPrefix(apiPath, "/Workspace") && !strings.HasPrefix(configuredPath, "/Workspace") { | ||
| return strings.TrimPrefix(apiPath, "/Workspace") | ||
| } | ||
|
|
||
| // Case 2: Config has /Workspace prefix, but API doesn't have it | ||
| if !strings.HasPrefix(apiPath, "/Workspace") && strings.HasPrefix(configuredPath, "/Workspace") { | ||
| return "/Workspace" + apiPath | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both of these cases, shouldn't we ask users to update the config with proper paths?
Changes
Fixes #4672
This commit addresses the issue where Databricks API may add or remove the /Workspace prefix in paths depending on workspace configuration, causing Terraform to detect false changes and produce 'inconsistent final plan' errors.
Changes:
The fix handles both directions:
This ensures the path in state always matches what user configured, preventing Terraform from detecting drift when there is none.
Tests
make testrun locallydocs/folderinternal/acceptanceNEXT_CHANGELOG.mdfile