Skip to content

Commit

Permalink
feat: Add snowflake grant ownership resource (#2604)
Browse files Browse the repository at this point in the history
The first part of the implementation of the `snowflake_grant_ownership`
resource. This is a "basic" version of this resource providing baseline
functionalities needed to transfer ownership in Terraform. In the next
pull request, I'll add all of the edge cases we have to cover (most of
them are described
[here](https://docs.snowflake.com/en/sql-reference/sql/grant-ownership#usage-notes)).

Changes made:
- Created a new `snowflake_grant_ownership` resource with CRUD
operations implemented (still there are TODOs left for discussion)
- Added examples and documentation needed for the resource and its
identifier

Things to do before the merge:
- remove `snowflake_grant_ownership` from the provider.go

TODO in the next pr(s):
- Add deprecation messages to old grant resources specifically made for
granting ownership
- Add edge cases and test them (and if needed describe them in the
documentation and add examples)
- Add `setId("")` in read and forcefully grant ownership in Create
operation
- Referring to
[comment](#2604 (comment)),
test different cases where the Delete operation may struggle with
- Test outside of Terraform interactions to see how it behaves in
different situations

## Test Plan
* [x] acceptance tests
* [x] unit tests for the resource identifier conversions from/to String
representation
* [x] unit tests for the helper functions needed by resource CRUD
operations

## References
* [GRANT
OWNERSHIP](https://docs.snowflake.com/en/sql-reference/sql/grant-ownership)

## Mentioned in
A list of issues requesting this resource (a big probability there's
more); notify after part 2 will be done.
- #2549
- #2199
- #2084
- #1942
- #1875
  • Loading branch information
sfc-gh-jcieslak authored Mar 14, 2024
1 parent 538b6dc commit bfadd24
Show file tree
Hide file tree
Showing 42 changed files with 3,312 additions and 176 deletions.
2 changes: 1 addition & 1 deletion docs/resources/grant_privileges_to_account_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Optional:

## Import

~> **Note** All the ..._name parts should be fully qualified names, e.g. for schema object it is `"<database_name>"."<schema_name>"."<object_name>"`
~> **Note** All the ..._name parts should be fully qualified names (where every part is quoted), e.g. for schema object it is `"<database_name>"."<schema_name>"."<object_name>"`
~> **Note** To import all_privileges write ALL or ALL PRIVILEGES in place of `<privileges>`

Import is supported using the following syntax:
Expand Down
10 changes: 5 additions & 5 deletions docs/resources/grant_privileges_to_database_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ Required:

Optional:

- `in_database` (String)
- `in_schema` (String)
- `in_database` (String) The fully qualified name of the database.
- `in_schema` (String) The fully qualified name of the schema.


<a id="nestedblock--on_schema_object--future"></a>
Expand All @@ -230,12 +230,12 @@ Required:

Optional:

- `in_database` (String)
- `in_schema` (String)
- `in_database` (String) The fully qualified name of the database.
- `in_schema` (String) The fully qualified name of the schema.

## Import

~> **Note** All the ..._name parts should be fully qualified names, e.g. for database object it is `"<database_name>"."<object_name>"`
~> **Note** All the ..._name parts should be fully qualified names (where every part is quoted), e.g. for database object it is `"<database_name>"."<object_name>"`
~> **Note** To import all_privileges write ALL or ALL PRIVILEGES in place of `<privileges>`

Import is supported using the following syntax:
Expand Down
2 changes: 1 addition & 1 deletion docs/technical-documentation/resource_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ resource "snowflake_grant_privileges_to_account_role" "new_resource" {
depends_on = [snowflake_database.test, snowflake_role.a, snowflake_role.b]
for_each = toset([snowflake_role.a.name, snowflake_role.b.name])
privileges = ["USAGE"]
role_name = each.key
account_role_name = each.key
on_account_object {
object_type = "DATABASE"
object_name = snowflake_database.test.name
Expand Down
Loading

0 comments on commit bfadd24

Please sign in to comment.