aliyun / terraform-provider-alicloud

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

alicloud_ecs_key_pair_attachment rewrites in for_each loop #6925

Open igorfraa opened 7 months ago

igorfraa commented 7 months ago

Terraform Version

Terraform v1.3.7
on darwin_arm64
+ provider registry.terraform.io/aliyun/alicloud v1.215.0

(also other versions)

Affected Resource(s)

Expected Behavior

Multiple ssh keys attached (binded in Alicloud terms) to the ECS instance.

Actual Behavior

One or more keys got binded but never all at once. Note: It seems the longer the list, the more keys got attached (up to 3-5 keys from list of 20). Attachments are random.

With force=true only the last key attaches through all the cases. Though this can be explained throughout the docs.

Terraform Configuration Files

variable "ssh_keys" {
  type        = map(string)
  description = "Ssh keys"
  default = {
  user1 = "ssh-rsa AAAAB3 ..."
  user2 = "ssh-rsa AAAAB3 ..."
  user3 = "ssh-rsa AAAAB3 ..."
  user4 = "ssh-rsa AAAAB3 ..."
  }
}
resource "alicloud_ecs_key_pair" "ssh_keys" {
  for_each      = var.ssh_keys
  key_pair_name = each.key
  public_key    = each.value
}

resource "alicloud_ecs_key_pair_attachment" "ssh_keys" {
  for_each      = var.ssh_keys
  key_pair_name = alicloud_ecs_key_pair.ssh_keys[each.key].key_pair_name
  instance_ids  = var.instance_ids
  force         = false
}

Steps to Reproduce

  1. terraform apply
igorfraa commented 7 months ago

please note if any more information needed

igorfraa commented 7 months ago

carefully reading corresponding resource I didn't get how is this supposed to go.

Dear Developer He Guimin (@xiaozhu36), would you have a chance to look into?

source link

xiaozhu36 commented 4 months ago

Hi @igorfraa I am sorry for late reply, what do you mean "rewrites"? Do the multi key pairs can not be attached multi ecs instances accuratly?

igorfraa commented 4 months ago

Hi @xiaozhu36 yes - multiple key pairs are not attached correctly.

If I recall correctly, in some tries I've seen more then one key pair attached, up to 3 or 5 random keys out of the 20 in list.

xiaozhu36 commented 3 months ago

HI @igorfraa Based on your tf template, I made a test with 5 instance ids, and it can works well and did not happen your issue. Could please share me more details? like tf command outputs and diff logs after running it.