Skip to content

Commit

Permalink
fix: procedure and function grants (#1502)
Browse files Browse the repository at this point in the history
* fix: procedure and function grants

* fix: procedure and function grants

* fix: procedure and function grants

* update tests

* update tests

* update tests

* update tests
  • Loading branch information
sfc-gh-swinkler authored Jan 31, 2023
1 parent 9a5fc2c commit 0d08ea8
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 640 deletions.
37 changes: 13 additions & 24 deletions docs/resources/function_grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,15 @@ description: |-

```terraform
resource "snowflake_function_grant" "grant" {
database_name = "database"
schema_name = "schema"
function_name = "function"
arguments {
name = "a"
type = "array"
}
arguments {
name = "b"
type = "string"
}
return_type = "string"
privilege = "USAGE"
roles = ["role1", "role2"]
shares = ["share1", "share2"]
on_future = false
with_grant_option = false
database_name = "database"
schema_name = "schema"
function_name = "function"
argument_data_types = ["array", "string"]
privilege = "USAGE"
roles = ["role1", "role2"]
shares = ["share1", "share2"]
on_future = false
with_grant_option = false
}
```

Expand All @@ -48,12 +36,13 @@ resource "snowflake_function_grant" "grant" {

### Optional

- `arguments` (Block List) List of the arguments for the function (must be present if function has arguments and function_name is present) (see [below for nested schema](#nestedblock--arguments))
- `argument_data_types` (List of String) List of the argument data types for the function (must be present if function has arguments and function_name is present)
- `arguments` (Block List, Deprecated) List of the arguments for the function (must be present if function has arguments and function_name is present) (see [below for nested schema](#nestedblock--arguments))
- `enable_multiple_grants` (Boolean) When this is set to true, multiple grants of the same type can be created. This will cause Terraform to not revoke grants applied to roles and objects outside Terraform.
- `function_name` (String) The name of the function on which to grant privileges immediately (only valid if on_future is false).
- `on_future` (Boolean) When this is set to true and a schema_name is provided, apply this grant on all future functions in the given schema. When this is true and no schema_name is provided apply this grant on all future functions in the given database. The function_name, arguments, return_type, and shares fields must be unset in order to use on_future.
- `privilege` (String) The privilege to grant on the current or future function. Must be one of `USAGE` or `OWNERSHIP`.
- `return_type` (String) The return type of the function (must be present if function_name is present)
- `return_type` (String, Deprecated) The return type of the function (must be present if function_name is present)
- `schema_name` (String) The name of the schema containing the current or future functions on which to grant privileges.
- `shares` (Set of String) Grants privilege to these shares (only valid if on_future is false).
- `with_grant_option` (Boolean) When this is set to true, allows the recipient role to grant the privileges to other roles.
Expand All @@ -76,5 +65,5 @@ Import is supported using the following syntax:

```shell
# format is database name | schema name | function signature | privilege | true/false for with_grant_option
terraform import snowflake_function_grant.example 'dbName|schemaName|functionName(ARG1 ARG1TYPE, ARG2 ARG2TYPE):RETURNTYPE|USAGE|false'
terraform import snowflake_function_grant.example 'dbName|schemaName|functionName(ARG1TYPE,ARG2TYPE)|USAGE|false'
```
37 changes: 13 additions & 24 deletions docs/resources/procedure_grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,15 @@ description: |-

```terraform
resource "snowflake_procedure_grant" "grant" {
database_name = "database"
schema_name = "schema"
procedure_name = "procedure"
arguments {
name = "a"
type = "array"
}
arguments {
name = "b"
type = "string"
}
return_type = "string"
privilege = "SELECT"
roles = ["role1", "role2"]
shares = ["share1", "share2"]
on_future = false
with_grant_option = false
database_name = "database"
schema_name = "schema"
procedure_name = "procedure"
argument_data_types = ["array", "string"]
privilege = "SELECT"
roles = ["role1", "role2"]
shares = ["share1", "share2"]
on_future = false
with_grant_option = false
}
```

Expand All @@ -48,12 +36,13 @@ resource "snowflake_procedure_grant" "grant" {

### Optional

- `arguments` (Block List) List of the arguments for the procedure (must be present if procedure has arguments and procedure_name is present) (see [below for nested schema](#nestedblock--arguments))
- `argument_data_types` (List of String) List of the argument data types for the procedure (must be present if procedure has arguments and procedure_name is present)
- `arguments` (Block List, Deprecated) List of the arguments for the procedure (must be present if procedure has arguments and procedure_name is present) (see [below for nested schema](#nestedblock--arguments))
- `enable_multiple_grants` (Boolean) When this is set to true, multiple grants of the same type can be created. This will cause Terraform to not revoke grants applied to roles and objects outside Terraform.
- `on_future` (Boolean) When this is set to true and a schema_name is provided, apply this grant on all future procedures in the given schema. When this is true and no schema_name is provided apply this grant on all future procedures in the given database. The procedure_name and shares fields must be unset in order to use on_future.
- `privilege` (String) The privilege to grant on the current or future procedure.
- `procedure_name` (String) The name of the procedure on which to grant privileges immediately (only valid if on_future is false).
- `return_type` (String) The return type of the procedure (must be present if procedure_name is present)
- `return_type` (String, Deprecated) The return type of the procedure (must be present if procedure_name is present)
- `schema_name` (String) The name of the schema containing the current or future procedures on which to grant privileges.
- `shares` (Set of String) Grants privilege to these shares (only valid if on_future is false).
- `with_grant_option` (Boolean) When this is set to true, allows the recipient role to grant the privileges to other roles.
Expand All @@ -76,5 +65,5 @@ Import is supported using the following syntax:

```shell
# format is database name | schema name | procedure signature | privilege | true/false for with_grant_option
terraform import snowflake_procedure_grant.example 'dbName|schemaName|procedureName(ARG1 ARG1TYPE, ARG2 ARG2TYPE):RETURNTYPE|USAGE|false'
terraform import snowflake_procedure_grant.example 'dbName|schemaName|procedureName(ARG1TYPE,ARG2TYPE)|USAGE|false'
```
2 changes: 1 addition & 1 deletion examples/resources/snowflake_function_grant/import.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# format is database name | schema name | function signature | privilege | true/false for with_grant_option
terraform import snowflake_function_grant.example 'dbName|schemaName|functionName(ARG1 ARG1TYPE, ARG2 ARG2TYPE):RETURNTYPE|USAGE|false'
terraform import snowflake_function_grant.example 'dbName|schemaName|functionName(ARG1TYPE,ARG2TYPE)|USAGE|false'
30 changes: 9 additions & 21 deletions examples/resources/snowflake_function_grant/resource.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
resource "snowflake_function_grant" "grant" {
database_name = "database"
schema_name = "schema"
function_name = "function"

arguments {
name = "a"
type = "array"
}
arguments {
name = "b"
type = "string"
}
return_type = "string"

privilege = "USAGE"
roles = ["role1", "role2"]

shares = ["share1", "share2"]

on_future = false
with_grant_option = false
database_name = "database"
schema_name = "schema"
function_name = "function"
argument_data_types = ["array", "string"]
privilege = "USAGE"
roles = ["role1", "role2"]
shares = ["share1", "share2"]
on_future = false
with_grant_option = false
}
2 changes: 1 addition & 1 deletion examples/resources/snowflake_procedure_grant/import.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# format is database name | schema name | procedure signature | privilege | true/false for with_grant_option
terraform import snowflake_procedure_grant.example 'dbName|schemaName|procedureName(ARG1 ARG1TYPE, ARG2 ARG2TYPE):RETURNTYPE|USAGE|false'
terraform import snowflake_procedure_grant.example 'dbName|schemaName|procedureName(ARG1TYPE,ARG2TYPE)|USAGE|false'
30 changes: 9 additions & 21 deletions examples/resources/snowflake_procedure_grant/resource.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
resource "snowflake_procedure_grant" "grant" {
database_name = "database"
schema_name = "schema"
procedure_name = "procedure"

arguments {
name = "a"
type = "array"
}
arguments {
name = "b"
type = "string"
}
return_type = "string"

privilege = "SELECT"
roles = ["role1", "role2"]

shares = ["share1", "share2"]

on_future = false
with_grant_option = false
database_name = "database"
schema_name = "schema"
procedure_name = "procedure"
argument_data_types = ["array", "string"]
privilege = "SELECT"
roles = ["role1", "role2"]
shares = ["share1", "share2"]
on_future = false
with_grant_option = false
}
Loading

0 comments on commit 0d08ea8

Please sign in to comment.