aidanmelen / terraform-provider-snowsql

Terraform SnowSQL provider
https://registry.terraform.io/providers/aidanmelen/snowsql/latest
Other
22 stars 10 forks source link

bug: `read_results` not json decodable when `read` is not specified #82

Closed aidanmelen closed 1 year ago

aidanmelen commented 1 year ago

The snowsql_exec resource supports an optional read block which will return a JSON encoded string containing the query result set(s). When the read block is not specified, attribute is a non-json decodable empty string which will fail to decode with the jsondecode() terraform function.

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "snowsql_exec" "role" {
  name = "my_role"

  create {
    statements = "CREATE ROLE IF NOT EXISTS my_role"
  }

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

output "show_role_results" {
  description = "The SnowSQL query result from the read statements."
  value       = jsondecode(nonsensitive(snowsql_exec.role.read_results))
}

Error Output

╷
│ Error: Error in function call
│ 
│   on outputs.tf line 3, in output "show_role_results":
│    3:   value       = jsondecode(nonsensitive(snowsql_exec.role.read_results))
│     ├────────────────
│     │ snowsql_exec.role.read_results has a sensitive value
│ 
│ Call to function "jsondecode" failed: EOF.
╵

Expected Behavior

That read_results is a empty JSON encoded list so that the jsondecode doesn't failed on a empty string.

> jsondecode("null")
null

Actual Behavior

We are essentially doing this:

> jsondecode("")

╷
│ Error: Error in function call
│ 
│   on <console-input> line 1:
│   (source code not available)
│ 
│ Call to function "jsondecode" failed: EOF.
╵

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. jsondecode read_results.
  2. terraform apply with the read block not specified.