From 558725a15c8dab536ac6e56e08ee79f36c2d7fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Cie=C5=9Blak?= Date: Thu, 12 Dec 2024 10:33:28 +0100 Subject: [PATCH] changes after review --- MIGRATION_GUIDE.md | 12 +++--- docs/index.md | 2 +- docs/resources/execute.md | 37 ++++--------------- docs/resources/unsafe_execute.md | 4 +- examples/additional/deprecated_resources.MD | 2 +- .../resources/snowflake_execute/resource.tf | 27 +------------- pkg/resources/execute.go | 4 +- pkg/resources/unsafe_execute.go | 2 +- templates/resources/execute.md.tmpl | 2 +- templates/resources/unsafe_execute.md.tmpl | 2 +- 10 files changed, 24 insertions(+), 70 deletions(-) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index f1d8ce8bda..0df924a65f 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -9,13 +9,15 @@ across different versions. ## v0.99.0 ➞ v0.100.0 -### unsafe_execute resource changes / new execute resource +### unsafe_execute resource deprecation / new execute resource The `snowflake_unsafe_execute` gets deprecated in favor of the new resource `snowflake_execute`. -It will be removed before v1, so please migrate to the `snowflake_execute` resource. For no downtime migration, -follow our [guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md). -Remember that imported resource id has to be unique (using UUIDs is recommended) and because of the nature of the resource. -First apply after importing is necessary to "copy" values from the configuration to the state. +The `snowflake_execute` was build on top of `snowflake_unsafe_execute` with a few improvements. +The unsafe version will be removed with the v1 release, so please migrate to the `snowflake_execute` resource. + +For no downtime migration, follow our [guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md). +When importing, remember that the given resource id has to be unique (using UUIDs is recommended). +Also, because of the nature of the resource, first apply after importing is necessary to "copy" values from the configuration to the state. ### snowflake_account resource changes diff --git a/docs/index.md b/docs/index.md index c16d0fc98a..f04b4eb2b5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -367,7 +367,7 @@ provider "snowflake" { - [snowflake_saml_integration](./docs/resources/saml_integration) - use [snowflake_saml2_integration](./docs/resources/saml2_integration) instead - [snowflake_stream](./docs/resources/stream) - [snowflake_tag_masking_policy_association](./docs/resources/tag_masking_policy_association) -- [snowflake_unsafe_execute](./docs/resources/unsafe_execute) - use [snowflake_account_role](./docs/resources/account_role) instead +- [snowflake_unsafe_execute](./docs/resources/unsafe_execute) - use [snowflake_execute](./docs/resources/execute) instead ## Currently deprecated datasources diff --git a/docs/resources/execute.md b/docs/resources/execute.md index d261631ee6..ce4216323d 100644 --- a/docs/resources/execute.md +++ b/docs/resources/execute.md @@ -3,7 +3,7 @@ page_title: "snowflake_execute Resource - terraform-provider-snowflake" subcategory: "" description: |- - Resource allowing execution of ANY SQL statement. It may destroy resources if used incorrectly. It may behave incorrectly combined with other resources. Use at your own risk. + Resource allowing execution of ANY SQL statement. --- # snowflake_execute (Resource) @@ -14,7 +14,7 @@ description: |- ~> **Note** Use `query` parameter with caution. It will fetch **ALL** the results returned by the query provided. Try to limit the number of results by writing query with filters. Query failure does not stop resource creation; it simply results in `query_results` being empty. -Resource allowing execution of ANY SQL statement. It may destroy resources if used incorrectly. It may behave incorrectly combined with other resources. Use at your own risk. +Resource allowing execution of ANY SQL statement. ## Example Usage @@ -71,7 +71,7 @@ resource "snowflake_execute" "test" { ### fixing bad configuration ################################## -# bad revert - simple +# bad revert # 1 - resource created with a bad revert; it is constructed, revert is not validated before destroy happens resource "snowflake_execute" "test" { execute = "CREATE DATABASE ABC" @@ -84,31 +84,6 @@ resource "snowflake_execute" "test" { revert = "DROP DATABASE ABC" } -# bad revert - complex (we assume that the problem is spotted after trying to change the execute) -# 1 - resource created with a bad revert; it is constructed, revert is not validated before destroy happens -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE ABC" - revert = "SELECT 1" -} - -# 2 - try to create different database; it will fail on bad destroy -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE XYZ" - revert = "SELECT 1" -} - -# 3 - fix the revert first -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE ABC" - revert = "DROP DATABASE ABC" -} - -# 4 - create different database updating revert also -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE XYZ" - revert = "DROP DATABASE XYZ" -} - # bad query # 1 - resource will be created; query_results will be empty resource "snowflake_execute" "test" { @@ -137,7 +112,7 @@ resource "snowflake_execute" "test" { ### Optional -- `query` (String) Optional SQL statement to do a read. Invoked after creation and every time it is changed. +- `query` (String) Optional SQL statement to do a read. Invoked on every resource refresh and every time it is changed. ### Read-Only @@ -148,4 +123,6 @@ resource "snowflake_execute" "test" { Import is supported using the following syntax: -{{codefile "shell" "/Users/jcieslak/Documents/terraform-provider-snowflake/examples/resources/snowflake_execute/import.sh"}} +```shell +terraform import snowflake_execute.example '' +``` diff --git a/docs/resources/unsafe_execute.md b/docs/resources/unsafe_execute.md index 7c143c1e24..3ac9e7c7b6 100644 --- a/docs/resources/unsafe_execute.md +++ b/docs/resources/unsafe_execute.md @@ -14,7 +14,7 @@ description: |- ~> **Note** Use `query` parameter with caution. It will fetch **ALL** the results returned by the query provided. Try to limit the number of results by writing query with filters. Query failure does not stop resource creation; it simply results in `query_results` being empty. -~> **Deprecation** This resource is deprecated and will be removed in a future major version release. Please use [snowflake_account_role](./account_role) instead. +~> **Deprecation** This resource is deprecated and will be removed in a future major version release. Please use [snowflake_execute](./execute) instead. Experimental resource allowing execution of ANY SQL statement. It may destroy resources if used incorrectly. It may behave incorrectly combined with other resources. Use at your own risk. @@ -139,7 +139,7 @@ resource "snowflake_unsafe_execute" "test" { ### Optional -- `query` (String) Optional SQL statement to do a read. Invoked after creation and every time it is changed. +- `query` (String) Optional SQL statement to do a read. Invoked on every resource refresh and every time it is changed. ### Read-Only diff --git a/examples/additional/deprecated_resources.MD b/examples/additional/deprecated_resources.MD index 579b925945..b0a8941854 100644 --- a/examples/additional/deprecated_resources.MD +++ b/examples/additional/deprecated_resources.MD @@ -6,4 +6,4 @@ - [snowflake_saml_integration](./docs/resources/saml_integration) - use [snowflake_saml2_integration](./docs/resources/saml2_integration) instead - [snowflake_stream](./docs/resources/stream) - [snowflake_tag_masking_policy_association](./docs/resources/tag_masking_policy_association) -- [snowflake_unsafe_execute](./docs/resources/unsafe_execute) - use [snowflake_account_role](./docs/resources/account_role) instead +- [snowflake_unsafe_execute](./docs/resources/unsafe_execute) - use [snowflake_execute](./docs/resources/execute) instead diff --git a/examples/resources/snowflake_execute/resource.tf b/examples/resources/snowflake_execute/resource.tf index 02fcff0f2d..bb6cde5616 100644 --- a/examples/resources/snowflake_execute/resource.tf +++ b/examples/resources/snowflake_execute/resource.tf @@ -50,7 +50,7 @@ resource "snowflake_execute" "test" { ### fixing bad configuration ################################## -# bad revert - simple +# bad revert # 1 - resource created with a bad revert; it is constructed, revert is not validated before destroy happens resource "snowflake_execute" "test" { execute = "CREATE DATABASE ABC" @@ -63,31 +63,6 @@ resource "snowflake_execute" "test" { revert = "DROP DATABASE ABC" } -# bad revert - complex (we assume that the problem is spotted after trying to change the execute) -# 1 - resource created with a bad revert; it is constructed, revert is not validated before destroy happens -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE ABC" - revert = "SELECT 1" -} - -# 2 - try to create different database; it will fail on bad destroy -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE XYZ" - revert = "SELECT 1" -} - -# 3 - fix the revert first -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE ABC" - revert = "DROP DATABASE ABC" -} - -# 4 - create different database updating revert also -resource "snowflake_execute" "test" { - execute = "CREATE DATABASE XYZ" - revert = "DROP DATABASE XYZ" -} - # bad query # 1 - resource will be created; query_results will be empty resource "snowflake_execute" "test" { diff --git a/pkg/resources/execute.go b/pkg/resources/execute.go index 375e014631..6ad9b189cd 100644 --- a/pkg/resources/execute.go +++ b/pkg/resources/execute.go @@ -31,7 +31,7 @@ var executeSchema = map[string]*schema.Schema{ "query": { Type: schema.TypeString, Optional: true, - Description: "Optional SQL statement to do a read. Invoked after creation and every time it is changed.", + Description: "Optional SQL statement to do a read. Invoked on every resource refresh and every time it is changed.", }, "query_results": { Type: schema.TypeList, @@ -59,7 +59,7 @@ func Execute() *schema.Resource { StateContext: schema.ImportStatePassthroughContext, }, - Description: "Resource allowing execution of ANY SQL statement. It may destroy resources if used incorrectly. It may behave incorrectly combined with other resources. Use at your own risk.", + Description: "Resource allowing execution of ANY SQL statement.", CustomizeDiff: TrackingCustomDiffWrapper(resources.UnsafeExecute, customdiff.All( customdiff.ForceNewIfChange("execute", func(ctx context.Context, oldValue, newValue, meta any) bool { diff --git a/pkg/resources/unsafe_execute.go b/pkg/resources/unsafe_execute.go index 2bc58d65d6..822900ce02 100644 --- a/pkg/resources/unsafe_execute.go +++ b/pkg/resources/unsafe_execute.go @@ -7,6 +7,6 @@ import ( func UnsafeExecute() *schema.Resource { unsafeExecute := Execute() unsafeExecute.Description = "Experimental resource allowing execution of ANY SQL statement. It may destroy resources if used incorrectly. It may behave incorrectly combined with other resources. Use at your own risk." - unsafeExecute.DeprecationMessage = "This resource is deprecated and will be removed in a future major version release. Please use snowflake_account_role instead." + unsafeExecute.DeprecationMessage = "This resource is deprecated and will be removed in a future major version release. Please use snowflake_execute instead." return unsafeExecute } diff --git a/templates/resources/execute.md.tmpl b/templates/resources/execute.md.tmpl index dc4863c62f..80794cba89 100644 --- a/templates/resources/execute.md.tmpl +++ b/templates/resources/execute.md.tmpl @@ -36,5 +36,5 @@ description: |- Import is supported using the following syntax: -{{ printf "{{codefile \"shell\" %q}}" .ImportFile }} +{{ codefile "shell" (printf "examples/resources/%s/import.sh" .Name)}} {{- end }} diff --git a/templates/resources/unsafe_execute.md.tmpl b/templates/resources/unsafe_execute.md.tmpl index dc4863c62f..80794cba89 100644 --- a/templates/resources/unsafe_execute.md.tmpl +++ b/templates/resources/unsafe_execute.md.tmpl @@ -36,5 +36,5 @@ description: |- Import is supported using the following syntax: -{{ printf "{{codefile \"shell\" %q}}" .ImportFile }} +{{ codefile "shell" (printf "examples/resources/%s/import.sh" .Name)}} {{- end }}