使用azurerm terraform提供器删除adx表

dced5bon  于 2022-12-27  发布在  其他
关注(0)|答案(1)|浏览(134)

如何使用azurerm terraform提供程序删除adx表?这似乎是有意排除的,所以我想知道我是否遗漏了一些基本的东西。
我试着做了以下几点:

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"
}

但得到一个错误:
代码=“ScriptContainsUnsupportedCommand”消息="[BadRequest]提供的脚本包含不受支持的命令。命令必须以下列 predicate 开头:'.创建,.创建或更改,.创建合并,.更改,.更改合并,.启用'“

brgchamk

brgchamk1#

我尝试在我的环境中重现相同的内容以删除表(如果存在):
代码:

resource "azurerm_kusto_script" "example" {
  name                               = "example"
  database_id                        = azurerm_kusto_database.mydb.id
  url                                = azurerm_storage_blob.newexample.id
  sas_token                          = data.azurerm_storage_account_blob_container_sas.example.sas
  continue_on_errors_enabled         = true
  force_an_update_when_value_changed = "first"
}

使用

source_content= ".drop table MyTable ifexists"

收到相同的错误:

Scripts/drop_old_table" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_kusto_script" for more information.

错误:

使用ifexists查询进行检查时,Terraform可能无法工作。
我使用了. drop表MyTable,但不包括ifexists当我检查门户时,我找不到任何表。

.drop table MyTable

代码:

resource "azurerm_storage_blob" "newexample" {
  name                   = "script.txt"
  storage_account_name   = azurerm_storage_account.newexample.name
  storage_container_name = azurerm_storage_container.conexample.name
  type                   = "Block"
  source_content         = ".drop table MyTable "
}

由于删除请求首先检查资源,因此出现错误:
要查询预先存在的资源,您可能必须使用变量来存储数据并使用布尔状态。
或尝试使用外部数据源,如果可以使用sdk或powershell cli terraform-check-if-resource-exists-before-creating-it | Stack Overflow完成

相关问题