Skip to content

Commit c8ab19d

Browse files
authored
Add enum for volume grant privileges (#3395)
## Changes Add an enum for volume grant privileges. Possible values are: - `ALL_PRIVILEGES` - `APPLY_TAG` (missing in Terraform docs but supported) - `MANAGE` - `READ_VOLUME` - `WRITE_VOLUME` It follows documented privileges in Terraform documentation: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/grants#volume-grants I will add `APPLY_TAG` to Terraform as a follow-up. ## Why Using enums gives better typing in JSON schema and allows generating enums in Python code ## Tests By inspecting the resulting JSON schema
1 parent 2c4255b commit c8ab19d

File tree

6 files changed

+129
-7
lines changed

6 files changed

+129
-7
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
### CLI
1010

1111
### Bundles
12+
* Add supported enum values to JSON schema for volume grant privileges ([#3395](https://github.com/databricks/cli/pull/3395))
1213

1314
### API Changes

bundle/config/resources/volume.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,36 @@ import (
1313
"github.com/databricks/databricks-sdk-go/service/catalog"
1414
)
1515

16+
type VolumeGrantPrivilege string
17+
18+
const (
19+
VolumeGrantPrivilegeAllPrivileges VolumeGrantPrivilege = "ALL_PRIVILEGES"
20+
VolumeGrantPrivilegeApplyTag VolumeGrantPrivilege = "APPLY_TAG"
21+
VolumeGrantPrivilegeManage VolumeGrantPrivilege = "MANAGE"
22+
VolumeGrantPrivilegeReadVolume VolumeGrantPrivilege = "READ_VOLUME"
23+
VolumeGrantPrivilegeWriteVolume VolumeGrantPrivilege = "WRITE_VOLUME"
24+
)
25+
26+
// Values returns all valid VolumeGrantPrivilege values
27+
func (VolumeGrantPrivilege) Values() []VolumeGrantPrivilege {
28+
return []VolumeGrantPrivilege{
29+
VolumeGrantPrivilegeAllPrivileges,
30+
VolumeGrantPrivilegeApplyTag,
31+
VolumeGrantPrivilegeManage,
32+
VolumeGrantPrivilegeReadVolume,
33+
VolumeGrantPrivilegeWriteVolume,
34+
}
35+
}
36+
37+
type VolumeGrant struct {
38+
Privileges []VolumeGrantPrivilege `json:"privileges"`
39+
40+
Principal string `json:"principal"`
41+
}
42+
1643
type Volume struct {
1744
// List of grants to apply on this volume.
18-
Grants []Grant `json:"grants,omitempty"`
45+
Grants []VolumeGrant `json:"grants,omitempty"`
1946

2047
// Full name of the volume (catalog_name.schema_name.volume_name). This value is read from
2148
// the terraform state after deployment succeeds.

bundle/deploy/terraform/tfdyn/convert_volume_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ func TestConvertVolume(t *testing.T) {
2323
StorageLocation: "s3://bucket/path",
2424
VolumeType: "EXTERNAL",
2525
},
26-
Grants: []resources.Grant{
26+
Grants: []resources.VolumeGrant{
2727
{
28-
Privileges: []string{"READ_VOLUME"},
29-
Principal: "[email protected]",
28+
Privileges: []resources.VolumeGrantPrivilege{
29+
resources.VolumeGrantPrivilegeReadVolume,
30+
},
31+
Principal: "[email protected]",
3032
},
3133
{
32-
Privileges: []string{"WRITE_VOLUME"},
33-
Principal: "[email protected]",
34+
Privileges: []resources.VolumeGrantPrivilege{
35+
resources.VolumeGrantPrivilegeWriteVolume,
36+
},
37+
Principal: "[email protected]",
3438
},
3539
},
3640
}

bundle/internal/schema/annotations.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,13 @@ github.com/databricks/cli/bundle/config/resources.SqlWarehousePermission:
598598
"user_name":
599599
"description": |-
600600
PLACEHOLDER
601+
github.com/databricks/cli/bundle/config/resources.VolumeGrant:
602+
"principal":
603+
"description": |-
604+
PLACEHOLDER
605+
"privileges":
606+
"description": |-
607+
PLACEHOLDER
601608
github.com/databricks/cli/bundle/config/variable.Lookup:
602609
"alert":
603610
"description": |-

bundle/internal/schema/annotations_openapi_overrides.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,19 @@ github.com/databricks/cli/bundle/config/resources.SqlWarehousePermissionLevel:
503503
CAN_MONITOR
504504
- |-
505505
CAN_VIEW
506+
github.com/databricks/cli/bundle/config/resources.VolumeGrantPrivilege:
507+
"_":
508+
"enum":
509+
- |-
510+
ALL_PRIVILEGES
511+
- |-
512+
APPLY_TAG
513+
- |-
514+
MANAGE
515+
- |-
516+
READ_VOLUME
517+
- |-
518+
WRITE_VOLUME
506519
github.com/databricks/cli/bundle/config/resources.Volume:
507520
"_":
508521
"markdown_description": |-

bundle/schema/jsonschema.json

Lines changed: 71 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)