terraform-provider-databricks
terraform-provider-databricks copied to clipboard
[ISSUE] Issue with `databricks_sql_query` resource, query based parameter, parameter values are invalid
Description
I am trying to deploy an sql query which has an query based input parameter. This throwing an unexpected error message, all other parameter types work as intended but specifically the query based parameter is causing issues.
The issue only appears when first deploying the query and including the parameter, if the sql_query already exists and I modify it to now include the query based parameter, this second time deploying does not cause an issue.
Because of this I have had to resort to changing my deployment pipeline to now has 2 steps, one where I exclude the params followed by a second where I include them.
Configuration
resource "databricks_sql_query" "count" {
data_source_id = data.databricks_sql_warehouse.dashboard_sql_endpoint.data_source_id
name = "count"
query = <<-EOT
SELECT 1
EOT
parent = "folders/${databricks_directory.queries.object_id}"
run_as_role = "owner"
}
resource "databricks_sql_query" "query_parameter_test" {
data_source_id = data.databricks_sql_warehouse.dashboard_sql_endpoint.data_source_id
name = "Query Based Parameter Test"
query = <<EOT
SELECT
*
FROM
system.billing.usage
LIMIT {{count}}
EOT
parent = "folders/${databricks_directory.queries.object_id}"
run_as_role = "owner"
parameter {
name = "count"
title = "count"
query {
query_id = databricks_sql_query.count.id
}
}
}
Expected Behavior
Able to deploy the query and the query based parameter to update the query works correctly.
Actual Behavior
Recieve this error message
module.dashboards_workspace.databricks_sql_query.query_parameter_test: Creating...
╷
│ Error: cannot create sql query: The following parameter values are invalid: [Map(count -> )].
│
│ with module.dashboards_workspace.databricks_sql_query.query_parameter_test,
│ on ../../modules/dashboards_workspace/dbu_usage_dashboard.tf line 720, in resource "databricks_sql_query" "query_parameter_test":
│ 720: resource "databricks_sql_query" "query_parameter_test" {
│
╵
make: *** [Makefile:33: tf-apply] Error 1
Steps to Reproduce
terraform apply
Note: if you remove the parameter block, deploy with terraform apply then add the block back and redeploy the deployment works fine and throws no errors
Terraform and provider versions
Terraform v1.6.1 on linux_amd64
Is it a regression?
Unsure
Debug Output
Unable to provide the debug output, apologies
Important Factoids
Nothing that I'm aware of
Would you like to implement a fix?
I encountered a similar (?) issue when creating a databricks_sql_query with a query-based parameter; it fails on the first attempt. However, I received a different Terraform error message:
│ Error: cannot create sql query: Session Id not found
│
│ with databricks_sql_query.queries["some_name"],
│ on main.tf line 68, in resource "databricks_sql_query" "queries":
│ 68: resource "databricks_sql_query" "queries" {
After initially creating the resource with a different parameter type (text), the creation process succeeded. Later, when I modified the parameter type back to query-based, Terraform recognized the change and updated the resource successfully.