Hi Shadi,
Sadly terraform always will try to recreate the machine when you change the password even if you already have the resource in your statefile
the machine, a work around is using azure cli within terraform null resource as bellow exameple,:
- Already have all definitions of VM
- Null resource change the password based on variable new_value
resource "null_resource" "reset_password" {
triggers = {
always_run = "${timestamp()}"
}
provisioner "local-exec" {
command = "az vm user update --resource-group <RG-VM> --name <VM-NAME> --username <User-Name> --password newPassword01$"
}
}
Note: that the local-exec provisioner will execute the command on the machine running Terraform, not on the VM. Therefore, you need to have the Azure CLI installed and configured on this machine
Let Me know if this solve your challenge. Luis,
Note: I recommend you protect sensitive variable as password in terraform (https://developer.hashicorp.com/terraform/tutorials/configuration-language/sensitive-variables)