Open mojanas opened 2 years ago
Hi @mojanas ,
Thank you for taking time to report this.
I'm not an expert of KQL, but when I paste the scripts to kusto query, it highlights command5
and seems it should be a -
after .alter
, after removing it, it works fine on my local. Would you please give it a try?
My config:
command5 = <<-EOT
.alter materialized-view View policy retention "{}"
EOT
Hi @ms-henglu - apologies, that was typo.
I've fixed that and also tried adding explicit dependencies on the blobs and scripts and am still hitting the "resource already exists" issue.
resource "azurerm_storage_container" "example" {
name = "setup-files"
storage_account_name = azurerm_storage_account.example.name
container_access_type = "private"
}
resource "azurerm_storage_blob" "example" {
name = "script.txt"
storage_account_name = azurerm_storage_account.example.name
storage_container_name = azurerm_storage_container.example.name
type = "Block"
source_content = local.allCommands // All the commands put in one script
depends_on = [
azurerm_storage_containe.example
]
}
resource "azurerm_kusto_script" "example" {
name = "example"
database_id = azurerm_kusto_database.example.id
url = azurerm_storage_blob.example.id
sas_token = data.azurerm_storage_account_blob_container_sas.example.sas
continue_on_errors_enabled = false
force_an_update_when_value_changed = "Last updated 2/24/2022"
depends_on = [
azurerm_storage_blob.example
]
}
I think I figured out the issue. At some point in my script resource block I had
url = azurerm_storage_blob.example.url
instead of
url = azurerm_storage_blob.example.id
Would be nice to have some validation check for using the correct field. and/or a better error message than "Internal Server Error". I enabled debug output while running locally and I was able to see the resource create successfully but fail running the commands. My guess is ARM ran into some issue parsing the blob content, which explains why I was getting the "resource already created" error. Also would be nice to have a fix for this, maybe save the resource to terraform state after creation and then start applying the script.
Hi @mojanas ,
But it seems url
and id
are set to the same value.
Yes I noticed they were the same as well. But as soon as I changed the script resource to use blob.id it started working
@mojanas , with noticing all above contexts, would you be ok if we close this issue?
I am having same issue.
resource "azurerm_kusto_script" "test" { name = "test" database_id = azurerm_kusto_database.data_explorer_database.id script_content = local.test_script continue_on_errors_enabled = false force_an_update_when_value_changed = md5(local.test_script) }
If the script contains mistake, then terraform will fail with some message -> which is correct behaviour (I suppose). BUT when I fix the mistake in the script and I run another terraform apply, it fail with a message that kusto script already exist and should be imported. How can it be created when terraform apply failed in previous run with the message that it's content is invalid?
It would be nice if in this case would be the resource marked as tainted or at least be in terraform state and something like that wouldn't be considered as new resource, but an update of existing resource, when it was already created.
I have the same problem, how can this be fixed?
resource "azurerm_kusto_script" "initial_provisioning" {
name = "initial-provisioning"
database_id = azurerm_kusto_database.prebid.id
script_content = file("${path.module}/scripts/initial.kusto")
force_an_update_when_value_changed = true
depends_on = [ azurerm_kusto_database.prebid ]
}
Here's a fix I've found:
terraform import azurerm_kusto_script.provisioning /subscriptions/627949ad-9d29-4279-9a16-2aa995e3b859/resourceGroups/analytics/providers/Microsoft.Kusto/clusters/setupad/databases/prebid/scripts/provisioning
Just change database
, subscription_id
, cluster_name
and script_name
to your own.
You can list and delete Kusto script with az-cli and then re-apply terraform
az kusto script list --cluster-name <CLUSTER> --database-name <DB> --resource-group <RG>
az kusto script delete --cluster-name <CLUSTER> --database-name <DB> --resource-group <RG> --name <SCRIPT_NAME>
https://learn.microsoft.com/en-us/cli/azure/kusto/script?view=azure-cli-latest
You can list and delete Kusto script with az-cli and then re-apply terraform
az kusto script list --cluster-name <CLUSTER> --database-name <DB> --resource-group <RG> az kusto script delete --cluster-name <CLUSTER> --database-name <DB> --resource-group <RG> --name <SCRIPT_NAME>
That's great to know, but it's still a bug and needs to be fixed
I am having same problem. Is there any way to remove this script using terraform just after execute it? Thanks
Community Note
Terraform (and AzureRM Provider) Version
~> 1.0.5
~> 2.83.0
Affected Resource(s)
azurerm_kusto_script
Terraform Configuration Files
Expected Behaviour
Resource (kusto script) is created and runs the commands successfully.
Actual Behaviour
First run
Seems like a transient error. When I run terraform plan again, it shows the script will be created:
But when I run `terraform apply again, I see this:
Sometimes, the command altering the cache policy on the materialized view will fail due to syntax error, but when I run the command in Kusto, it completes successfully.
Steps to Reproduce
terraform plan
terraform apply
Important Factoids
References
0000