hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.32k stars 1.72k forks source link

apigee_endpoint_attachment - Error 400: the resource is locked by another operation #12369

Closed pysiok1983 closed 2 years ago

pysiok1983 commented 2 years ago

Community Note

Terraform Version

1.2.7 Google provider - 4.32.0

Affected Resource(s)

Terraform Configuration Files

locals = {
    psc_groups = {
      psc_01 = {
        service_attachment_name = "psc1"
        service_attachment  = "projects/<proj1>/regions/us-central1/serviceAttachments/sa1"

      }
      psc_02 = {
        service_attachment_name = "psc2"
        service_attachment  = "projects/<proj2>/regions/us-central1/serviceAttachments/sa2"

      }
    }
}

resource "google_apigee_endpoint_attachment" "apigee_endpoint_attachment" {
  for_each               = local.psc_groups
  org_id                 = google_apigee_organization.org.id
  endpoint_attachment_id = each.value.service_attachemnt_name
  location               = "us-central1"
  service_attachment     = each.value.service_attachemnt
}

Debug Output

│ Error: Error creating EndpointAttachment: googleapi: Error 400: the resource is locked by another operation where endpoint attachment psc1 is currently being created for organization proj1 by operation: d03e570e-56c4-4af9-85aa-c117a77be7ac │ Details: │ [ │ │ "@type": "type.googleapis.com/google.rpc.RequestInfo", │ "requestId": "210181044925815171" │ │ ]

Expected Behavior

Both PSCs should be created without any issues.

Actual Behavior

Seems that using a loop for google_apigee_endpoint_attachment causes an issue. The resource doesn't wait enough long and when the second psc is launching APIgee reports an issue.

Steps to Reproduce

  1. terraform apply

Important Factoids

Using -parallelism=1 solved this issue but delays the whole deployment.

References

edwardmedia commented 2 years ago

@pysiok1983 this limitation is at the API. There is little the provider can do. Does this make sense?

pysiok1983 commented 2 years ago

Can we add a delay for each iteration within this resource?

edwardmedia commented 2 years ago

@pysiok1983 I don't think so. There is no need when one resource is created. When you prepare a module, that might be a good place to do. Does this make sense?

pysiok1983 commented 2 years ago

@pysiok1983 I don't think so. There is no need when one resource is created. When you prepare a module, that might be a good place to do. Does this make sense?

I have tested a module - same issue.

 resource "time_sleep" "psc_propagation" {
   create_duration = "15s"
 }

module "psc_sb" {
    source                  = "../psc"
    for_each                = var.psc_groups
    service_attachment_name = each.value.service_attachment_name
    service_attachment      = each.value.service_attachment
    depends_on             = [ time_sleep.psc_propagation ]
}
edwardmedia commented 2 years ago

@pysiok1983 sorry, what I meant was that delay logic could be built inside a module which might handle the concurrency in multiple instances, because this only happens when you create multiple instances at the same time. For your case, using -parallelism=1 is still the best choice, I think.

pysiok1983 commented 2 years ago

@pysiok1983 sorry, what I meant was that delay logic could be built inside a module which might handle the concurrency in multiple instances.

Are you able to provide an example?

edwardmedia commented 2 years ago

@pysiok1983 sorry no. This repo is for the individual resource. If there is no existing module available, you probably need to build it by yourself.

To your suggestion here, not sure how delay for each iteration within this resource can help? Can you elaborate?

edwardmedia commented 2 years ago

Closing this now. @pysiok1983 feel free to reopen if you want to continue

github-actions[bot] commented 1 year 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.