From c8781c7194f3b9b66061fa021c72e44aadaa8585 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Mon, 3 Jun 2024 09:22:13 +0200 Subject: [PATCH] Added `full_name` attribute to `databricks_system_schema` resource This will simplify references to the system schemas from other resources, such as, grants. --- catalog/resource_system_schema.go | 11 ++++++++++- catalog/resource_system_schema_test.go | 10 ++++++---- docs/resources/system_schema.md | 5 +++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/catalog/resource_system_schema.go b/catalog/resource_system_schema.go index 19c3e371fa..06b1ff24d3 100644 --- a/catalog/resource_system_schema.go +++ b/catalog/resource_system_schema.go @@ -17,6 +17,10 @@ func ResourceSystemSchema() common.Resource { Type: schema.TypeString, Computed: true, } + m["full_name"] = &schema.Schema{ + Type: schema.TypeString, + Computed: true, + } m["state"].Computed = true return m }) @@ -85,7 +89,12 @@ func ResourceSystemSchema() common.Resource { } for _, schema := range systemSchemaInfo.Schemas { if schema.Schema == schemaName { - return common.StructToData(schema, systemSchema, d) + err = common.StructToData(schema, systemSchema, d) + if err != nil { + return err + } + d.Set("full_name", fmt.Sprintf("system.%s", schemaName)) + return nil } } return nil diff --git a/catalog/resource_system_schema_test.go b/catalog/resource_system_schema_test.go index baaeb02f65..d3720075ab 100644 --- a/catalog/resource_system_schema_test.go +++ b/catalog/resource_system_schema_test.go @@ -11,7 +11,7 @@ import ( ) func TestSystemSchemaCreate(t *testing.T) { - d, err := qa.ResourceFixture{ + qa.ResourceFixture{ Fixtures: []qa.HTTPFixture{ { Method: http.MethodGet, @@ -52,9 +52,11 @@ func TestSystemSchemaCreate(t *testing.T) { Resource: ResourceSystemSchema(), HCL: `schema = "access"`, Create: true, - }.Apply(t) - assert.NoError(t, err) - assert.Equal(t, "abc|access", d.Id()) + }.ApplyAndExpectData(t, map[string]any{ + "schema": "access", + "id": "abc|access", + "full_name": "system.access", + }) } func TestSystemSchemaCreate_Error(t *testing.T) { diff --git a/docs/resources/system_schema.md b/docs/resources/system_schema.md index 51ea5a9280..18c515de6e 100644 --- a/docs/resources/system_schema.md +++ b/docs/resources/system_schema.md @@ -23,7 +23,7 @@ resource "databricks_system_schema" "this" { The following arguments are available: -* `schema` - (Required) Full name of the system schema. +* `schema` - (Required) name of the system schema. ## Attribute Reference @@ -31,11 +31,12 @@ In addition to all arguments above, the following attributes are exported: * `id` - the ID of system schema in form of `metastore_id|schema_name`. * `state` - The current state of enablement for the system schema. +* `full_name` - the full name of the system schema, in form of `system.`. ## Import This resource can be imported by the metastore id and schema name ```bash -terraform import databricks_system_schema.this | +terraform import databricks_system_schema.this '|' ```