From 8f8d86d0bd0c619edb20cc190e810299917f0b80 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 3 Jun 2020 12:29:19 +0100 Subject: [PATCH] re-added 500 Response workaround for CosmosDB CheckNameExists bug that has resurfaced --- .../services/cosmos/cosmosdb_account_resource.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go index 87af01badb75..74fd6573ebb7 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "log" + "net/http" "regexp" "strings" "time" @@ -307,13 +308,15 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) r, err := client.CheckNameExists(ctx, name) if err != nil { - return fmt.Errorf("Error checking if CosmosDB Account %q already exists (Resource Group %q): %+v", name, resourceGroup, err) - } - - if !utils.ResponseWasNotFound(r) { - return fmt.Errorf("CosmosDB Account %s already exists, please import the resource via terraform import", name) + // todo remove when https://github.com/Azure/azure-sdk-for-go/issues/9891 is fixed + if !utils.ResponseWasStatusCode(r, http.StatusInternalServerError) { + return fmt.Errorf("Error checking if CosmosDB Account %q already exists (Resource Group %q): %+v", name, resourceGroup, err) + } + } else { + if !utils.ResponseWasNotFound(r) { + return fmt.Errorf("CosmosDB Account %s already exists, please import the resource via terraform import", name) + } } - geoLocations, err := expandAzureRmCosmosDBAccountGeoLocations(name, d) if err != nil { return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) geo locations: %+v", name, resourceGroup, err)