Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alicloud_ecs_key_pair_attachment rewrites in for_each loop #6925

Open
igorfraa opened this issue Feb 1, 2024 · 5 comments
Open

alicloud_ecs_key_pair_attachment rewrites in for_each loop #6925

igorfraa opened this issue Feb 1, 2024 · 5 comments

Comments

@igorfraa
Copy link

igorfraa commented Feb 1, 2024

Terraform Version

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

(also other versions)

Affected Resource(s)

  • alicloud_ecs_key_pair_attachment
  • alicloud_instance (as a target)

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
Copy link
Author

igorfraa commented Feb 1, 2024

please note if any more information needed

@igorfraa
Copy link
Author

igorfraa commented Feb 1, 2024

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
Copy link
Member

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
Copy link
Author

igorfraa commented May 7, 2024

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants