Skip to content
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

feat: Add snowflake grant ownership resource #2604

Merged
merged 15 commits into from
Mar 14, 2024
287 changes: 287 additions & 0 deletions docs/resources/grant_ownership.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "snowflake_grant_ownership Resource - terraform-provider-snowflake"
subcategory: ""
description: |-

---

~> **Note** This is a preview resource. It's ready for general use. In case of any errors, please file an issue in our GitHub repository.



!> **Warning** Be careful when using `always_apply` field. It will always produce a plan (even when no changes were made) and can be harmful in some setups. For more details why we decided to introduce it to go our document explaining those design decisions (coming soon).

# snowflake_grant_ownership (Resource)



## Example Usage

```terraform
##################################
### on object to account role
##################################

resource "snowflake_role" "test" {
name = "test_role"
}

resource "snowflake_database" "test" {
name = "test_database"
}

resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
}

resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
outbound_privileges = "COPY"
on {
object_type = "SCHEMA"
object_name = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}

##################################
### on object to database role
##################################

resource "snowflake_database" "test" {
name = "test_database"
}

resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
}

resource "snowflake_database_role" "test" {
name = "test_database_role"
database = snowflake_database.test.name
}

resource "snowflake_grant_ownership" "test" {
database_role_name = "\"${snowflake_database_role.test.database}\".\"${snowflake_database_role.test.name}\""
outbound_privileges = "REVOKE"
on {
object_type = "SCHEMA"
object_name = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}

##################################
### on all tables in database to account role
##################################

resource "snowflake_role" "test" {
name = "test_role"
}

resource "snowflake_database" "test" {
name = "test_database"
}

resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
on {
all {
plural_object_type = "TABLES"
in_database = snowflake_database.test.name
}
}
}

##################################
### on all tables in schema to account role
##################################

resource "snowflake_role" "test" {
name = "test_role"
}

resource "snowflake_database" "test" {
name = "test_database"
}

resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
}

resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
on {
all {
plural_object_type = "TABLES"
in_schema = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}
}

##################################
### on future tables in database to account role
##################################

resource "snowflake_role" "test" {
name = "test_role"
}

resource "snowflake_database" "test" {
name = "test_database"
}

resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
on {
future {
plural_object_type = "TABLES"
in_database = snowflake_database.test.name
}
}
}

##################################
### on future tables in schema to account role
##################################

resource "snowflake_role" "test" {
name = "test_role"
}

resource "snowflake_database" "test" {
name = "test_database"
}

resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
}

resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
on {
future {
plural_object_type = "TABLES"
in_schema = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `on` (Block List, Min: 1, Max: 1) Configures which object(s) should transfer their ownership to the specified role. (see [below for nested schema](#nestedblock--on))

### Optional

- `account_role_name` (String) The fully qualified name of the account role to which privileges will be granted.
- `database_role_name` (String) The fully qualified name of the database role to which privileges will be granted.
- `outbound_privileges` (String) Specifies whether to remove or transfer all existing outbound privileges on the object when ownership is transferred to a new role. Available options are: REVOKE for removing existing privileges and COPY to transfer them with ownership.
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--on"></a>
### Nested Schema for `on`

Optional:

- `all` (Block List, Max: 1) Configures the privilege to be granted on all objects in either a database or schema. (see [below for nested schema](#nestedblock--on--all))
- `future` (Block List, Max: 1) Configures the privilege to be granted on all objects in either a database or schema. (see [below for nested schema](#nestedblock--on--future))
- `object_name` (String) Specifies the identifier for the object on which you are transferring ownership.
- `object_type` (String) Specifies the type of object on which you are transferring ownership. Available values are: AGGREGATION POLICY | ALERT | AUTHENTICATION POLICY | COMPUTE POOL | DATABASE | DATABASE ROLE | DYNAMIC TABLE | EVENT TABLE | EXTERNAL TABLE | EXTERNAL VOLUME | FAILOVER GROUP | FILE FORMAT | FUNCTION | HYBRID TABLE | ICEBERG TABLE | IMAGE REPOSITORY | INTEGRATION | MATERIALIZED VIEW | NETWORK POLICY | NETWORK RULE | PACKAGES POLICY | PIPE | PROCEDURE | MASKING POLICY | PASSWORD POLICY | PROJECTION POLICY | REPLICATION GROUP | ROLE | ROW ACCESS POLICY | SCHEMA | SESSION POLICY | SECRET | SEQUENCE | STAGE | STREAM | TABLE | TAG | TASK | USER | VIEW | WAREHOUSE

<a id="nestedblock--on--all"></a>
### Nested Schema for `on.all`

Required:

- `object_type_plural` (String) Specifies the type of object in plural form on which you are transferring ownership. Available values are: AGGREGATION POLICIES | ALERTS | AUTHENTICATION POLICIES | COMPUTE POOLS | DATABASES | DATABASE ROLES | DYNAMIC TABLES | EVENT TABLES | EXTERNAL TABLES | EXTERNAL VOLUMES | FAILOVER GROUPS | FILE FORMATS | FUNCTIONS | HYBRID TABLES | ICEBERG TABLES | IMAGE REPOSITORIES | INTEGRATIONS | MATERIALIZED VIEWS | NETWORK POLICIES | NETWORK RULES | PACKAGES POLICIES | PIPES | PROCEDURES | MASKING POLICIES | PASSWORD POLICIES | PROJECTION POLICIES | REPLICATION GROUPS | ROLES | ROW ACCESS POLICIES | SCHEMAS | SESSION POLICIES | SECRETS | SEQUENCES | STAGES | STREAMS | TABLES | TAGS | TASKS | USERS | VIEWS | WAREHOUSES

Optional:

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


<a id="nestedblock--on--future"></a>
### Nested Schema for `on.future`

Required:

- `object_type_plural` (String) Specifies the type of object in plural form on which you are transferring ownership. Available values are: AGGREGATION POLICIES | ALERTS | AUTHENTICATION POLICIES | COMPUTE POOLS | DATABASES | DATABASE ROLES | DYNAMIC TABLES | EVENT TABLES | EXTERNAL TABLES | EXTERNAL VOLUMES | FAILOVER GROUPS | FILE FORMATS | FUNCTIONS | HYBRID TABLES | ICEBERG TABLES | IMAGE REPOSITORIES | INTEGRATIONS | MATERIALIZED VIEWS | NETWORK POLICIES | NETWORK RULES | PACKAGES POLICIES | PIPES | PROCEDURES | MASKING POLICIES | PASSWORD POLICIES | PROJECTION POLICIES | REPLICATION GROUPS | ROLES | ROW ACCESS POLICIES | SCHEMAS | SESSION POLICIES | SECRETS | SEQUENCES | STAGES | STREAMS | TABLES | TAGS | TASKS | USERS | VIEWS | WAREHOUSES

Optional:

- `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 (where every part is quoted), e.g. for schema object it is `"<database_name>"."<schema_name>"."<object_name>"`

Import is supported using the following syntax:

`terraform import "<role_type>|<role_identifier>|<outbound_privileges_behavior>|<grant_type>|<grant_data>"`

where:
- role_type - string - type of granted role (either ToAccountRole or ToDatabaseRole)
- role_name - string - fully qualified identifier for either account role or database role (depending on the role_type)
- outbound_privileges_behavior - string - behavior specified for existing roles (can be either COPY or REVOKE)
- grant_type - enum
- grant_data - data dependent on grant_type

It has varying number of parts, depending on grant_type. All the possible types are:

### OnObject
`terraform import "<role_type>|<role_identifier>|<outbound_privileges_behavior>|OnObject|<object_type>|<object_name>"`

### OnAll

OnAll contains inner types for all options.

#### InDatabase
`terraform import "<role_type>|<role_identifier>|<outbound_privileges_behavior>|OnAll|<plural_object_type>|InDatabase|<database_name>"`

#### InSchema
`terraform import "<role_type>|<role_identifier>|<outbound_privileges_behavior>|OnAll|<plural_object_type>|InSchema|<schema_name>"`

### OnAll

OnFuture contains inner types for all options.

#### InDatabase
`terraform import "<role_type>|<role_identifier>|<outbound_privileges_behavior>|OnFuture|<plural_object_type>|InDatabase|<database_name>"`

#### InSchema
`terraform import "<role_type>|<role_identifier>|<outbound_privileges_behavior>|OnFuture|<plural_object_type>|InSchema|<schema_name>"`

### Import examples

#### OnObject on Schema ToAccountRole
`terraform import "ToAccountRole|\"account_role\"|COPY|OnObject|SCHEMA|\"database_name\".\"schema_name\""`

#### OnObject on Schema ToDatabaseRole
`terraform import "ToDatabaseRole|\"database_name\".\"database_role_name\"|COPY|OnObject|SCHEMA|\"database_name\".\"schema_name\""`

#### OnObject on Table
`terraform import "ToAccountRole|\"account_role\"|COPY|OnObject|TABLE|\"database_name\".\"schema_name\".\"table_name\""`

#### OnAll InDatabase
`terraform import "ToAccountRole|\"account_role\"|REVOKE|OnAll|TABLES|InDatabase|\"database_name\""`

#### OnAll InSchema
`terraform import "ToAccountRole|\"account_role\"||OnAll|TABLES|InSchema|\"database_name\".\"schema_name\""`

#### OnFuture InDatabase
`terraform import "ToAccountRole|\"account_role\"||OnFuture|TABLES|InDatabase|\"database_name\""`

#### OnFuture InSchema
`terraform import "ToAccountRole|\"account_role\"|COPY|OnFuture|TABLES|InSchema|\"database_name\".\"schema_name\""`
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) TODO
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
- `in_schema` (String) TODO


<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) TODO
- `in_schema` (String) TODO

## 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
Loading