Skip to content

Commit cb42fdc

Browse files
authored
Added initial Unity Catalog integration tests (#1592)
Added some coverage for: * `databricks_grants` * `databricks_schemas` * `databricks_schema` * `databricks_catalogs` * `databricks_catalog` * `databricks_external_location` * `databricks_storage_credential` * `databricks_metastore_assignment` * `databricks_metastore_data_access` * `databricks_metastore`
1 parent a508761 commit cb42fdc

File tree

8 files changed

+171
-15
lines changed

8 files changed

+171
-15
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package acceptance
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
7+
"github.com/databricks/terraform-provider-databricks/qa"
8+
)
9+
10+
func TestUcAccExternalLocation(t *testing.T) {
11+
qa.RequireCloudEnv(t, "ucws")
12+
acceptance.Test(t, []acceptance.Step{
13+
{
14+
Template: `
15+
resource "databricks_storage_credential" "external" {
16+
name = "cred-{var.RANDOM}"
17+
aws_iam_role {
18+
role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}"
19+
}
20+
comment = "Managed by TF"
21+
}
22+
23+
resource "databricks_external_location" "some" {
24+
name = "external"
25+
url = "s3://{env.TEST_BUCKET}/some{var.RANDOM}"
26+
credential_name = databricks_storage_credential.external.id
27+
comment = "Managed by TF"
28+
}
29+
30+
resource "databricks_grants" "some" {
31+
external_location = databricks_external_location.some.id
32+
grant {
33+
principal = "{env.TEST_DATA_ENG_GROUP}"
34+
privileges = ["CREATE_TABLE", "READ_FILES"]
35+
}
36+
}`,
37+
},
38+
})
39+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package acceptance
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
7+
"github.com/databricks/terraform-provider-databricks/qa"
8+
)
9+
10+
func TestUcAccMetastoreAssignment(t *testing.T) {
11+
qa.RequireCloudEnv(t, "ucws")
12+
acceptance.Test(t, []acceptance.Step{
13+
{
14+
Template: `resource "databricks_metastore_assignment" "this" {
15+
metastore_id = "{env.TEST_METASTORE_ID}"
16+
workspace_id = {env.TEST_WORKSPACE_ID}
17+
}`,
18+
},
19+
})
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package acceptance
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
7+
"github.com/databricks/terraform-provider-databricks/qa"
8+
)
9+
10+
func TestUcAccMetastoreDataAccessOnAws(t *testing.T) {
11+
qa.RequireCloudEnv(t, "ucws")
12+
acceptance.Test(t, []acceptance.Step{
13+
{
14+
Template: `
15+
resource "databricks_metastore" "this" {
16+
name = "primary"
17+
storage_root = "s3://{env.TEST_BUCKET}/test{var.RANDOM}"
18+
force_destroy = true
19+
}
20+
21+
resource "databricks_metastore_data_access" "this" {
22+
metastore_id = databricks_metastore.this.id
23+
name = "{var.RANDOM}"
24+
aws_iam_role {
25+
role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}"
26+
}
27+
is_default = true
28+
}`,
29+
},
30+
})
31+
}

catalog/acceptance/mws_recipient_test.go renamed to catalog/acceptance/recipient_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/databricks/terraform-provider-databricks/qa"
88
)
99

10-
func TestAccCreateRecipientDb2Open(t *testing.T) {
11-
qa.RequireCloudEnv(t, "aws-uc-prod")
10+
func TestUcAccCreateRecipientDb2Open(t *testing.T) {
11+
qa.RequireCloudEnv(t, "ucws")
1212
acceptance.Test(t, []acceptance.Step{
1313
{
1414
Template: `
@@ -18,25 +18,29 @@ func TestAccCreateRecipientDb2Open(t *testing.T) {
1818
authentication_type = "TOKEN"
1919
sharing_code = "{var.RANDOM}"
2020
ip_access_list {
21-
allowed_ip_addresses = ["10.0.0.0/16"] // using private ip for acc testing
21+
// using private ip for acc testing
22+
allowed_ip_addresses = ["10.0.0.0/16"]
2223
}
2324
}`,
2425
},
2526
})
2627
}
2728

28-
func TestAccCreateRecipientDb2DbAws(t *testing.T) {
29-
qa.RequireCloudEnv(t, "aws-uc-prod")
29+
func TestUcAccCreateRecipientDb2DbAws(t *testing.T) {
30+
qa.RequireCloudEnv(t, "ucws")
3031
acceptance.Test(t, []acceptance.Step{
3132
{
3233
Template: `
3334
resource "databricks_metastore" "recipient_metastore" {
3435
name = "{var.RANDOM}-terraform-recipient-metastore"
35-
storage_root = format("s3a://%s/%s", "{var.RANDOM}", "{var.RANDOM}")
36+
storage_root = "s3://{env.TEST_BUCKET}/test{var.RANDOM}"
3637
delta_sharing_scope = "INTERNAL"
3738
delta_sharing_recipient_token_lifetime_in_seconds = "60000"
3839
force_destroy = true
39-
lifecycle { ignore_changes = [storage_root] } // fake storage root is causing issues
40+
lifecycle {
41+
// fake storage root is causing issues
42+
ignore_changes = [storage_root]
43+
}
4044
}
4145
4246
resource "databricks_recipient" "db2db" {

catalog/acceptance/schema_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package acceptance
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
7+
"github.com/databricks/terraform-provider-databricks/qa"
8+
)
9+
10+
func TestUcAccSchema(t *testing.T) {
11+
qa.RequireCloudEnv(t, "ucws")
12+
acceptance.Test(t, []acceptance.Step{
13+
{
14+
Template: `
15+
resource "databricks_catalog" "sandbox" {
16+
name = "sandbox{var.RANDOM}"
17+
comment = "this catalog is managed by terraform"
18+
properties = {
19+
purpose = "testing"
20+
}
21+
}
22+
23+
data "databricks_catalogs" "all" {
24+
depends_on = [databricks_catalog.sandbox]
25+
}
26+
27+
resource "databricks_grants" "sandbox" {
28+
catalog = databricks_catalog.sandbox.name
29+
grant {
30+
principal = "{env.TEST_DATA_SCI_GROUP}"
31+
privileges = ["USAGE", "CREATE"]
32+
}
33+
grant {
34+
principal = "{env.TEST_DATA_ENG_GROUP}"
35+
privileges = ["USAGE"]
36+
}
37+
}
38+
39+
resource "databricks_schema" "things" {
40+
catalog_name = databricks_catalog.sandbox.id
41+
name = "things{var.RANDOM}"
42+
comment = "this database is managed by terraform"
43+
properties = {
44+
kind = "various"
45+
}
46+
}
47+
48+
data "databricks_schemas" "sandbox" {
49+
catalog_name = databricks_catalog.sandbox.id
50+
depends_on = [databricks_schema.things]
51+
}
52+
53+
resource "databricks_grants" "things" {
54+
schema = databricks_schema.things.id
55+
grant {
56+
principal = "{env.TEST_DATA_ENG_GROUP}"
57+
privileges = ["USAGE"]
58+
}
59+
}`,
60+
},
61+
})
62+
}

catalog/resource_metastore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type MetastoreInfo struct {
3333
CreatedBy string `json:"created_by,omitempty" tf:"computed"`
3434
UpdatedAt int64 `json:"updated_at,omitempty" tf:"computed"`
3535
UpdatedBy string `json:"updated_by,omitempty" tf:"computed"`
36-
DeltaSharingScope string `json:"delta_sharing_scope,omitempty"`
36+
DeltaSharingScope string `json:"delta_sharing_scope,omitempty" tf:"suppress_diff"`
3737
DeltaSharingRecipientTokenLifetimeInSeconds int64 `json:"delta_sharing_recipient_token_lifetime_in_seconds,omitempty"`
3838
DeltaSharingOrganizationName string `json:"delta_sharing_organization_name,omitempty"`
3939
}

internal/acceptance/acceptance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Test(t *testing.T, steps []Step, otherVars ...map[string]string) {
4949
awsAttrs = "aws_attributes {}"
5050
}
5151
instancePoolID := ""
52-
if cloudEnv != "MWS" && cloudEnv != "gcp-accounts" && !strings.HasPrefix(cloudEnv, "unity-catalog-") {
52+
if cloudEnv != "MWS" && cloudEnv != "gcp-accounts" && !strings.HasPrefix(cloudEnv, "uc") {
5353
// TODO: replace this with data resource
5454
instancePoolID = compute.CommonInstancePoolID()
5555
}

mws/acceptance/mws_permissionassignments_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import (
77
"github.com/databricks/terraform-provider-databricks/qa"
88
)
99

10-
func TestAccAssignGroupToWorkspace(t *testing.T) {
11-
qa.RequireCloudEnv(t, "unity-catalog-account")
10+
func TestUcAccAssignGroupToWorkspace(t *testing.T) {
11+
qa.RequireCloudEnv(t, "ucacct")
1212
acceptance.Test(t, []acceptance.Step{
1313
{
1414
Template: `
1515
resource "databricks_group" "this" {
1616
display_name = "TF {var.RANDOM}"
1717
}
1818
resource "databricks_mws_permission_assignment" "this" {
19-
workspace_id = {env.TEST_UC_WORKSPACE_ID}
19+
workspace_id = {env.TEST_WORKSPACE_ID}
2020
principal_id = databricks_group.this.id
2121
permissions = ["USER"]
2222
}`,
@@ -27,7 +27,7 @@ func TestAccAssignGroupToWorkspace(t *testing.T) {
2727
display_name = "TF {var.RANDOM}"
2828
}
2929
resource "databricks_mws_permission_assignment" "this" {
30-
workspace_id = {env.TEST_UC_WORKSPACE_ID}
30+
workspace_id = {env.TEST_WORKSPACE_ID}
3131
principal_id = databricks_group.this.id
3232
permissions = ["ADMIN"]
3333
}`,
@@ -38,7 +38,7 @@ func TestAccAssignGroupToWorkspace(t *testing.T) {
3838
display_name = "TF {var.RANDOM}"
3939
}
4040
resource "databricks_mws_permission_assignment" "this" {
41-
workspace_id = {env.TEST_UC_WORKSPACE_ID}
41+
workspace_id = {env.TEST_WORKSPACE_ID}
4242
principal_id = databricks_group.this.id
4343
permissions = ["USER"]
4444
}`,
@@ -55,7 +55,7 @@ func TestAccAssignSpnToWorkspace(t *testing.T) {
5555
display_name = "TF {var.RANDOM}"
5656
}
5757
resource "databricks_mws_permission_assignment" "this" {
58-
workspace_id = {env.TEST_UC_WORKSPACE_ID}
58+
workspace_id = {env.TEST_WORKSPACE_ID}
5959
principal_id = databricks_service_principal.this.id
6060
permissions = ["USER"]
6161
}`,

0 commit comments

Comments
 (0)