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 support for table column comments and to control a tables data retention and change tracking settings #614

Merged

Conversation

robbruce
Copy link
Contributor

Adds the following options to the table resource

  • comments on columns
  • property to control DATA_RETENTION_TIME_IN_DAYS on a table
  • property to control CHANGE_TRACKING on a table

Test Plan

  • acceptance tests
$ TF_ACC=1 go test -v ./... -run TestAcc_Table
?   	github.com/chanzuckerberg/terraform-provider-snowflake	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/datasources	(cached) [no tests to run]
?   	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/db	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/provider	(cached) [no tests to run]
=== RUN   TestAcc_Table
=== PAUSE TestAcc_Table
=== CONT  TestAcc_Table
--- PASS: TestAcc_Table (57.92s)
PASS
ok  	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/resources	58.328s
testing: warning: no tests to run
PASS
ok  	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/snowflake	(cached) [no tests to run]
?   	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/testhelpers	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/validation	(cached) [no tests to run]
?   	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/version	[no test files]

References

  • None

@robbruce robbruce requested a review from a team as a code owner July 22, 2021 12:43
@robbruce robbruce requested a review from alldoami July 22, 2021 12:43
@robbruce robbruce changed the title Add support for table column comments and to control a tables data retention and change tracking settings feat: Add support for table column comments and to control a tables data retention and change tracking settings Jul 22, 2021
"data_retention_days": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this default value overwrite the inherited value from a higher level object? I believe the default behavior in snowflake is to inherit from the "higher object". For example, if I were to set data_retention_days=20 for my schema, I'd expect that to be inherited by the table. This seems like it might break that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think since the variable is called data_retention_time_in_days we should also name it that here. https://docs.snowflake.com/en/sql-reference/parameters.html#data-retention-time-in-days

It does look like the Default value is 1 in the docs though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More context
If a retention period is specified for a database or schema, the period is inherited by default for all objects created in the database/schema

from https://docs.snowflake.com/en/user-guide/data-time-travel.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alldoami @berosen - I really wasn't sure what to use as snowflake_schema has data_retention_days and snowflake_database has data_retention_time_in_days so there's inconsistencies already.

https://github.com/chanzuckerberg/terraform-provider-snowflake/blob/main/pkg/resources/schema.go#L54
https://github.com/chanzuckerberg/terraform-provider-snowflake/blob/main/pkg/resources/database.go#L25

@berosen - yes you're right it will override the default from a parent object, I could change this so that if its nil then the setting is not applied to the table if that's more suitable. Which in the case of using this provider, it will be the schema as that has the logic I have here, e.g. it defaults to 1, rather than defaults to inherit.

@alldoami - I can change the behaviour of the snowflake_schema resource too, but obviously that will have some side effects for existing deployments. I have no idea why on the database the value is computed though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robbruce , personally I like the idea of using nil. I feel the change would be more in-line with expected behaviour. I think making the change in snowflake_schema would be a good idea as well. However, I'll defer to whatever @alldoami feels is best.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@berosen - I have been looking into this, and I'm not sure its possible with how the current typing system works for schema.TypeInt - see hashicorp/terraform-plugin-sdk#261

Essentially , if I set Default to be nil, then the SDK returns this as 0 and so there doesn't appear to be a nice way to inherit.

In addition, when reading a table with SHOW TABLES, then even if the value was not supplied (so it inherits) then it returns the value defined in it's parent schema, so even then there is no way to detect if there is a difference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I see your reasoning now with the naming @robbruce.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robbruce That's a good point, I think the work around for that would be complicated. Maybe it's enough to write a note in the description that the inheritance needs to be explicitly defined by passing the same value as the parent object? ie

snowflake_table foo {
   ...
   data_retention_days=snowflake_schema.name. data_retention_days
}

Sorry for the noise all!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@berosen @alldoami - updated the description as suggested and the table example too.

@alldoami
Copy link
Contributor

/ok-to-test sha=b75a091

@github-actions
Copy link

Integration tests success for b75a091

@alldoami
Copy link
Contributor

/ok-to-test sha=5eb437d

@github-actions
Copy link

Integration tests failure for 5eb437d

@alldoami
Copy link
Contributor

/ok-to-test sha=5d770a1

@github-actions
Copy link

Integration tests failure for 5d770a1

@robbruce
Copy link
Contributor Author

@alldoami - what needs to be done to sort out the integration-trusted test?

@alldoami
Copy link
Contributor

alldoami commented Jul 26, 2021

@robbruce
Copy link
Contributor Author

@alldoami
Copy link
Contributor

/ok-to-test sha=05e036d

@github-actions
Copy link

Integration tests failure for 05e036d

@alldoami
Copy link
Contributor

/ok-to-test sha=f2adee7

@github-actions
Copy link

Integration tests success for f2adee7

Copy link
Contributor

@alldoami alldoami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo! Nice

@alldoami alldoami merged commit daa46a0 into Snowflake-Labs:main Jul 28, 2021
@robbruce robbruce deleted the f/table_resource_enhancements branch July 28, 2021 07:46
jtzero pushed a commit to rxrevu/terraform-provider-snowflake that referenced this pull request Aug 19, 2021
anton-chekanov pushed a commit to anton-chekanov/terraform-provider-snowflake that referenced this pull request Jan 25, 2022
daniepett pushed a commit to daniepett/terraform-provider-snowflake that referenced this pull request Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants