diff --git a/docs/resources/database.md b/docs/resources/database.md index 745bf988d3..92bb9fabd4 100644 --- a/docs/resources/database.md +++ b/docs/resources/database.md @@ -55,7 +55,7 @@ resource "snowflake_database" "from_share" { ### Optional - `comment` (String) -- `data_retention_time_in_days` (Number) Number of days for which Snowflake retains historical data for performing Time Travel actions (SELECT, CLONE, UNDROP) on the object. A value of 0 effectively disables Time Travel for the specified database, schema, or table. For more information, see Understanding & Using Time Travel. +- `data_retention_time_in_days` (Number) Number of days for which Snowflake retains historical data for performing Time Travel actions (SELECT, CLONE, UNDROP) on the object. A value of 0 effectively disables Time Travel for the specified database. Default value for this field is set to -1, which is a fallback to use Snowflake default. For more information, see Understanding & Using Time Travel. - `from_database` (String) Specify a database to create a clone from. - `from_replica` (String) Specify a fully-qualified path to a database to create a replica from. A fully qualified path follows the format of "".""."". An example would be: "myorg1"."account1"."db1" - `from_share` (Map of String) Specify a provider and a share in this map to create a database from a share. diff --git a/docs/resources/table.md b/docs/resources/table.md index b78561a146..0a97906388 100644 --- a/docs/resources/table.md +++ b/docs/resources/table.md @@ -95,7 +95,7 @@ resource "snowflake_table" "table" { - `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, 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. -- `data_retention_time_in_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_time_in_days` (Number) Number of days for which Snowflake retains historical data for performing Time Travel actions (SELECT, CLONE, UNDROP) on the object. A value of 0 effectively disables Time Travel for the specified table. Default value for this field is set to -1, which is a fallback to use Snowflake default. For more information, see Understanding & Using Time Travel. - `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)) diff --git a/pkg/resources/database.go b/pkg/resources/database.go index 89d69c1448..5d4f3c2308 100644 --- a/pkg/resources/database.go +++ b/pkg/resources/database.go @@ -4,10 +4,11 @@ import ( "context" "database/sql" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "slices" "strconv" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) diff --git a/pkg/resources/table.go b/pkg/resources/table.go index 87849227c4..ec28f67213 100644 --- a/pkg/resources/table.go +++ b/pkg/resources/table.go @@ -583,7 +583,7 @@ func CreateTable(d *schema.ResourceData, meta interface{}) error { if v := d.Get("data_retention_time_in_days"); v.(int) != -1 { createRequest.WithDataRetentionTimeInDays(sdk.Int(v.(int))) } - //else if v, ok := d.GetOk("data_retention_days"); ok { // TODO: I would remove it + // else if v, ok := d.GetOk("data_retention_days"); ok { // TODO: I would remove it // createRequest.WithDataRetentionTimeInDays(sdk.Int(v.(int))) //} @@ -666,7 +666,7 @@ func ReadTable(d *schema.ResourceData, meta interface{}) error { if v := d.Get("data_retention_time_in_days"); v.(int) != -1 || int64(table.RetentionTime) != schemaRetentionTime { dataRetentionKey = "data_retention_time_in_days" } - //else if _, ok := d.GetOk("data_retention_days"); ok { // TODO: I would remove it + // else if _, ok := d.GetOk("data_retention_days"); ok { // TODO: I would remove it // dataRetentionKey = "data_retention_days" //} if dataRetentionKey != "" { @@ -724,7 +724,7 @@ func UpdateTable(d *schema.ResourceData, meta interface{}) error { setRequest.WithChangeTracking(sdk.Bool(changeTracking)) } - //if d.HasChange("data_retention_days") { // TODO: I would remove it + // if d.HasChange("data_retention_days") { // TODO: I would remove it // dataRetentionDays := d.Get("data_retention_days").(int) // runSetStatement = true // setRequest.WithDataRetentionTimeInDays(sdk.Int(dataRetentionDays)) diff --git a/pkg/resources/table_acceptance_test.go b/pkg/resources/table_acceptance_test.go index 23193d14a9..bddf11df9e 100644 --- a/pkg/resources/table_acceptance_test.go +++ b/pkg/resources/table_acceptance_test.go @@ -4,13 +4,14 @@ import ( "context" "database/sql" "fmt" - "github.com/hashicorp/terraform-plugin-testing/config" - "github.com/hashicorp/terraform-plugin-testing/plancheck" - "github.com/stretchr/testify/require" "strconv" "strings" "testing" + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/stretchr/testify/require" + acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" diff --git a/pkg/resources/testdata/TestAcc_Database_DefaultDataRetentionTime/WithoutDatabase/test.tf b/pkg/resources/testdata/TestAcc_Database_DefaultDataRetentionTime/WithoutDatabase/test.tf index 5616b3616f..410fd24e92 100644 --- a/pkg/resources/testdata/TestAcc_Database_DefaultDataRetentionTime/WithoutDatabase/test.tf +++ b/pkg/resources/testdata/TestAcc_Database_DefaultDataRetentionTime/WithoutDatabase/test.tf @@ -4,5 +4,5 @@ resource "snowflake_account_parameter" "test" { } resource "snowflake_database" "test" { - name = var.database + name = var.database } diff --git a/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithTable/test.tf b/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithTable/test.tf index 05b7ab162d..cf5c2831f0 100644 --- a/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithTable/test.tf +++ b/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithTable/test.tf @@ -1,14 +1,14 @@ resource "snowflake_schema" "test" { - database = var.database - name = var.schema + database = var.database + name = var.schema data_retention_days = var.schema_data_retention_time } resource "snowflake_table" "test" { - depends_on = [snowflake_schema.test] - database = var.database - schema = var.schema - name = var.table + depends_on = [snowflake_schema.test] + database = var.database + schema = var.schema + name = var.table data_retention_time_in_days = var.table_data_retention_time column { diff --git a/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithoutTable/test.tf b/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithoutTable/test.tf index d01176f703..038429961f 100644 --- a/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithoutTable/test.tf +++ b/pkg/resources/testdata/TestAcc_Table_DefaultDataRetentionTime/WithoutTable/test.tf @@ -1,14 +1,14 @@ resource "snowflake_schema" "test" { - database = var.database - name = var.schema + database = var.database + name = var.schema data_retention_days = var.schema_data_retention_time } resource "snowflake_table" "test" { depends_on = [snowflake_schema.test] - database = var.database + database = var.database schema = var.schema - name = var.table + name = var.table column { name = "id"