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

fix: linting errors #1432

Merged
merged 11 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions docs/data-sources/current_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,15 @@ description: |-
# snowflake_current_role (Data Source)


## Example Usage

```terraform
data "snowflake_current_role" "this" {}

resource "aws_ssm_parameter" "snowflake_account_role" {
name = "/snowflake/account_role"
type = "String"
value = data.snowflake_current_account.this.name
}
```


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

### Read-Only

- `name` (String)
- `id` (String) The ID of this resource.
- `name` (String) The name of the [primary role](https://docs.snowflake.com/en/user-guide/security-access-control-overview.html#label-access-control-role-enforcement) in use for the current session.


64 changes: 51 additions & 13 deletions docs/resources/object_parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,49 @@ resource "snowflake_database" "d" {
name = "TEST_DB"
}

resource "snowflake_schema" "s" {
name = "TEST_SCHEMA"
database = snowflake_database.d.name
}

resource "snowflake_object_parameter" "o" {
key = "ENABLE_STREAM_TASK_REPLICATION"
value = "true"
key = "SUSPEND_TASK_AFTER_NUM_FAILURES"
value = "33"
object_type = "DATABASE"
object_name = snowflake_database.d.name
object_identifier {
name = snowflake_database.d.name
}
}

resource "snowflake_schema" "s" {
name = "TEST_SCHEMA"
database = snowflake_database.d.name
}

resource "snowflake_object_parameter" "o2" {
key = "PIPE_EXECUTION_PAUSED"
value = "false"
key = "USER_TASK_TIMEOUT_MS"
value = "500"
object_type = "SCHEMA"
object_name = "${snowflake_database.d.name}.${snowflake_schema.s.name}"
object_identifier {
database = snowflake_database.d.name
name = snowflake_schema.s.name
}
}

resource "snowflake_table" "t" {
name = "TEST_TABLE"
database = snowflake_database.d.name
schema = snowflake_schema.s.name
column {
name = "id"
type = "NUMBER"
}
}

resource "snowflake_object_parameter" "o3" {
key = "DATA_RETENTION_TIME_IN_DAYS"
value = "89"
object_type = "TABLE"
object_identifier {
database = snowflake_database.d.name
schema = snowflake_schema.s.name
name = snowflake_table.t.name
}
}
```

Expand All @@ -43,18 +69,30 @@ resource "snowflake_object_parameter" "o2" {
### Required

- `key` (String) Name of object parameter. Valid values are those in [object parameters](https://docs.snowflake.com/en/sql-reference/parameters.html#object-parameters).
- `object_name` (String) Name of object to which the parameter applies.
- `object_identifier` (Block List, Min: 1) Specifies the object identifier for the object parameter. (see [below for nested schema](#nestedblock--object_identifier))
- `object_type` (String) Type of object to which the parameter applies. Valid values are those in [object types](https://docs.snowflake.com/en/sql-reference/parameters.html#object-types).
- `value` (String) Value of object parameter, as a string. Constraints are the same as those for the parameters in Snowflake documentation.

### Read-Only

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

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

Required:

- `name` (String) Name of the object to set the parameter for.

Optional:

- `database` (String) Name of the database that the object was created in.
- `schema` (String) Name of the schema that the object was created in.

## Import

Import is supported using the following syntax:

```shell
terraform import snowflake_object_parameter.s <key>❄️<object_type>❄️<object_name>
terraform import snowflake_object_parameter.s <key>❄️<object_type>❄️<object_identifier>
```
2 changes: 1 addition & 1 deletion docs/resources/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ resource "snowflake_table" "table" {
- `change_tracking` (Boolean) Specifies whether to enable change tracking on the table. Default false.
- `cluster_by` (List of String) A list of one or more table columns/expressions to be used as clustering key(s) for the table
- `comment` (String) Specifies a comment for the table.
- `data_retention_days` (Number) Specifies the retention period for the table so that Time Travel actions (SELECT, CLONE, UNDROP) can be performed on historical data in the table. Default value is 1, if you wish to inherit the parent schema setting then pass in the schema attribute to this argument.
- `data_retention_days` (Number, Deprecated) Specifies the retention period for the table so that Time Travel actions (SELECT, CLONE, UNDROP) can be performed on historical data in the table. Default value is 1, if you wish to inherit the parent schema setting then pass in the schema attribute to this argument.
- `primary_key` (Block List, Max: 1, Deprecated) Definitions of primary key constraint to create on table (see [below for nested schema](#nestedblock--primary_key))
- `tag` (Block List, Deprecated) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

Expand Down
13 changes: 13 additions & 0 deletions docs/resources/view_grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ resource "snowflake_view_grant" "grant" {
on_future = false
with_grant_option = false
}

/*
Snowflake view grant is an object level grant, not a schema level grant. To add schema level
grants, use the `snowflake_schema_grant` resource
*/

resource "snowflake_schema_grant" "grant" {
database_name = "database"
schema_name = "schema"

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

<!-- schema generated by tfplugindocs -->
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/snowflake_object_parameter/import.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import snowflake_object_parameter.s <key>❄️<object_type>❄️<object_name>
terraform import snowflake_object_parameter.s <key>❄️<object_type>❄️<object_identifier>
48 changes: 37 additions & 11 deletions examples/resources/snowflake_object_parameter/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,47 @@ resource "snowflake_database" "d" {
name = "TEST_DB"
}

resource "snowflake_schema" "s" {
name = "TEST_SCHEMA"
database = snowflake_database.d.name
}

resource "snowflake_object_parameter" "o" {
key = "ENABLE_STREAM_TASK_REPLICATION"
value = "true"
key = "SUSPEND_TASK_AFTER_NUM_FAILURES"
value = "33"
object_type = "DATABASE"
object_name = snowflake_database.d.name
object_identifier {
name = snowflake_database.d.name
}
}

resource "snowflake_schema" "s" {
name = "TEST_SCHEMA"
database = snowflake_database.d.name
}

resource "snowflake_object_parameter" "o2" {
key = "PIPE_EXECUTION_PAUSED"
value = "false"
key = "USER_TASK_TIMEOUT_MS"
value = "500"
object_type = "SCHEMA"
object_name = "${snowflake_database.d.name}.${snowflake_schema.s.name}"
object_identifier {
database = snowflake_database.d.name
name = snowflake_schema.s.name
}
}

resource "snowflake_table" "t" {
name = "TEST_TABLE"
database = snowflake_database.d.name
schema = snowflake_schema.s.name
column {
name = "id"
type = "NUMBER"
}
}

resource "snowflake_object_parameter" "o3" {
key = "DATA_RETENTION_TIME_IN_DAYS"
value = "89"
object_type = "TABLE"
object_identifier {
database = snowflake_database.d.name
schema = snowflake_schema.s.name
name = snowflake_table.t.name
}
}
13 changes: 13 additions & 0 deletions examples/resources/snowflake_view_grant/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,16 @@ resource "snowflake_view_grant" "grant" {
on_future = false
with_grant_option = false
}

/*
Snowflake view grant is an object level grant, not a schema level grant. To add schema level
grants, use the `snowflake_schema_grant` resource
*/

resource "snowflake_schema_grant" "grant" {
database_name = "database"
schema_name = "schema"

privilege = "USAGE"
roles = ["role1", "role2"]
}
11 changes: 6 additions & 5 deletions pkg/datasources/current_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

var currentRoleSchema = map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Description: "The name of the [primary role](https://docs.snowflake.com/en/user-guide/security-access-control-overview.html#label-access-control-role-enforcement) in use for the current session.",
},
}
Expand All @@ -27,15 +27,16 @@ func CurrentRole() *schema.Resource {
func ReadCurrentRole(d *schema.ResourceData, meta interface{}) error {
db := meta.(*sql.DB)
role, err := snowflake.ReadCurrentRole(db)

if err != nil {
log.Printf("[DEBUG] current_role failed to decode")
d.SetId("")
return nil
}

d.SetId(fmt.Sprintf(role.Role))
d.Set("name", role.Role)

err = d.Set("name", role.Role)
if err != nil {
return err
}
return nil
}
45 changes: 22 additions & 23 deletions pkg/datasources/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,30 @@ func ReadParameters(d *schema.ResourceData, meta interface{}) error {
params = append(params, paramMap)
}
return d.Set("parameters", params)
} else {
parameters, err := snowflake.ListParameters(db, parameterType, pattern)
if errors.Is(err, sql.ErrNoRows) {
log.Printf("[DEBUG] parameters not found")
d.SetId("")
return nil
} else if err != nil {
log.Printf("[DEBUG] error occurred during read: %v", err.Error())
return err
}
d.SetId("parameters")
}
parameters, err := snowflake.ListParameters(db, parameterType, pattern)
if errors.Is(err, sql.ErrNoRows) {
log.Printf("[DEBUG] parameters not found")
d.SetId("")
return nil
} else if err != nil {
log.Printf("[DEBUG] error occurred during read: %v", err.Error())
return err
}
d.SetId("parameters")

params := []map[string]interface{}{}
for _, param := range parameters {
paramMap := map[string]interface{}{}
params := []map[string]interface{}{}
for _, param := range parameters {
paramMap := map[string]interface{}{}

paramMap["key"] = param.Key.String
paramMap["value"] = param.Value.String
paramMap["default"] = param.Default.String
paramMap["level"] = param.Level.String
paramMap["description"] = param.Description.String
paramMap["type"] = param.PType.String
paramMap["key"] = param.Key.String
paramMap["value"] = param.Value.String
paramMap["default"] = param.Default.String
paramMap["level"] = param.Level.String
paramMap["description"] = param.Description.String
paramMap["type"] = param.PType.String

params = append(params, paramMap)
}
return d.Set("parameters", params)
params = append(params, paramMap)
}
return d.Set("parameters", params)
}
6 changes: 3 additions & 3 deletions pkg/resources/account_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var accountParameterSchema = map[string]*schema.Schema{
Required: true,
ForceNew: true,
Description: "Name of account parameter. Valid values are those in [account parameters](https://docs.snowflake.com/en/sql-reference/parameters.html#account-parameters).",
ValidateFunc: validation.StringInSlice(maps.Keys(snowflake.GetParameters(snowflake.ParameterTypeAccount)), false),
ValidateFunc: validation.StringInSlice(maps.Keys(snowflake.GetParameterDefaults(snowflake.ParameterTypeAccount)), false),
},
"value": {
Type: schema.TypeString,
Expand Down Expand Up @@ -46,7 +46,7 @@ func CreateAccountParameter(d *schema.ResourceData, meta interface{}) error {
key := d.Get("key").(string)
value := d.Get("value").(string)

parameterDefault := snowflake.GetParameters(snowflake.ParameterTypeAccount)[key]
parameterDefault := snowflake.GetParameterDefaults(snowflake.ParameterTypeAccount)[key]
if parameterDefault.Validate != nil {
if err := parameterDefault.Validate(value); err != nil {
return err
Expand Down Expand Up @@ -102,7 +102,7 @@ func DeleteAccountParameter(d *schema.ResourceData, meta interface{}) error {
db := meta.(*sql.DB)
key := d.Get("key").(string)

parameterDefault := snowflake.GetParameters(snowflake.ParameterTypeAccount)[key]
parameterDefault := snowflake.GetParameterDefaults(snowflake.ParameterTypeAccount)[key]
defaultValue := parameterDefault.DefaultValue
value := fmt.Sprintf("%v", defaultValue)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ func expandStringList(configured []interface{}) []string {
}
return vs
}

func expandObjectIdentifier(objectIdentifier interface{}) (string, string, string) {
objectIdentifierMap := objectIdentifier.([]interface{})[0].(map[string]interface{})
objectName := objectIdentifierMap["name"].(string)
var objectSchema string
if v := objectIdentifierMap["schema"]; v != nil {
objectSchema = v.(string)
}
var objectDatabase string
if v := objectIdentifierMap["database"]; v != nil {
objectDatabase = v.(string)
}
return objectDatabase, objectSchema, objectName
}
Loading