-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Internal] Migrate Share Resource to Plugin Framework #4047
Merged
rauchy
merged 12 commits into
main
from
rauchy/migrate-share-resource-to-plugin-framework
Oct 29, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
52325e6
[Internal] CRUD operations for plugin framework's version of the Shar…
rauchy 8bdcf00
fix failing integration test
rauchy 7e1e37c
simplify variable names
rauchy 68ce58f
use effective fields
rauchy 9a42a81
add some diagnostics checks
rauchy 6761603
rename acceptance test file to match contribution guide
rauchy f4cb006
use GetDatabricksStagingName for resource name
rauchy a40043e
addressed some PR comments
rauchy 559b1f9
copy over effective fields from existing state during read operation
rauchy 54fe63a
support adding objects anywhere in the list + integration test for th…
rauchy 3cc7c62
remove redundant log
rauchy 52c62e3
set user agent in resource context
rauchy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
internal/providers/pluginfw/resources/sharing/resource_acc_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package sharing_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/databricks/terraform-provider-databricks/internal/acceptance" | ||
) | ||
|
||
const preTestTemplate = ` | ||
resource "databricks_catalog" "sandbox" { | ||
name = "sandbox{var.STICKY_RANDOM}" | ||
comment = "this catalog is managed by terraform" | ||
properties = { | ||
purpose = "testing" | ||
} | ||
} | ||
|
||
resource "databricks_schema" "things" { | ||
catalog_name = databricks_catalog.sandbox.id | ||
name = "things{var.STICKY_RANDOM}" | ||
comment = "this database is managed by terraform" | ||
properties = { | ||
kind = "various" | ||
} | ||
} | ||
|
||
resource "databricks_table" "mytable" { | ||
catalog_name = databricks_catalog.sandbox.id | ||
schema_name = databricks_schema.things.name | ||
name = "bar" | ||
table_type = "MANAGED" | ||
data_source_format = "DELTA" | ||
|
||
column { | ||
name = "id" | ||
position = 0 | ||
type_name = "INT" | ||
type_text = "int" | ||
type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}" | ||
} | ||
} | ||
|
||
resource "databricks_table" "mytable_2" { | ||
catalog_name = databricks_catalog.sandbox.id | ||
schema_name = databricks_schema.things.name | ||
name = "bar_2" | ||
table_type = "MANAGED" | ||
data_source_format = "DELTA" | ||
|
||
column { | ||
name = "id" | ||
position = 0 | ||
type_name = "INT" | ||
type_text = "int" | ||
type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}" | ||
} | ||
} | ||
|
||
resource "databricks_table" "mytable_3" { | ||
catalog_name = databricks_catalog.sandbox.id | ||
schema_name = databricks_schema.things.name | ||
name = "bar_3" | ||
table_type = "MANAGED" | ||
data_source_format = "DELTA" | ||
|
||
column { | ||
name = "id" | ||
position = 0 | ||
type_name = "INT" | ||
type_text = "int" | ||
type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}" | ||
} | ||
} | ||
` | ||
|
||
const preTestTemplateUpdate = ` | ||
resource "databricks_grants" "some" { | ||
catalog = databricks_catalog.sandbox.id | ||
grant { | ||
principal = "account users" | ||
privileges = ["ALL_PRIVILEGES"] | ||
} | ||
grant { | ||
principal = "{env.TEST_METASTORE_ADMIN_GROUP_NAME}" | ||
privileges = ["ALL_PRIVILEGES"] | ||
} | ||
} | ||
` | ||
|
||
func TestUcAccCreateShare(t *testing.T) { | ||
acceptance.UnityWorkspaceLevel(t, acceptance.Step{ | ||
Template: preTestTemplate + ` | ||
resource "databricks_share_pluginframework" "myshare" { | ||
name = "{var.STICKY_RANDOM}-terraform-delta-share" | ||
owner = "account users" | ||
object { | ||
name = databricks_table.mytable.id | ||
comment = "c" | ||
data_object_type = "TABLE" | ||
} | ||
object { | ||
name = databricks_table.mytable_2.id | ||
cdf_enabled = false | ||
comment = "c" | ||
data_object_type = "TABLE" | ||
} | ||
} | ||
|
||
resource "databricks_recipient" "db2open" { | ||
name = "{var.STICKY_RANDOM}-terraform-db2open-recipient" | ||
comment = "made by terraform" | ||
authentication_type = "TOKEN" | ||
sharing_code = "{var.STICKY_RANDOM}" | ||
ip_access_list { | ||
// using private ip for acc testing | ||
allowed_ip_addresses = ["10.0.0.0/16"] | ||
} | ||
} | ||
|
||
resource "databricks_grants" "some" { | ||
share = databricks_share_pluginframework.myshare.name | ||
grant { | ||
principal = databricks_recipient.db2open.name | ||
privileges = ["SELECT"] | ||
} | ||
} | ||
`, | ||
}) | ||
} | ||
|
||
func shareTemplateWithOwner(comment string, owner string) string { | ||
return fmt.Sprintf(` | ||
resource "databricks_share_pluginframework" "myshare" { | ||
name = "{var.STICKY_RANDOM}-terraform-delta-share" | ||
owner = "%s" | ||
object { | ||
name = databricks_table.mytable.id | ||
comment = "%s" | ||
data_object_type = "TABLE" | ||
history_data_sharing_status = "DISABLED" | ||
} | ||
|
||
}`, owner, comment) | ||
} | ||
|
||
func TestUcAccUpdateShare(t *testing.T) { | ||
acceptance.UnityWorkspaceLevel(t, acceptance.Step{ | ||
Template: preTestTemplate + preTestTemplateUpdate + shareTemplateWithOwner("c", "account users"), | ||
}, acceptance.Step{ | ||
Template: preTestTemplate + preTestTemplateUpdate + shareTemplateWithOwner("e", "account users"), | ||
}, acceptance.Step{ | ||
Template: preTestTemplate + preTestTemplateUpdate + shareTemplateWithOwner("e", "{env.TEST_DATA_ENG_GROUP}"), | ||
}, acceptance.Step{ | ||
Template: preTestTemplate + preTestTemplateUpdate + shareTemplateWithOwner("f", "{env.TEST_METASTORE_ADMIN_GROUP_NAME}"), | ||
}) | ||
} | ||
|
||
func TestUcAccUpdateShareAddObject(t *testing.T) { | ||
acceptance.UnityWorkspaceLevel(t, acceptance.Step{ | ||
Template: preTestTemplate + preTestTemplateUpdate + | ||
`resource "databricks_share_pluginframework" "myshare" { | ||
name = "{var.STICKY_RANDOM}-terraform-delta-share" | ||
owner = "account users" | ||
object { | ||
name = databricks_table.mytable.id | ||
comment = "A" | ||
data_object_type = "TABLE" | ||
history_data_sharing_status = "DISABLED" | ||
} | ||
object { | ||
name = databricks_table.mytable_3.id | ||
comment = "C" | ||
data_object_type = "TABLE" | ||
history_data_sharing_status = "DISABLED" | ||
} | ||
|
||
}`, | ||
}, acceptance.Step{ | ||
Template: preTestTemplate + preTestTemplateUpdate + | ||
`resource "databricks_share_pluginframework" "myshare" { | ||
name = "{var.STICKY_RANDOM}-terraform-delta-share" | ||
owner = "account users" | ||
object { | ||
name = databricks_table.mytable.id | ||
comment = "AA" | ||
data_object_type = "TABLE" | ||
history_data_sharing_status = "DISABLED" | ||
} | ||
object { | ||
name = databricks_table.mytable_2.id | ||
comment = "BB" | ||
data_object_type = "TABLE" | ||
history_data_sharing_status = "DISABLED" | ||
} | ||
object { | ||
name = databricks_table.mytable_3.id | ||
comment = "CC" | ||
data_object_type = "TABLE" | ||
history_data_sharing_status = "DISABLED" | ||
} | ||
}`, | ||
}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add an integration test which adds an object in middle in the update step? This was a limitation in SDKv2 as ordering used to matter whereas now it should work with plugin framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would fail currently because object in ShareInfo that we use for schema is a list and it should be set instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Added support + integration test in 4b7eb0e