Skip to content

Commit

Permalink
Added full_name attribute to databricks_system_schema resource
Browse files Browse the repository at this point in the history
This will simplify references to the system schemas from other resources, such as, grants.
  • Loading branch information
alexott committed Jun 3, 2024
1 parent 196b05b commit c8781c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
11 changes: 10 additions & 1 deletion catalog/resource_system_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions catalog/resource_system_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestSystemSchemaCreate(t *testing.T) {
d, err := qa.ResourceFixture{
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: http.MethodGet,
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions docs/resources/system_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ 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

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.<schema>`.

## Import

This resource can be imported by the metastore id and schema name

```bash
terraform import databricks_system_schema.this <metastore_id>|<schema_name>
terraform import databricks_system_schema.this '<metastore_id>|<schema_name>'
```

0 comments on commit c8781c7

Please sign in to comment.