Skip to content

Commit

Permalink
changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Dec 12, 2024
1 parent 5224266 commit 558725a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 70 deletions.
12 changes: 7 additions & 5 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 7 additions & 30 deletions docs/resources/execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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" {
Expand Down Expand Up @@ -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

Expand All @@ -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 '<random-uuid>'
```
4 changes: 2 additions & 2 deletions docs/resources/unsafe_execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
~> **Deprecation** This resource is deprecated and will be removed in a future major version release. Please use [snowflake_execute](./execute) instead. <deprecation>

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.

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/additional/deprecated_resources.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 1 addition & 26 deletions examples/resources/snowflake_execute/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/unsafe_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion templates/resources/execute.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion templates/resources/unsafe_execute.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit 558725a

Please sign in to comment.