Azure / terraform-azurerm-avm-res-compute-virtualmachine

Terraform AVM module for virtual machines
MIT License
14 stars 22 forks source link

[AVM Module Issue]: Cannot add multiple admin ssh keys for the same user #103

Closed lodrantl closed 1 week ago

lodrantl commented 1 month ago

Check for previous/existing GitHub issues

Issue Type?

Bug

(Optional) Module Version

0.15.1

(Optional) Correlation Id

No response

Description

The module requires the admin_ssh_key usernames to be unique which prevent you from adding multiple keys for the same user.

module "vm_linux_aap_vm_linux" {
  source  = "Azure/avm-res-compute-virtualmachine/azurerm"
  version = "0.15.1"
  admin_username                     = "admin"
  generate_admin_password_or_ssh_key = false
  location                           = "loc"
  name                               = "vm"
  resource_group_name    = "rg"
  os_type                            = "Linux"
  sku_size                           = "Standard_D2_v5"
  zone                               = 1

  admin_ssh_keys = [
    {
      public_key = "ssh-rsa ..."
      username   = "admin"
    },
    {
      public_key = "ssh-rsa ..."
      username   = "admin"
    }
  ]

  source_image_reference = {
    offer     = "RHEL"
    publisher = "RedHat"
    sku       = "92-gen2"
    version   = "latest"
  }
}

Error given:

│ Error: Duplicate object key
│ 
│   on .terraform/modules/vm_linux_aap_vm_linux/main.linux_vm.tf line 71, in resource "azurerm_linux_virtual_machine" "this":
│   71:     for_each = { for key in local.admin_ssh_keys : key.username => key }
│     ├────────────────
│     │ key.username is "admin"
│ 
│ Two different items produced the key "admin" in this 'for' expression. If duplicates are expected, use the ellipsis (...) after the value expression to enable grouping by key.

I can submit a PR fix if needed.

Best, Luka

jchancellor-ms commented 1 week ago

@lodrantl - Thanks for submitting this. I'm back this week, so let me correct this and create a new release.

jchancellor-ms commented 1 week ago

@lodrantl - I determined that one of the filters was missing causing this issue. I've pushed v0.16.0 to address this. The PR closed this issue, but if you discover that this is still a problem, please re-open this issue and I'll address. Thanks again for your submission.