How does one drop an adx table using the azurerm terraform provider? It seems like an intentional exclusion, so I wonder if I'm missing something fundamental here.
I tried doing the following:
resource "azurerm_kusto_script" "drop_old_table" {
name = "drop_old_table"
database_id = azurerm_kusto_database.mydb.id
continue_on_errors_enabled = false
script_content = ".drop tables ( Table1, Table2) ifexists"
}
But got an error:
Code="ScriptContainsUnsupportedCommand" Message="[BadRequest] The provided script contains unsupported command. The commands must start with the following verbs: '.create, .create-or-alter, .create-merge, .alter, .alter-merge, .enable'"
I tried to reproduce the same in my environment to drop the table if exists:
code:
Using
Received the same error :
error:
Terraform may not work while cheking using ifexists query .
I used .drop table MyTable excluding the ifexists When I checked the portal , I could not find anytable.
Code:
As drop requies to check the resource first, gave error:
To query for pre existing resource, you may have to use variables to store data and use Boolean state.
or try use external data_source ,if can be done using sdk or powershell cli terraform-check-if-resource-exists-before-creating-it | Stack Overflow
Reference : .drop table and .drop tables - Azure Data Explorer | Microsoft Learn