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: adding in tag support #713

Merged
merged 25 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
14 changes: 14 additions & 0 deletions docs/resources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ resource "snowflake_database" "test2" {
- **from_database** (String) Specify a database to create a clone from.
- **from_share** (Map of String) Specify a provider and a share in this map to create a database from a share.
- **id** (String) The ID of this resource.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Expand Down
15 changes: 15 additions & 0 deletions docs/resources/external_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ resource snowflake_external_table external_table {
- **partition_by** (List of String) Specifies any partition columns to evaluate for the external table.
- **pattern** (String) Specifies the file names and/or paths on the external stage to match.
- **refresh_on_create** (Boolean) Specifies weather to refresh when an external table is created.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

### Read-Only

Expand All @@ -67,6 +68,20 @@ Required:
- **name** (String) Column name
- **type** (String) Column type, e.g. VARIANT


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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Import is supported using the following syntax:
Expand Down
14 changes: 14 additions & 0 deletions docs/resources/materialized_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ SQL
- **id** (String) The ID of this resource.
- **is_secure** (Boolean) Specifies that the view is secure.
- **or_replace** (Boolean) Overwrites the View if it exists.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Expand Down
14 changes: 14 additions & 0 deletions docs/resources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ resource snowflake_role role {

- **comment** (String)
- **id** (String) The ID of this resource.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Expand Down
14 changes: 14 additions & 0 deletions docs/resources/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ resource snowflake_schema schema {
- **id** (String) The ID of this resource.
- **is_managed** (Boolean) Specifies a managed schema. Managed access schemas centralize privilege management with the schema owner.
- **is_transient** (Boolean) Specifies a schema as transient. Transient schemas do not have a Fail-safe period so they do not incur additional storage costs once they leave Time Travel; however, this means they are also not protected by Fail-safe in the event of a data loss.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Expand Down
14 changes: 14 additions & 0 deletions docs/resources/stage.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,22 @@ resource "snowflake_stage_grant" "grant_example_stage" {
- **id** (String) The ID of this resource.
- **snowflake_iam_user** (String)
- **storage_integration** (String) Specifies the name of the storage integration used to delegate authentication responsibility for external cloud storage to a Snowflake identity and access management (IAM) entity.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))
- **url** (String) Specifies the URL for the stage.

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Import is supported using the following syntax:
Expand Down
15 changes: 15 additions & 0 deletions docs/resources/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ resource "snowflake_table" "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.
- **id** (String) The ID of this resource.
- **primary_key** (Block List, Max: 1) Definitions of primary key constraint to create on table (see [below for nested schema](#nestedblock--primary_key))
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

### Read-Only

Expand Down Expand Up @@ -127,6 +128,20 @@ Optional:

- **name** (String) Name of constraint


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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Import is supported using the following syntax:
Expand Down
29 changes: 29 additions & 0 deletions docs/resources/tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "snowflake_tag Resource - terraform-provider-snowflake"
subcategory: ""
description: |-

---

# snowflake_tag (Resource)





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

### Required

- **database** (String) The database in which to create the tag.
- **name** (String) Specifies the identifier for the tag; must be unique for the database in which the tag is created.
- **schema** (String) The schema in which to create the tag.

### Optional

- **comment** (String) Specifies a comment for the tag.
- **id** (String) The ID of this resource.


14 changes: 14 additions & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,25 @@ resource snowflake_user user {
- **password** (String, Sensitive) **WARNING:** this will put the password in the terraform state file. Use carefully.
- **rsa_public_key** (String) Specifies the user’s RSA public key; used for key-pair authentication. Must be on 1 line without header and trailer.
- **rsa_public_key_2** (String) Specifies the user’s second RSA public key; used to rotate the public and private keys for key-pair authentication based on an expiration schedule set by your organization. Must be on 1 line without header and trailer.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

### Read-Only

- **has_rsa_public_key** (Boolean) Will be true if user as an RSA key set.

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Import is supported using the following syntax:
Expand Down
14 changes: 14 additions & 0 deletions docs/resources/view.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ SQL
- **id** (String) The ID of this resource.
- **is_secure** (Boolean) Specifies that the view is secure.
- **or_replace** (Boolean) Overwrites the View if it exists.
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Expand Down
14 changes: 14 additions & 0 deletions docs/resources/warehouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,23 @@ resource snowflake_warehouse w {
- **scaling_policy** (String) Specifies the policy for automatically starting and shutting down clusters in a multi-cluster warehouse running in Auto-scale mode.
- **statement_queued_timeout_in_seconds** (Number) Object parameter that specifies the time, in seconds, a SQL statement (query, DDL, DML, etc.) can be queued on a warehouse before it is canceled by the system.
- **statement_timeout_in_seconds** (Number) Specifies the time, in seconds, after which a running SQL statement (query, DDL, DML, etc.) is canceled by the system
- **tag** (Block List) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))
- **wait_for_provisioning** (Boolean) Specifies whether the warehouse, after being resized, waits for all the servers to provision before executing any queued or new queries.
- **warehouse_size** (String) Specifies the size of the virtual warehouse. Larger warehouse sizes 5X-Large and 6X-Large are currently in preview and only available on Amazon Web Services (AWS).

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

Required:

- **name** (String) Tag name, e.g. department.
- **value** (String) Tag value, e.g. marketing_info.

Optional:

- **database** (String) Name of the database that the tag was created in.
- **schema** (String) Name of the schema that the tag was created in.

## Import

Import is supported using the following syntax:
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func getResources() map[string]*schema.Resource {
"snowflake_stream": resources.Stream(),
"snowflake_table": resources.Table(),
"snowflake_external_table": resources.ExternalTable(),
"snowflake_tag": resources.Tag(),
"snowflake_task": resources.Task(),
"snowflake_user": resources.User(),
"snowflake_user_public_keys": resources.UserPublicKeys(),
Expand Down
Binary file removed pkg/resources/__debug_bin
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/resources/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var databaseSchema = map[string]*schema.Schema{
ForceNew: true,
ConflictsWith: []string{"from_share"},
},
"tag": tagReferenceSchema,
}

var databaseProperties = []string{"comment", "data_retention_time_in_days"}
Expand Down
6 changes: 6 additions & 0 deletions pkg/resources/external_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var externalTableSchema = map[string]*schema.Schema{
ForceNew: true,
Description: "Name of the role that owns the external table.",
},
"tag": tagReferenceSchema,
}

func ExternalTable() *schema.Resource {
Expand Down Expand Up @@ -233,6 +234,11 @@ func CreateExternalTable(data *schema.ResourceData, meta interface{}) error {
builder.WithComment(v.(string))
}

if v, ok := data.GetOk("tag"); ok {
tags := getTags(v)
builder.WithTags(tags.toSnowflakeTagValues())
}

stmt := builder.Create()
err := snowflake.Exec(db, stmt)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ func stream(t *testing.T, id string, params map[string]interface{}) *schema.Reso
return d
}

func tag(t *testing.T, id string, params map[string]interface{}) *schema.ResourceData {
r := require.New(t)
d := schema.TestResourceDataRaw(t, resources.Tag().Schema, params)
r.NotNil(d)
d.SetId(id)
return d
}

func providers() map[string]*schema.Provider {
p := provider.Provider()
return map[string]*schema.Provider{
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/materialized_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var materializedViewSchema = map[string]*schema.Schema{
ForceNew: true,
DiffSuppressFunc: DiffSuppressStatement,
},
"tag": tagReferenceSchema,
}

// View returns a pointer to the resource representing a view
Expand Down Expand Up @@ -152,6 +153,11 @@ func CreateMaterializedView(d *schema.ResourceData, meta interface{}) error {
builder.WithComment(v.(string))
}

if v, ok := d.GetOk("tag"); ok {
tags := getTags(v)
builder.WithTags(tags.toSnowflakeTagValues())
}

q := builder.Create()
log.Print("[DEBUG] xxx ", q)
err := snowflake.ExecMulti(db, q)
Expand Down Expand Up @@ -295,6 +301,8 @@ func UpdateMaterializedView(d *schema.ResourceData, meta interface{}) error {
}
}

handleTagChanges(db, d, builder)

return ReadMaterializedView(d, meta)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/resources/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func CreateResource(
case schema.TypeInt:
valInt := val.(int)
qb.SetInt(field, valInt)
case schema.TypeList:
tags, ok := val.([]snowflake.TagValue)
if !ok {
continue
}
qb.SetTags(tags)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var roleSchema = map[string]*schema.Schema{
Optional: true,
// TODO validation
},
"tag": tagReferenceSchema,
}

func Role() *schema.Resource {
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var schemaSchema = map[string]*schema.Schema{
Description: "Specifies the number of days for which Time Travel actions (CLONE and UNDROP) can be performed on the schema, as well as specifying the default Time Travel retention time for all tables created in the schema.",
ValidateFunc: validation.IntBetween(0, 90),
},
"tag": tagReferenceSchema,
}

type schemaID struct {
Expand Down Expand Up @@ -144,6 +145,11 @@ func CreateSchema(d *schema.ResourceData, meta interface{}) error {
builder.WithDataRetentionDays(v.(int))
}

if v, ok := d.GetOk("tag"); ok {
tags := getTags(v)
builder.WithTags(tags.toSnowflakeTagValues())
}

q := builder.Create()

err := snowflake.Exec(db, q)
Expand Down Expand Up @@ -300,6 +306,8 @@ func UpdateSchema(d *schema.ResourceData, meta interface{}) error {
}
}

handleTagChanges(db, d, builder)

return ReadSchema(d, meta)
}

Expand Down
Loading