Skip to content

Commit

Permalink
azurerm_kusto_script - Lock kusto cluster so multiple scripts can b…
Browse files Browse the repository at this point in the history
…e applied (#16690)
  • Loading branch information
mojanas committed May 12, 2022
1 parent 865b078 commit f9fb933
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
4 changes: 4 additions & 0 deletions internal/services/kusto/kusto_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
Expand Down Expand Up @@ -261,6 +262,9 @@ func resourceKustoClusterCreateUpdate(d *pluginsdk.ResourceData, meta interface{
}
}

locks.ByID(id.Name)
defer locks.UnlockByID(id.Name)

sku, err := expandKustoClusterSku(d.Get("sku").([]interface{}))
if err != nil {
return err
Expand Down
4 changes: 0 additions & 4 deletions internal/services/kusto/kusto_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/parse"
kustoValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down Expand Up @@ -96,9 +95,6 @@ func resourceKustoDatabaseCreateUpdate(d *pluginsdk.ResourceData, meta interface
}
}

locks.ByID(id.ID())
defer locks.UnlockByID(id.ID())

databaseProperties := expandKustoDatabaseProperties(d)

readWriteDatabase := kusto.ReadWriteDatabase{
Expand Down
5 changes: 3 additions & 2 deletions internal/services/kusto/kusto_database_script_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ func resourceKustoDatabaseScriptCreateUpdate(d *pluginsdk.ResourceData, meta int
}
}

locks.ByID(databaseId.ID())
defer locks.UnlockByID(databaseId.ID())
clusterId := parse.NewClusterID(databaseId.SubscriptionId, databaseId.ResourceGroup, databaseId.ClusterName)
locks.ByID(clusterId.ID())
defer locks.UnlockByID(clusterId.ID())

forceUpdateTag := d.Get("force_an_update_when_value_changed").(string)
if len(forceUpdateTag) == 0 {
Expand Down
43 changes: 41 additions & 2 deletions internal/services/kusto/kusto_database_script_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func TestAccKustoScript_multiple(t *testing.T) {
Config: r.multiple(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(fmt.Sprintf("%s%d", data.ResourceName, 2)).ExistsInAzure(r),
check.That(fmt.Sprintf("%s%d", data.ResourceName, 3)).ExistsInAzure(r),
check.That(fmt.Sprintf("%s%d", data.ResourceName, 4)).ExistsInAzure(r),
),
},
data.ImportStep("sas_token"),
Expand Down Expand Up @@ -234,6 +237,27 @@ func (r KustoScriptResource) multiple(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_kusto_database" "test2" {
name = "acctest-kd-2-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
cluster_name = azurerm_kusto_cluster.test.name
}
resource "azurerm_kusto_database" "test3" {
name = "acctest-kd-3-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
cluster_name = azurerm_kusto_cluster.test.name
}
resource "azurerm_kusto_database" "test4" {
name = "acctest-kd-4-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
cluster_name = azurerm_kusto_cluster.test.name
}
resource "azurerm_kusto_script" "test" {
name = "acctest-ks-%d"
database_id = azurerm_kusto_database.test.id
Expand All @@ -243,9 +267,24 @@ resource "azurerm_kusto_script" "test" {
resource "azurerm_kusto_script" "test2" {
name = "acctest-ks-2-%d"
database_id = azurerm_kusto_database.test.id
database_id = azurerm_kusto_database.test2.id
url = azurerm_storage_blob.test.id
sas_token = data.azurerm_storage_account_blob_container_sas.test.sas
}
resource "azurerm_kusto_script" "test3" {
name = "acctest-ks-3-%d"
database_id = azurerm_kusto_database.test3.id
url = azurerm_storage_blob.test.id
sas_token = data.azurerm_storage_account_blob_container_sas.test.sas
}
resource "azurerm_kusto_script" "test4" {
name = "acctest-ks-4-%d"
database_id = azurerm_kusto_database.test4.id
url = azurerm_storage_blob.test.id
sas_token = data.azurerm_storage_account_blob_container_sas.test.sas
}
`, template, data.RandomInteger, data.RandomInteger)
`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger,
data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

0 comments on commit f9fb933

Please sign in to comment.