Skip to content

Commit

Permalink
Added initial Unity Catalog integration tests (#1592)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
nfx authored Sep 9, 2022
1 parent a508761 commit cb42fdc
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 15 deletions.
39 changes: 39 additions & 0 deletions catalog/acceptance/external_location_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package acceptance

import (
"testing"

"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/databricks/terraform-provider-databricks/qa"
)

func TestUcAccExternalLocation(t *testing.T) {
qa.RequireCloudEnv(t, "ucws")
acceptance.Test(t, []acceptance.Step{
{
Template: `
resource "databricks_storage_credential" "external" {
name = "cred-{var.RANDOM}"
aws_iam_role {
role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}"
}
comment = "Managed by TF"
}
resource "databricks_external_location" "some" {
name = "external"
url = "s3://{env.TEST_BUCKET}/some{var.RANDOM}"
credential_name = databricks_storage_credential.external.id
comment = "Managed by TF"
}
resource "databricks_grants" "some" {
external_location = databricks_external_location.some.id
grant {
principal = "{env.TEST_DATA_ENG_GROUP}"
privileges = ["CREATE_TABLE", "READ_FILES"]
}
}`,
},
})
}
20 changes: 20 additions & 0 deletions catalog/acceptance/metastore_assignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package acceptance

import (
"testing"

"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/databricks/terraform-provider-databricks/qa"
)

func TestUcAccMetastoreAssignment(t *testing.T) {
qa.RequireCloudEnv(t, "ucws")
acceptance.Test(t, []acceptance.Step{
{
Template: `resource "databricks_metastore_assignment" "this" {
metastore_id = "{env.TEST_METASTORE_ID}"
workspace_id = {env.TEST_WORKSPACE_ID}
}`,
},
})
}
31 changes: 31 additions & 0 deletions catalog/acceptance/metastore_data_access_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package acceptance

import (
"testing"

"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/databricks/terraform-provider-databricks/qa"
)

func TestUcAccMetastoreDataAccessOnAws(t *testing.T) {
qa.RequireCloudEnv(t, "ucws")
acceptance.Test(t, []acceptance.Step{
{
Template: `
resource "databricks_metastore" "this" {
name = "primary"
storage_root = "s3://{env.TEST_BUCKET}/test{var.RANDOM}"
force_destroy = true
}
resource "databricks_metastore_data_access" "this" {
metastore_id = databricks_metastore.this.id
name = "{var.RANDOM}"
aws_iam_role {
role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}"
}
is_default = true
}`,
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/databricks/terraform-provider-databricks/qa"
)

func TestAccCreateRecipientDb2Open(t *testing.T) {
qa.RequireCloudEnv(t, "aws-uc-prod")
func TestUcAccCreateRecipientDb2Open(t *testing.T) {
qa.RequireCloudEnv(t, "ucws")
acceptance.Test(t, []acceptance.Step{
{
Template: `
Expand All @@ -18,25 +18,29 @@ func TestAccCreateRecipientDb2Open(t *testing.T) {
authentication_type = "TOKEN"
sharing_code = "{var.RANDOM}"
ip_access_list {
allowed_ip_addresses = ["10.0.0.0/16"] // using private ip for acc testing
// using private ip for acc testing
allowed_ip_addresses = ["10.0.0.0/16"]
}
}`,
},
})
}

func TestAccCreateRecipientDb2DbAws(t *testing.T) {
qa.RequireCloudEnv(t, "aws-uc-prod")
func TestUcAccCreateRecipientDb2DbAws(t *testing.T) {
qa.RequireCloudEnv(t, "ucws")
acceptance.Test(t, []acceptance.Step{
{
Template: `
resource "databricks_metastore" "recipient_metastore" {
name = "{var.RANDOM}-terraform-recipient-metastore"
storage_root = format("s3a://%s/%s", "{var.RANDOM}", "{var.RANDOM}")
storage_root = "s3://{env.TEST_BUCKET}/test{var.RANDOM}"
delta_sharing_scope = "INTERNAL"
delta_sharing_recipient_token_lifetime_in_seconds = "60000"
force_destroy = true
lifecycle { ignore_changes = [storage_root] } // fake storage root is causing issues
lifecycle {
// fake storage root is causing issues
ignore_changes = [storage_root]
}
}
resource "databricks_recipient" "db2db" {
Expand Down
62 changes: 62 additions & 0 deletions catalog/acceptance/schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package acceptance

import (
"testing"

"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/databricks/terraform-provider-databricks/qa"
)

func TestUcAccSchema(t *testing.T) {
qa.RequireCloudEnv(t, "ucws")
acceptance.Test(t, []acceptance.Step{
{
Template: `
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.RANDOM}"
comment = "this catalog is managed by terraform"
properties = {
purpose = "testing"
}
}
data "databricks_catalogs" "all" {
depends_on = [databricks_catalog.sandbox]
}
resource "databricks_grants" "sandbox" {
catalog = databricks_catalog.sandbox.name
grant {
principal = "{env.TEST_DATA_SCI_GROUP}"
privileges = ["USAGE", "CREATE"]
}
grant {
principal = "{env.TEST_DATA_ENG_GROUP}"
privileges = ["USAGE"]
}
}
resource "databricks_schema" "things" {
catalog_name = databricks_catalog.sandbox.id
name = "things{var.RANDOM}"
comment = "this database is managed by terraform"
properties = {
kind = "various"
}
}
data "databricks_schemas" "sandbox" {
catalog_name = databricks_catalog.sandbox.id
depends_on = [databricks_schema.things]
}
resource "databricks_grants" "things" {
schema = databricks_schema.things.id
grant {
principal = "{env.TEST_DATA_ENG_GROUP}"
privileges = ["USAGE"]
}
}`,
},
})
}
2 changes: 1 addition & 1 deletion catalog/resource_metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type MetastoreInfo struct {
CreatedBy string `json:"created_by,omitempty" tf:"computed"`
UpdatedAt int64 `json:"updated_at,omitempty" tf:"computed"`
UpdatedBy string `json:"updated_by,omitempty" tf:"computed"`
DeltaSharingScope string `json:"delta_sharing_scope,omitempty"`
DeltaSharingScope string `json:"delta_sharing_scope,omitempty" tf:"suppress_diff"`
DeltaSharingRecipientTokenLifetimeInSeconds int64 `json:"delta_sharing_recipient_token_lifetime_in_seconds,omitempty"`
DeltaSharingOrganizationName string `json:"delta_sharing_organization_name,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Test(t *testing.T, steps []Step, otherVars ...map[string]string) {
awsAttrs = "aws_attributes {}"
}
instancePoolID := ""
if cloudEnv != "MWS" && cloudEnv != "gcp-accounts" && !strings.HasPrefix(cloudEnv, "unity-catalog-") {
if cloudEnv != "MWS" && cloudEnv != "gcp-accounts" && !strings.HasPrefix(cloudEnv, "uc") {
// TODO: replace this with data resource
instancePoolID = compute.CommonInstancePoolID()
}
Expand Down
12 changes: 6 additions & 6 deletions mws/acceptance/mws_permissionassignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"github.com/databricks/terraform-provider-databricks/qa"
)

func TestAccAssignGroupToWorkspace(t *testing.T) {
qa.RequireCloudEnv(t, "unity-catalog-account")
func TestUcAccAssignGroupToWorkspace(t *testing.T) {
qa.RequireCloudEnv(t, "ucacct")
acceptance.Test(t, []acceptance.Step{
{
Template: `
resource "databricks_group" "this" {
display_name = "TF {var.RANDOM}"
}
resource "databricks_mws_permission_assignment" "this" {
workspace_id = {env.TEST_UC_WORKSPACE_ID}
workspace_id = {env.TEST_WORKSPACE_ID}
principal_id = databricks_group.this.id
permissions = ["USER"]
}`,
Expand All @@ -27,7 +27,7 @@ func TestAccAssignGroupToWorkspace(t *testing.T) {
display_name = "TF {var.RANDOM}"
}
resource "databricks_mws_permission_assignment" "this" {
workspace_id = {env.TEST_UC_WORKSPACE_ID}
workspace_id = {env.TEST_WORKSPACE_ID}
principal_id = databricks_group.this.id
permissions = ["ADMIN"]
}`,
Expand All @@ -38,7 +38,7 @@ func TestAccAssignGroupToWorkspace(t *testing.T) {
display_name = "TF {var.RANDOM}"
}
resource "databricks_mws_permission_assignment" "this" {
workspace_id = {env.TEST_UC_WORKSPACE_ID}
workspace_id = {env.TEST_WORKSPACE_ID}
principal_id = databricks_group.this.id
permissions = ["USER"]
}`,
Expand All @@ -55,7 +55,7 @@ func TestAccAssignSpnToWorkspace(t *testing.T) {
display_name = "TF {var.RANDOM}"
}
resource "databricks_mws_permission_assignment" "this" {
workspace_id = {env.TEST_UC_WORKSPACE_ID}
workspace_id = {env.TEST_WORKSPACE_ID}
principal_id = databricks_service_principal.this.id
permissions = ["USER"]
}`,
Expand Down

0 comments on commit cb42fdc

Please sign in to comment.