The snowsql_exec resource allows you to execute arbitrary Snowflake SQL queries from Terraform, and use the results in your infrastructure management. When using the read statements in the resource, the result(s) of the SQL query/queries will be available in the read_results attribute as a sensitive raw JSON string.
To output the query results in a non-sensitive format to the console, you can use the nonsensitive function to mark the read_results value as non-sensitive before decoding it with the jsondecode function.
resource "snowsql_exec" "role" {
name = "my_role"
create {
statements = "CREATE ROLE IF NOT EXISTS my_role;"
}
read {
statements = "SHOW ROLES LIKE 'my_role';"
}
delete {
statements = "DROP ROLE IF EXISTS my_role;"
}
}
output "read_results" {
description = "The SnowSQL query result from the read statements."
value = jsondecode(nonsensitive(snowsql_exec.role.read_results))
}
This will output the JSON formatted results like this:
The
snowsql_exec
resource allows you to execute arbitrary Snowflake SQL queries from Terraform, and use the results in your infrastructure management. When using theread
statements in the resource, the result(s) of the SQL query/queries will be available in theread_results
attribute as a sensitive raw JSON string.To output the query results in a non-sensitive format to the console, you can use the
nonsensitive
function to mark theread_results
value as non-sensitive before decoding it with thejsondecode
function.This will output the JSON formatted results like this: