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.61k stars 4.65k forks source link

Multiple `azurerm_cognitive_deployment`s result in a "Another operation is being performed on the parent resource" error #22607

Closed msha1026 closed 1 year ago

msha1026 commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.3

AzureRM Provider Version

3.65.0

Affected Resource(s)/Data Source(s)

azurerm_cognitive_deployment

Terraform Configuration Files

resource "azurerm_cognitive_account" "cognitive_account" {
  name                = "${var.prefix}-${var.project}-openai-${var.environment}"
  location            = var.location
  resource_group_name = var.resource_group_name
  kind                = "OpenAI"
  sku_name            = "S0"
}

resource "azurerm_cognitive_deployment" "gpt35turbo" {
  name                 = "chat"
  cognitive_account_id = azurerm_cognitive_account.cognitive_account.id

  model {
    format  = "OpenAI"
    name    = "gpt-35-turbo"
    version = "0301"
  }

  scale {
    type = "Standard"
  }
}

resource "azurerm_cognitive_deployment" "ada" {
  name                 = "embedding-ada"
  cognitive_account_id = azurerm_cognitive_account.cognitive_account.id

  model {
    format  = "OpenAI"
    name    = "text-embedding-ada-002"
    version = "2"
  }

  scale {
    type = "Standard"
  }
}

Debug Output/Panic Output

│ Error: creating Deployment (Subscription: "***"
│ Resource Group Name: "***"
│ Account Name: "cpg-copilot-openai-tst"
│ Deployment Name: "embedding-ada"): performing CreateOrUpdate: unexpected status 409 with error: RequestConflict: Another operation is being performed on the parent resource '/subscriptions/***/resourceGroups/***/providers/Microsoft.CognitiveServices/accounts/cpg-copilot-openai-tst'. Please try again later.
│ 
│   with module.copilot_platform.azurerm_cognitive_deployment.ada,
│   on modules/platform/cognitive.tf line 39, in resource "azurerm_cognitive_deployment" "ada":
│   39: resource "azurerm_cognitive_deployment" "ada" {
│ 
│ creating Deployment (Subscription: "***"
│ Resource Group Name: "***"
│ Account Name: "cpg-copilot-openai-tst"
│ Deployment Name: "embedding-ada"): performing CreateOrUpdate: unexpected
│ status 409 with error: RequestConflict: Another operation is being
│ performed on the parent resource
│ '/subscriptions/***/resourceGroups/***/providers/Microsoft.CognitiveServices/accounts/cpg-copilot-openai-tst'.
│ Please try again later.

Expected Behaviour

Successfully created multiple OpenAI model deployments (assuming there's some retry logic under the hood).

Actual Behaviour

Failed to create multiple OpenAI model deployments.

Steps to Reproduce

No response

Important Factoids

No response

References

No response

liuwuliuyun commented 1 year ago

Hi @msha1026 , thanks for raising this issue. As the error message suggests, creating deployments is only able to do sequentially. I think you could try the depend_on meta to make the second deployment depend on the first one as a workaround. For azurerm devs, we could add locks to the parent resource and avoid having this problem. I will start implementing this later. Let me know if you have more questions on this.

msha1026 commented 1 year ago

Great, makes sense. We will use the depends_on workaround for now. Thank you, @liuwuliuyun!

Erzangel commented 1 year ago

Hello, I am in a case where I create the azurerm_cognitive_deployment through a count and therefore cannot use the depends-on workaround.

i.e. if my count is set to 3, I am almost sure to run into the above error.

If locks to the parent resource make it so that each resource in the count is applied sequentially, this does seem like the correct solution!

github-actions[bot] commented 6 months 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.