Skip to content

Commit 4409a63

Browse files
authored
[Feature] Add workspace_path attribute to databricks_notebook resource and data source (#3885)
## Changes <!-- Summary of your changes that are easy to understand --> This unifies these resources/data sources with other workspace objects - it will be useful to support it as we adopt `/Workspace/...` paths in jobs and other resources ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [ ] using Go SDK
1 parent 1f8e5e1 commit 4409a63

File tree

6 files changed

+48
-34
lines changed

6 files changed

+48
-34
lines changed

docs/data-sources/notebook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ This data source exports the following attributes:
2929
* `language` - notebook language
3030
* `object_id` - notebook object ID
3131
* `object_type` - notebook object type
32+
* `workspace_path` - path on Workspace File System (WSFS) in form of `/Workspace` + `path`

docs/resources/notebook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ In addition to all arguments above, the following attributes are exported:
6060
* `id` - Path of notebook on workspace
6161
* `url` - Routable URL of the notebook
6262
* `object_id` - Unique identifier for a NOTEBOOK
63+
* `workspace_path` - path on Workspace File System (WSFS) in form of `/Workspace` + `path`
6364

6465
## Access Control
6566

workspace/data_notebook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func DataSourceNotebook() common.Resource {
4646
Optional: true,
4747
Computed: true,
4848
},
49+
"workspace_path": {
50+
Type: schema.TypeString,
51+
Computed: true,
52+
},
4953
}
5054
return common.Resource{
5155
Schema: s,
@@ -74,6 +78,7 @@ func DataSourceNotebook() common.Resource {
7478
if err != nil {
7579
return err
7680
}
81+
d.Set("workspace_path", "/Workspace"+objectStatus.Path)
7782
return nil
7883
},
7984
}

workspace/data_notebook_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import (
55

66
"github.com/databricks/databricks-sdk-go/apierr"
77
"github.com/databricks/terraform-provider-databricks/qa"
8-
"github.com/stretchr/testify/assert"
9-
"github.com/stretchr/testify/require"
108
)
119

1210
func TestDataSourceNotebook(t *testing.T) {
13-
d, err := qa.ResourceFixture{
11+
qa.ResourceFixture{
1412
Fixtures: []qa.HTTPFixture{
1513
{
1614
Method: "GET",
@@ -38,10 +36,11 @@ func TestDataSourceNotebook(t *testing.T) {
3836
"path": "/a/b/c",
3937
"format": "SOURCE",
4038
},
41-
}.Apply(t)
42-
require.NoError(t, err)
43-
assert.Equal(t, "/a/b/c", d.Id())
44-
assert.Equal(t, "SGVsbG8gd29ybGQK", d.Get("content"))
39+
}.ApplyAndExpectData(t, map[string]any{
40+
"id": "/a/b/c",
41+
"content": "SGVsbG8gd29ybGQK",
42+
"workspace_path": "/Workspace/a/b/c",
43+
})
4544
}
4645

4746
func TestDataSourceNotebook_ErrorExport(t *testing.T) {

workspace/resource_notebook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ func ResourceNotebook() common.Resource {
249249
Optional: true,
250250
Computed: true,
251251
},
252+
"workspace_path": {
253+
Type: schema.TypeString,
254+
Computed: true,
255+
},
252256
})
253257
s["content_base64"].RequiredWith = []string{"language"}
254258
return common.Resource{
@@ -308,6 +312,7 @@ func ResourceNotebook() common.Resource {
308312
return err
309313
}
310314
d.Set("url", c.FormatURL("#workspace", d.Id()))
315+
d.Set("workspace_path", "/Workspace"+objectStatus.Path)
311316
return common.StructToData(objectStatus, s, d)
312317
},
313318
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {

workspace/resource_notebook_test.go

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func TestResourceNotebookRead(t *testing.T) {
1414
path := "/test/path.py"
1515
objectID := 12345
16-
d, err := qa.ResourceFixture{
16+
qa.ResourceFixture{
1717
Fixtures: []qa.HTTPFixture{
1818
{
1919
Method: http.MethodGet,
@@ -30,17 +30,18 @@ func TestResourceNotebookRead(t *testing.T) {
3030
Read: true,
3131
New: true,
3232
ID: path,
33-
}.Apply(t)
34-
assert.NoError(t, err)
35-
assert.Equal(t, path, d.Id())
36-
assert.Equal(t, path, d.Get("path"))
37-
assert.Equal(t, "PYTHON", d.Get("language"))
38-
assert.Equal(t, objectID, d.Get("object_id"))
33+
}.ApplyAndExpectData(t, map[string]any{
34+
"path": path,
35+
"object_id": objectID,
36+
"language": "PYTHON",
37+
"id": path,
38+
"workspace_path": "/Workspace" + path,
39+
})
3940
}
4041

4142
func TestResourceNotebookDelete(t *testing.T) {
4243
path := "/test/path.py"
43-
d, err := qa.ResourceFixture{
44+
qa.ResourceFixture{
4445
Fixtures: []qa.HTTPFixture{
4546
{
4647
Method: http.MethodPost,
@@ -52,9 +53,9 @@ func TestResourceNotebookDelete(t *testing.T) {
5253
Resource: ResourceNotebook(),
5354
Delete: true,
5455
ID: path,
55-
}.Apply(t)
56-
assert.NoError(t, err)
57-
assert.Equal(t, path, d.Id())
56+
}.ApplyAndExpectData(t, map[string]any{
57+
"id": path,
58+
})
5859
}
5960

6061
func TestResourceNotebookRead_NotFound(t *testing.T) {
@@ -99,7 +100,7 @@ func TestResourceNotebookRead_Error(t *testing.T) {
99100
}
100101

101102
func TestResourceNotebookCreate_DirectoryExist(t *testing.T) {
102-
d, err := qa.ResourceFixture{
103+
qa.ResourceFixture{
103104
Fixtures: []qa.HTTPFixture{
104105
{
105106
Method: "POST",
@@ -144,13 +145,14 @@ func TestResourceNotebookCreate_DirectoryExist(t *testing.T) {
144145
"path": "/foo/path.py",
145146
},
146147
Create: true,
147-
}.Apply(t)
148-
assert.NoError(t, err)
149-
assert.Equal(t, "/foo/path.py", d.Id())
148+
}.ApplyAndExpectData(t, map[string]any{
149+
"path": "/foo/path.py",
150+
"id": "/foo/path.py",
151+
})
150152
}
151153

152154
func TestResourceNotebookCreate_DirectoryDoesntExist(t *testing.T) {
153-
d, err := qa.ResourceFixture{
155+
qa.ResourceFixture{
154156
Fixtures: []qa.HTTPFixture{
155157
{
156158
Method: "POST",
@@ -211,9 +213,10 @@ func TestResourceNotebookCreate_DirectoryDoesntExist(t *testing.T) {
211213
"path": "/foo/path.py",
212214
},
213215
Create: true,
214-
}.Apply(t)
215-
assert.NoError(t, err)
216-
assert.Equal(t, "/foo/path.py", d.Id())
216+
}.ApplyAndExpectData(t, map[string]any{
217+
"path": "/foo/path.py",
218+
"id": "/foo/path.py",
219+
})
217220
}
218221

219222
func TestResourceNotebookCreate_DirectoryCreateError(t *testing.T) {
@@ -260,7 +263,7 @@ func TestResourceNotebookCreate_DirectoryCreateError(t *testing.T) {
260263
}
261264

262265
func TestResourceNotebookCreateSource_Jupyter(t *testing.T) {
263-
d, err := qa.ResourceFixture{
266+
qa.ResourceFixture{
264267
Fixtures: []qa.HTTPFixture{
265268
{
266269
Method: http.MethodPost,
@@ -308,13 +311,13 @@ func TestResourceNotebookCreateSource_Jupyter(t *testing.T) {
308311
"path": "/Mars",
309312
},
310313
Create: true,
311-
}.Apply(t)
312-
assert.NoError(t, err)
313-
assert.Equal(t, "/Mars", d.Id())
314+
}.ApplyAndExpectData(t, map[string]any{
315+
"id": "/Mars",
316+
})
314317
}
315318

316319
func TestResourceNotebookCreateSource(t *testing.T) {
317-
d, err := qa.ResourceFixture{
320+
qa.ResourceFixture{
318321
Fixtures: []qa.HTTPFixture{
319322
{
320323
Method: http.MethodPost,
@@ -346,9 +349,9 @@ func TestResourceNotebookCreateSource(t *testing.T) {
346349
"path": "/Dashboard",
347350
},
348351
Create: true,
349-
}.Apply(t)
350-
assert.NoError(t, err)
351-
assert.Equal(t, "/Dashboard", d.Id())
352+
}.ApplyAndExpectData(t, map[string]any{
353+
"id": "/Dashboard",
354+
})
352355
}
353356

354357
func TestResourceNotebookCreate_Error(t *testing.T) {

0 commit comments

Comments
 (0)