hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.58k stars 4.62k forks source link

Cognitive Service Account creation error #8377

Closed paveldokov closed 4 years ago

paveldokov commented 4 years ago

Terraform (and AzureRM Provider) Version

Terraform v0.12.29

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_cognitive_account" "cv_prediction" {
  name                = "${var.name}-prediction"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  kind                = "CustomVision.Prediction"

  sku_name = "S0"

  tags = {
    Environment = var.environment
  }
}
resource "azurerm_cognitive_account" "cv_training" {
  name                = "${var.name}-training"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  kind                = "CustomVision.Training"

  sku_name = "S0"

  tags = {
    Environment = var.environment
  }
}

Debug Output

Panic Output

Expected Behavior

The cognitive accounts are created successfully. This actually happens 50% of the time:

random_string.random: Creating...
random_string.random: Creation complete after 0s [id=Zbx]
azurerm_resource_group.rg: Creating...
azurerm_resource_group.rg: Creation complete after 0s [id=/subscriptions/<sub_id>/resourceGroups/<resource_group_name>]
azurerm_cognitive_account.cv_prediction: Creating...
azurerm_cognitive_account.cv_prediction: Creation complete after 2s [id=/subscriptions/<sub_Id>/resourceGroups/<resource_group_name>/providers/Microsoft.CognitiveServices/accounts/dev-123-prediction]
azurerm_cognitive_account.cv_training: Creating...
azurerm_cognitive_account.cv_training: Creation complete after 1s [id=/subscriptions/sub_id/resourceGroups/<resource_group_name>/providers/Microsoft.CognitiveServices/accounts/dev-123-training]

Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

Actual Behavior

One or both of the accounts fail to create at least 50% of the time with error:

Error: Error obtaining keys for Cognitive Services Account "dev-123-training" in Resource Group "<resource-group-name>": cognitiveservices.AccountsClient#ListKeys: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="RequestConflict" Message="Cannot modify resource with id '/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.CognitiveServices/accounts/dev-123-training' because the resource entity provisioning state is not terminal. Please wait for the provisioning state to become terminal and then retry the request."

Usually, the training account will fail, but the prediction account might fail as well.

Steps to Reproduce

  1. terraform apply

Important Factoids

Regardless of the error, the cognitive services account is created and usable, nonetheless, Terraform marks it as tainted and on subsequent run will be recreated. As noted, this behaviour is observed ~50% of the time.

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!