|
| 1 | +package acceptance |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +var grantsTemplate = ` |
| 9 | +resource "databricks_catalog" "sandbox" { |
| 10 | + name = "sandbox{var.STICKY_RANDOM}" |
| 11 | + comment = "this catalog is managed by terraform" |
| 12 | + properties = { |
| 13 | + purpose = "testing" |
| 14 | + } |
| 15 | +} |
| 16 | +
|
| 17 | +resource "databricks_schema" "things" { |
| 18 | + catalog_name = databricks_catalog.sandbox.id |
| 19 | + name = "things{var.STICKY_RANDOM}" |
| 20 | + comment = "this database is managed by terraform" |
| 21 | + properties = { |
| 22 | + kind = "various" |
| 23 | + } |
| 24 | +} |
| 25 | +
|
| 26 | +resource "databricks_table" "mytable" { |
| 27 | + catalog_name = databricks_catalog.sandbox.id |
| 28 | + schema_name = databricks_schema.things.name |
| 29 | + name = "bar" |
| 30 | + table_type = "MANAGED" |
| 31 | + data_source_format = "DELTA" |
| 32 | + |
| 33 | + column { |
| 34 | + name = "id" |
| 35 | + position = 0 |
| 36 | + type_name = "INT" |
| 37 | + type_text = "int" |
| 38 | + type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}" |
| 39 | + } |
| 40 | +} |
| 41 | +
|
| 42 | +resource "databricks_storage_credential" "external" { |
| 43 | + name = "cred-{var.STICKY_RANDOM}" |
| 44 | + aws_iam_role { |
| 45 | + role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}" |
| 46 | + } |
| 47 | + comment = "Managed by TF" |
| 48 | +} |
| 49 | +
|
| 50 | +resource "databricks_external_location" "some" { |
| 51 | + name = "external-{var.STICKY_RANDOM}" |
| 52 | + url = "s3://{env.TEST_BUCKET}/some{var.STICKY_RANDOM}" |
| 53 | + credential_name = databricks_storage_credential.external.id |
| 54 | + comment = "Managed by TF" |
| 55 | +} |
| 56 | + |
| 57 | +resource "databricks_grants" "metastore" { |
| 58 | + metastore = "{env.TEST_METASTORE_ID}" |
| 59 | + grant { |
| 60 | + principal = "%s" |
| 61 | + privileges = ["CREATE_STORAGE_CREDENTIAL"] |
| 62 | + } |
| 63 | +} |
| 64 | +
|
| 65 | +resource "databricks_grants" "catalog" { |
| 66 | + catalog = databricks_catalog.sandbox.id |
| 67 | + grant { |
| 68 | + principal = "%s" |
| 69 | + privileges = ["ALL_PRIVILEGES"] |
| 70 | + } |
| 71 | +} |
| 72 | +
|
| 73 | +resource "databricks_grants" "schema" { |
| 74 | + schema = databricks_schema.things.id |
| 75 | + grant { |
| 76 | + principal = "%s" |
| 77 | + privileges = ["ALL_PRIVILEGES"] |
| 78 | + } |
| 79 | +} |
| 80 | +
|
| 81 | +resource "databricks_grants" "table" { |
| 82 | + table = databricks_table.mytable.id |
| 83 | + grant { |
| 84 | + principal = "%s" |
| 85 | + privileges = ["ALL_PRIVILEGES"] |
| 86 | + } |
| 87 | +} |
| 88 | +
|
| 89 | +resource "databricks_grants" "cred" { |
| 90 | + storage_credential = databricks_storage_credential.external.id |
| 91 | + grant { |
| 92 | + principal = "%s" |
| 93 | + privileges = ["ALL_PRIVILEGES"] |
| 94 | + } |
| 95 | +} |
| 96 | +
|
| 97 | +resource "databricks_grants" "some" { |
| 98 | + external_location = databricks_external_location.some.id |
| 99 | + grant { |
| 100 | + principal = "%s" |
| 101 | + privileges = ["ALL_PRIVILEGES"] |
| 102 | + } |
| 103 | +}` |
| 104 | + |
| 105 | +func TestUcAccGrants(t *testing.T) { |
| 106 | + unityWorkspaceLevel(t, step{ |
| 107 | + Template: strings.ReplaceAll(grantsTemplate, "%s", "{env.TEST_DATA_ENG_GROUP}"), |
| 108 | + }, |
| 109 | + step{ |
| 110 | + Template: strings.ReplaceAll(grantsTemplate, "%s", "{env.TEST_DATA_SCI_GROUP}"), |
| 111 | + }) |
| 112 | +} |
0 commit comments