aliyun / terraform-provider-alicloud

Terraform AliCloud provider
https://www.terraform.io/docs/providers/alicloud/
Mozilla Public License 2.0
578 stars 538 forks source link

alicloud_amqp_binding state conflicts when creating many bindings #7078

Open wopol opened 3 months ago

wopol commented 3 months ago

When we try to create many bindings at once, conflicts may occur because when building resource IDs InstanceId, VirtualHost, SourceExchange and DestinationName are considered.

When new binding is created and we read data from the API DestinationName is missing when looking for the right binding. It may happen that when we have many bindings for the same Exchange, the wrong state will be saved.

To reproduce this issue, you can consider the following example:

bindings = {
{
      key           = "execution-v1"
      queue_name    = "worker-execution"
      exchange_name = "internal-direct"
    },
    {
      key           = "kyc-v1"
      queue_name    = "worker-kyc"
      exchange_name = "internal-direct"
    },
    {
      key           = "user-v1"
      queue_name    = "worker-user"
      exchange_name = "internal-direct"
    },
}
.....
resource "alicloud_amqp_binding" "bindings" {
  for_each          = { for s in var.bindings : "${s.queue_name}_${s.key}" => s }
  binding_key       = each.value.key
  binding_type      = "QUEUE"
  destination_name  = each.value.queue_name
  instance_id       = var.instance_id != "" ? var.instance_id : alicloud_amqp_instance.default[0].id 
  source_exchange   = each.value.exchange_name
  virtual_host_name = alicloud_amqp_virtual_host.host.virtual_host_name

  depends_on = [alicloud_amqp_queue.queue, alicloud_amqp_exchange.exchanges]
}

PR: https://github.com/aliyun/terraform-provider-alicloud/pull/7077

wopol commented 1 month ago

Could someone take a look?

wopol commented 2 weeks ago

@xiaozhu36 ?