Azure / Azure/relational-infrastructure

Support changing VM admin password

Open
#31 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HCL
Stars
3
Forks
3
PR merge metrics
No merged PRs in 30d

Description

By default, the AVM module for creating VMs sets a random admin password that is then tracked in Terraform state.

Customers would like to set the VM admin password to a known value stored in their password vault or an Azure Key Vault. If the VM admin password attribute is set in the AVM module, and then changed at a later date, this forces a destroy and re-create of the VM itself. This behavior is related to the way the azurerm provider handles setting the initial VM admin password at VM creation.

This approach poses a significant risk to critical Epic infrastructure.

Proposed solution for Windows VMs:

- Allow initial VM admin password to be set to a random value as per AVM default. This value will be stored in Terraform state and never changed, so will never trip the destroy/re-create scenario
- Use azurerm_virtual_machine_extension resource block to set the VM admin password to desired value
- If VM admin password changes in the future, it will be handled by the azurerm_virtual_machine_extension block, which does not trip the destroy/re-create scenario
- Still need to figure out how to do this for Linux VMs

Sample code for Windows VM:

```terraform
resource "azurerm_virtual_machine_extension" "admin_access" {
for_each = module.epic_vm_instances_primary

name = each.value.name
virtual_machine_id = each.value.virtual_machine.id

publisher = "Microsoft.Compute"
type = "VMAccessAgent"

type_handler_version = "2.4"
auto_upgrade_minor_version = true

protected_settings = jsonencode({
username = "azureuser",
password = ,
reset_password = true,
})
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.