Skip to content
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

Add databricks_workspace_file resource #2266

Merged
merged 4 commits into from
May 8, 2023
Merged

Add databricks_workspace_file resource #2266

merged 4 commits into from
May 8, 2023

Conversation

alexott
Copy link
Contributor

@alexott alexott commented May 5, 2023

Changes

With recent release of the workspace file support it's now possible to store arbitrary files in the workspace, not only notebooks. It's also recommended way to store init scripts to avoid security problems associated with storing init scripts on DBFS.

I deliberately didn't use the Go SDK as all code was already available. Migration to Go SDK will follow after discussions on the change required for supporting list command (see #2258)

This fixes #2206

Tests

  • make test run locally
  • tested manually
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@alexott alexott requested review from a team May 5, 2023 12:30
With recent release of the workspace file support it's now possible to store arbitrary
files in the workspace, not only notebooks.  It's also recommended way to store init
scripts to avoid security problems associated with storing init scripts on DBFS.
@alexott alexott force-pushed the workspace-files-support branch from ce30f6e to 9026889 Compare May 5, 2023 12:32
@alexott alexott marked this pull request as ready for review May 5, 2023 12:55
Copy link
Contributor

@nfx nfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. sdk has to be used for all new resources.
  2. finish s/notebook/file/g in the docs ;)

if err != nil {
return err
}
notebooksAPI := NewNotebooksAPI(ctx, c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDK has to be used for all new resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote why it wasn't used :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the c.WorkspaceClient() instead of NewNotebooksAPI

@alexott alexott requested a review from nfx May 8, 2023 11:59
@codecov-commenter
Copy link

codecov-commenter commented May 8, 2023

Codecov Report

Merging #2266 (27abb22) into master (80ddeeb) will decrease coverage by 0.06%.
The diff coverage is 82.05%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2266      +/-   ##
==========================================
- Coverage   88.79%   88.74%   -0.06%     
==========================================
  Files         139      140       +1     
  Lines       11477    11549      +72     
==========================================
+ Hits        10191    10249      +58     
- Misses        861      868       +7     
- Partials      425      432       +7     
Impacted Files Coverage Δ
workspace/resource_workspace_file.go 78.12% <78.12%> (ø)
permissions/resource_permissions.go 89.62% <100.00%> (+0.26%) ⬆️
provider/provider.go 93.90% <100.00%> (+0.03%) ⬆️
workspace/data_notebook_paths.go 87.50% <100.00%> (+0.83%) ⬆️
workspace/resource_notebook.go 90.20% <100.00%> (ø)

if err != nil {
return err
}
notebooksAPI := NewNotebooksAPI(ctx, c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the c.WorkspaceClient() instead of NewNotebooksAPI

@alexott alexott requested a review from nfx May 8, 2023 12:58
Path: path,
Overwrite: true,
}
err = notebooksAPI.Import(ctx, createNotebook)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client.Workspace.Import(ctx, ws_api.Import{
				Content:   base64.StdEncoding.EncodeToString(content),
				Format:    ws_api.ExportFormatAuto,
				Path:      path,
				Overwrite: true,
			})

path := d.Get("path").(string)
parent := filepath.ToSlash(filepath.Dir(path))
if parent != "/" {
err = notebooksAPI.MkdirsByPath(ctx, parent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = notebooksAPI.MkdirsByPath(ctx, parent)
err = client.Workspace..MkdirsByPath(ctx, parent)

Copy link
Contributor

@nfx nfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nfx nfx merged commit 3c2c2b5 into master May 8, 2023
@nfx nfx deleted the workspace-files-support branch May 8, 2023 14:55
nfx added a commit that referenced this pull request May 12, 2023
# Version changelog

## 1.16.0

 * Added [databricks_workspace_file](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/workspace_file) resource ([#2266](#2266)).
 * Added `notification_settings` block to [databricks_job](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/job) resource ([#2276](#2276)).
 * Added missing permission to [databricks_aws_crossaccount_policy](https://registry.terraform.io/providers/databricks/databricks/latest/docs/data-sources/aws_crossaccount_policy) data source ([#2283](#2283)).
 * Fixed [databricks_sql_table](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/sql_table) doc ([#2281](#2281)).
 * Fixed doc on tag propagation and tag conflict for [databricks_instance_pool](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/instance_pool) resource ([#2242](#2242)).
 * Document & export [databricks_workspace_conf](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/workspace_conf) parameters for legacy init scripts ([#2280](#2280)).
 * Removed deprecated `CREATE_VIEW` from code of [databricks_grants](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/grants) resource ([#2230](#2230)).
 * Exporter: relax handling of problematic files/directories ([#2258](#2258)).
@nfx nfx mentioned this pull request May 12, 2023
nfx added a commit that referenced this pull request May 12, 2023
# Version changelog

## 1.16.0

 * Added [databricks_workspace_file](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/workspace_file) resource ([#2266](#2266)).
 * Added `notification_settings` block to [databricks_job](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/job) resource ([#2276](#2276)).
 * Added missing permission to [databricks_aws_crossaccount_policy](https://registry.terraform.io/providers/databricks/databricks/latest/docs/data-sources/aws_crossaccount_policy) data source ([#2283](#2283)).
 * Fixed [databricks_sql_table](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/sql_table) doc ([#2281](#2281)).
 * Fixed doc on tag propagation and tag conflict for [databricks_instance_pool](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/instance_pool) resource ([#2242](#2242)).
 * Document & export [databricks_workspace_conf](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/workspace_conf) parameters for legacy init scripts ([#2280](#2280)).
 * Removed deprecated `CREATE_VIEW` from code of [databricks_grants](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/grants) resource ([#2230](#2230)).
 * Exporter: relax handling of problematic files/directories ([#2258](#2258)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support for workspace files
3 participants