Skip to content

Commit 64f0e73

Browse files
authored
correct force_new attributes for databricks_schema and databricks_volume (#2635)
* correct force_new attributes for schema and volume * fix old tests * fix test
1 parent e89bcdd commit 64f0e73

File tree

6 files changed

+121
-9
lines changed

6 files changed

+121
-9
lines changed

catalog/resource_schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
type SchemaInfo struct {
1313
Name string `json:"name" tf:"force_new"`
14-
CatalogName string `json:"catalog_name"`
14+
CatalogName string `json:"catalog_name" tf:"force_new"`
1515
StorageRoot string `json:"storage_root,omitempty" tf:"force_new"`
1616
Comment string `json:"comment,omitempty"`
1717
Properties map[string]string `json:"properties,omitempty"`

catalog/resource_schema_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func TestUpdateSchema(t *testing.T) {
121121
Resource: "/api/2.1/unity-catalog/schemas/b.a?",
122122
Response: catalog.SchemaInfo{
123123
Name: "a",
124+
CatalogName: "b",
124125
MetastoreId: "d",
125126
Comment: "c",
126127
Owner: "administrators",
@@ -145,6 +146,53 @@ func TestUpdateSchema(t *testing.T) {
145146
}.ApplyNoError(t)
146147
}
147148

149+
func TestUpdateSchemaForceNew(t *testing.T) {
150+
qa.ResourceFixture{
151+
Fixtures: []qa.HTTPFixture{
152+
{
153+
Method: "PATCH",
154+
Resource: "/api/2.1/unity-catalog/schemas/b.a",
155+
ExpectedRequest: catalog.UpdateSchema{
156+
Owner: "administrators",
157+
Name: "a",
158+
Comment: "c",
159+
},
160+
Response: catalog.SchemaInfo{
161+
FullName: "b.a",
162+
Comment: "c",
163+
Owner: "administrators",
164+
},
165+
},
166+
{
167+
Method: "GET",
168+
Resource: "/api/2.1/unity-catalog/schemas/b.a?",
169+
Response: catalog.SchemaInfo{
170+
Name: "a",
171+
MetastoreId: "d",
172+
Comment: "c",
173+
Owner: "administrators",
174+
},
175+
},
176+
},
177+
RequiresNew: true,
178+
Resource: ResourceSchema(),
179+
Update: true,
180+
ID: "b.a",
181+
InstanceState: map[string]string{
182+
"metastore_id": "d",
183+
"name": "a",
184+
"catalog_name": "b",
185+
"comment": "c",
186+
},
187+
HCL: `
188+
name = "a"
189+
catalog_name = "x"
190+
comment = "c"
191+
owner = "administrators"
192+
`,
193+
}.ApplyNoError(t)
194+
}
195+
148196
func TestDeleteSchema(t *testing.T) {
149197
qa.ResourceFixture{
150198
Fixtures: []qa.HTTPFixture{

catalog/resource_volume.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
// We also need to annotate tf:"computed" for the Owner field.
1414
type VolumeInfo struct {
1515
// The name of the catalog where the schema and the volume are
16-
CatalogName string `json:"catalog_name"`
16+
CatalogName string `json:"catalog_name" tf:"force_new"`
1717
// The comment attached to the volume
1818
Comment string `json:"comment,omitempty"`
1919
// The name of the schema where the volume is
20-
SchemaName string `json:"schema_name"`
20+
SchemaName string `json:"schema_name" tf:"force_new"`
2121
FullNameArg string `json:"-" url:"-"`
2222
// The name of the volume
2323
Name string `json:"name"`

catalog/resource_volume_test.go

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ func TestVolumesUpdate(t *testing.T) {
329329
},
330330
Resource: ResourceVolume(),
331331
Update: true,
332-
ID: "testCatalogName.testSchemaName.testName",
332+
InstanceState: map[string]string{
333+
"catalog_name": "testCatalogName",
334+
"schema_name": "testSchemaName",
335+
},
336+
ID: "testCatalogName.testSchemaName.testName",
333337
HCL: `
334338
name = "testNameNew"
335339
volume_type = "testVolumeType"
@@ -347,6 +351,62 @@ func TestVolumesUpdate(t *testing.T) {
347351
assert.Equal(t, "This is a new test comment.", d.Get("comment"))
348352
}
349353

354+
func TestVolumesUpdateForceNew(t *testing.T) {
355+
d, err := qa.ResourceFixture{
356+
Fixtures: []qa.HTTPFixture{
357+
{
358+
Method: http.MethodGet,
359+
Resource: "/api/2.1/unity-catalog/volumes/testCatalogNameNew.testSchemaName.testName?",
360+
Response: catalog.VolumeInfo{
361+
Name: "testNameNew",
362+
VolumeType: catalog.VolumeType("testVolumeType"),
363+
CatalogName: "testCatalogNameNew",
364+
SchemaName: "testSchemaName",
365+
Comment: "This is a new test comment.",
366+
FullName: "testCatalogName.testSchemaName.testNameNew",
367+
Owner: "testOwnerNew",
368+
},
369+
},
370+
{
371+
Method: http.MethodPatch,
372+
Resource: "/api/2.1/unity-catalog/volumes/testCatalogName.testSchemaName.testName",
373+
ExpectedRequest: catalog.UpdateVolumeRequestContent{
374+
Name: "testNameNew",
375+
Comment: "This is a new test comment.",
376+
Owner: "testOwnerNew",
377+
},
378+
Response: catalog.VolumeInfo{
379+
Name: "testNameNew",
380+
VolumeType: catalog.VolumeType("testVolumeType"),
381+
CatalogName: "testCatalogNameNew",
382+
SchemaName: "testSchemaName",
383+
Comment: "This is a new test comment.",
384+
FullName: "testCatalogNameNew.testSchemaName.testName",
385+
Owner: "testOwnerNew",
386+
},
387+
},
388+
},
389+
Resource: ResourceVolume(),
390+
RequiresNew: true,
391+
Update: true,
392+
ID: "testCatalogName.testSchemaName.testName",
393+
HCL: `
394+
name = "testNameNew"
395+
volume_type = "testVolumeType"
396+
catalog_name = "testCatalogNameNew"
397+
schema_name = "testSchemaName"
398+
comment = "This is a new test comment."
399+
owner = "testOwnerNew"
400+
`,
401+
}.Apply(t)
402+
assert.NoError(t, err)
403+
assert.Equal(t, "testNameNew", d.Get("name"))
404+
assert.Equal(t, "testVolumeType", d.Get("volume_type"))
405+
assert.Equal(t, "testCatalogNameNew", d.Get("catalog_name"))
406+
assert.Equal(t, "testSchemaName", d.Get("schema_name"))
407+
assert.Equal(t, "This is a new test comment.", d.Get("comment"))
408+
}
409+
350410
func TestVolumeUpdate_Error(t *testing.T) {
351411
_, err := qa.ResourceFixture{
352412
Fixtures: []qa.HTTPFixture{
@@ -367,7 +427,11 @@ func TestVolumeUpdate_Error(t *testing.T) {
367427
},
368428
Resource: ResourceVolume(),
369429
Update: true,
370-
ID: "testCatalogName.testSchemaName.testName",
430+
InstanceState: map[string]string{
431+
"catalog_name": "testCatalogName",
432+
"schema_name": "testSchemaName",
433+
},
434+
ID: "testCatalogName.testSchemaName.testName",
371435
HCL: `
372436
name = "testNameNew"
373437
volume_type = "testVolumeType"

docs/resources/schema.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource "databricks_schema" "things" {
3434
The following arguments are required:
3535

3636
* `name` - Name of Schema relative to parent catalog. Change forces creation of a new resource.
37-
* `catalog_name` - Name of parent catalog
37+
* `catalog_name` - Name of parent catalog. Change forces creation of a new resource.
3838
* `storage_root` - (Optional) Managed location of the schema. Location in cloud storage where data for managed tables will be stored. If not specified, the location will default to the metastore root location. Change forces creation of a new resource.
3939
* `owner` - (Optional) Username/groupname/sp application_id of the schema owner.
4040
* `comment` - (Optional) User-supplied free-form text.
@@ -46,7 +46,7 @@ The following arguments are required:
4646
This resource can be imported by its full name:
4747

4848
```bash
49-
$ terraform import databricks_schema.this <catalog_name>.<name>
49+
terraform import databricks_schema.this <catalog_name>.<name>
5050
```
5151

5252
## Related Resources

docs/resources/volume.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ resource "databricks_volume" "this" {
8080
The following arguments are supported:
8181

8282
* `name` - Name of the Volume
83-
* `catalog_name` - Name of parent Catalog
84-
* `schema_name` - Name of parent Schema relative to parent Catalog
83+
* `catalog_name` - Name of parent Catalog. Change forces creation of a new resource.
84+
* `schema_name` - Name of parent Schema relative to parent Catalog. Change forces creation of a new resource.
8585
* `volume_type` - Volume type. `EXTERNAL` or `MANAGED`.
8686
* `owner` - (Optional) Name of the volume owner.
8787
* `storage_location` - (Optional) Path inside an External Location. Only used for `EXTERNAL` Volumes.

0 commit comments

Comments
 (0)