Skip to content

Commit e89bcdd

Browse files
authored
Add options field to UC catalog resource to support foreign catalog creation (#2616)
* Done * Done * test * fix * format * Done * Done * Done * Done
1 parent bf3e048 commit e89bcdd

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

catalog/resource_catalog.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type CatalogInfo struct {
3333
ProviderName string `json:"provider_name,omitempty" tf:"force_new,conflicts:storage_root"`
3434
ShareName string `json:"share_name,omitempty" tf:"force_new,conflicts:storage_root"`
3535
ConnectionName string `json:"connection_name,omitempty" tf:"force_new,conflicts:storage_root"`
36+
Options map[string]string `json:"options,omitempty" tf:"force_new"`
3637
Properties map[string]string `json:"properties,omitempty"`
3738
Owner string `json:"owner,omitempty" tf:"computed"`
3839
IsolationMode string `json:"isolation_mode,omitempty" tf:"computed"`

catalog/resource_catalog_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,68 @@ func TestCatalogCreateDeltaSharing(t *testing.T) {
396396
}.ApplyNoError(t)
397397
}
398398

399+
func TestCatalogCreateForeign(t *testing.T) {
400+
d, err := qa.ResourceFixture{
401+
Fixtures: []qa.HTTPFixture{
402+
{
403+
Method: "POST",
404+
Resource: "/api/2.1/unity-catalog/catalogs",
405+
ExpectedRequest: catalog.CatalogInfo{
406+
Name: "foreign_catalog",
407+
Comment: "b",
408+
Options: map[string]string{
409+
"database": "abcd",
410+
},
411+
ConnectionName: "foo",
412+
},
413+
Response: catalog.CatalogInfo{
414+
Name: "foreign_catalog",
415+
Comment: "b",
416+
Options: map[string]string{
417+
"database": "abcd",
418+
},
419+
ConnectionName: "foo",
420+
MetastoreId: "e",
421+
Owner: "f",
422+
},
423+
},
424+
{
425+
Method: "DELETE",
426+
Resource: "/api/2.1/unity-catalog/schemas/foreign_catalog.default?",
427+
},
428+
{
429+
Method: "GET",
430+
Resource: "/api/2.1/unity-catalog/catalogs/foreign_catalog?",
431+
Response: catalog.CatalogInfo{
432+
Name: "foreign_catalog",
433+
Comment: "b",
434+
Options: map[string]string{
435+
"database": "abcd",
436+
},
437+
ConnectionName: "foo",
438+
MetastoreId: "e",
439+
Owner: "f",
440+
},
441+
},
442+
},
443+
Resource: ResourceCatalog(),
444+
Create: true,
445+
HCL: `
446+
name = "foreign_catalog"
447+
comment = "b"
448+
options = {
449+
database = "abcd"
450+
}
451+
connection_name = "foo"
452+
`,
453+
}.Apply(t)
454+
assert.NoError(t, err)
455+
assert.Equal(t, "foreign_catalog", d.Get("name"))
456+
assert.Equal(t, "foo", d.Get("connection_name"))
457+
assert.Equal(t, "b", d.Get("comment"))
458+
assert.Equal(t, map[string]interface{}{"database": "abcd"}, d.Get("options"))
459+
}
460+
399461
func TestCatalogCreateIsolated(t *testing.T) {
400462
qa.ResourceFixture{
401463
Fixtures: []qa.HTTPFixture{

docs/resources/catalog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The following arguments are required:
3333
* `isolation_mode` - (Optional) Whether the catalog is accessible from all workspaces or a specific set of workspaces. Can be `ISOLATED` or `OPEN`. Setting the catalog to `ISOLATED` will automatically allow access from the current workspace.
3434
* `comment` - (Optional) User-supplied free-form text.
3535
* `properties` - (Optional) Extensible Catalog properties.
36+
* `options` - (Optional) For Foreign Catalogs: the name of the entity from an external data source that maps to a catalog. For example, the database name in a PostgreSQL server.
3637
* `force_destroy` - (Optional) Delete catalog regardless of its contents.
3738

3839
## Import

0 commit comments

Comments
 (0)