Skip to content

Commit

Permalink
docs: remove if exist from example. since default terraform behavior …
Browse files Browse the repository at this point in the history
…is to fail when the resource already exists. instead i updated the import section to include an example using idempotent snowsql clauses.
  • Loading branch information
aidanmelen committed Mar 1, 2023
1 parent 4604d48 commit d75cc45
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ REGISTRY=registry.terraform.io
HOSTNAME=aidanmelen
NAME=snowsql
BINARY=terraform-provider-${NAME}
VERSION=1.3.2
VERSION=1.3.3
OS_ARCH=darwin_amd64

.PHONY: help
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/snowflake-provider-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ terraform {
required_providers {
snowsql = {
source = "aidanmelen/snowsql"
version = ">= 1.3.2"
version = ">= 1.3.3"
}
}
}
Expand Down
43 changes: 27 additions & 16 deletions docs/resources/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
page_title: "snowsql_exec Resource - terraform-provider-snowsql"
subcategory: ""
description: |-
---

# snowsql_exec (Resource)
Expand All @@ -16,11 +16,11 @@ This basic example shows how to manage an arbitrary Snowflake object.
```terraform
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}
delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}
```
Expand All @@ -38,15 +38,15 @@ This resource allows you to execute arbitrary SnowSQL queries and use the result
```terraform
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}
read {
statements = "SHOW ROLES LIKE 'my_role'"
}
delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ Execute the update statements as an in-place Terraform change by adding or modif
```terraform
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}
read {
Expand All @@ -95,11 +95,11 @@ resource "snowsql_exec" "role" {
# uncomment to update role in-place
# update {
# statements = "ALTER ROLE IF EXISTS my_role SET COMMENT = 'updated with terraform'"
# statements = "ALTER ROLE my_role SET COMMENT = 'updated with terraform'"
# }
delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}
```
Expand All @@ -109,19 +109,19 @@ resource "snowsql_exec" "role" {
```terraform
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}
read {
statements = "SHOW ROLES LIKE 'my_role'"
}
update {
statements = "ALTER ROLE IF EXISTS my_role SET COMMENT = 'updated with terraform'"
statements = "ALTER ROLE my_role SET COMMENT = 'updated with terraform'"
}
delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}
```
Expand Down Expand Up @@ -210,7 +210,7 @@ resource "snowsql_exec" "function" {
statements = <<-EOT
USE SCHEMA ${snowflake_database.database.name}.PUBLIC;
CREATE OR REPLACE FUNCTION js_factorial(d double)
CREATE FUNCTION js_factorial(d double)
RETURNS double
LANGUAGE JAVASCRIPT
STRICT
Expand All @@ -236,10 +236,7 @@ resource "snowsql_exec" "function" {
}
delete {
statements = <<-EOT
DROP FUNCTION IF EXISTS
${snowflake_database.database.name}.PUBLIC.js_factorial(FLOAT);
EOT
statements = "DROP FUNCTION ${snowflake_database.database.name}.PUBLIC.js_factorial(FLOAT);"
}
}
```
Expand Down Expand Up @@ -272,3 +269,17 @@ Import is supported using the following syntax:
```shell
terraform import snowsql_exec.name name
```

However, since the default method only imports the object without controlling the read/refresh logic, it is recommended to use snowflake clauses to interact with existing objects, such as:

```terraform
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE my_role"
}
delete {
statements = "DROP ROLE my_role"
}
}
```
2 changes: 1 addition & 1 deletion examples/data-sources/query/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
}
snowsql = {
source = "aidanmelen/snowsql"
version = ">= 1.3.2"
version = ">= 1.3.3"
}
random = ">= 2.1"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/resources/exec/basic/.create-delete.tf.docs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}

delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}
9 changes: 9 additions & 0 deletions examples/resources/exec/basic/.import.tf.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE my_role"
}

delete {
statements = "DROP ROLE my_role"
}
}
4 changes: 2 additions & 2 deletions examples/resources/exec/basic/.read.tf.docs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}

read {
statements = "SHOW ROLES LIKE 'my_role'"
}

delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/resources/exec/basic/.update.tf.docs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}

read {
statements = "SHOW ROLES LIKE 'my_role'"
}

update {
statements = "ALTER ROLE IF EXISTS my_role SET COMMENT = 'updated with terraform'"
statements = "ALTER ROLE my_role SET COMMENT = 'updated with terraform'"
}

delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}
6 changes: 3 additions & 3 deletions examples/resources/exec/basic/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "snowsql_exec" "role" {
create {
statements = "CREATE ROLE IF NOT EXISTS my_role"
statements = "CREATE ROLE my_role"
}

read {
Expand All @@ -9,10 +9,10 @@ resource "snowsql_exec" "role" {

# uncomment to update role in-place
# update {
# statements = "ALTER ROLE IF EXISTS my_role SET COMMENT = 'updated with terraform'"
# statements = "ALTER ROLE my_role SET COMMENT = 'updated with terraform'"
# }

delete {
statements = "DROP ROLE IF EXISTS my_role"
statements = "DROP ROLE my_role"
}
}
2 changes: 1 addition & 1 deletion examples/resources/exec/basic/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
}
snowsql = {
source = "aidanmelen/snowsql"
version = ">= 1.3.2"
version = ">= 1.3.3"
}
random = ">= 2.1"
}
Expand Down
7 changes: 2 additions & 5 deletions examples/resources/exec/complete/function.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "snowsql_exec" "function" {
statements = <<-EOT
USE SCHEMA ${snowflake_database.database.name}.PUBLIC;
CREATE OR REPLACE FUNCTION js_factorial(d double)
CREATE FUNCTION js_factorial(d double)
RETURNS double
LANGUAGE JAVASCRIPT
STRICT
Expand All @@ -31,9 +31,6 @@ resource "snowsql_exec" "function" {
}

delete {
statements = <<-EOT
DROP FUNCTION IF EXISTS
${snowflake_database.database.name}.PUBLIC.js_factorial(FLOAT);
EOT
statements = "DROP FUNCTION ${snowflake_database.database.name}.PUBLIC.js_factorial(FLOAT);"
}
}
2 changes: 1 addition & 1 deletion examples/resources/exec/complete/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
}
snowsql = {
source = "aidanmelen/snowsql"
version = ">= 1.3.2"
version = ">= 1.3.3"
}
random = ">= 2.1"
}
Expand Down
2 changes: 1 addition & 1 deletion templates/guides/snowflake-provider-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ terraform {
required_providers {
snowsql = {
source = "aidanmelen/snowsql"
version = ">= 1.3.2"
version = ">= 1.3.3"
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions templates/resources/exec.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ Import is supported using the following syntax:
```shell
terraform import snowsql_exec.name name
```

However, since the default method only imports the object without controlling the read/refresh logic, it is recommended to use snowflake clauses to interact with existing objects, such as:

{{ tffile "examples/resources/exec/basic/.import.tf.docs" }}

0 comments on commit d75cc45

Please sign in to comment.