Problem scenario
You try to run terraform apply
to create an Azure VM but you receive a message like this:
Error: Error applying plan:
1 error(s) occurred:
* azurerm_virtual_machine.myterraformvm: 1 error(s) occurred:
* azurerm_virtual_machine.myterraformvm: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCo" Message="Authentication using either SSH or by user name and password must be enabled in Linux profile." Target="linux"
What should you do?
Solution
1. Back up your .tf file. Look at your .tf file. Find a stanza like this:
key_data = "ssh-rsa AAAAC5Mx{snip}ikjmI3w"
2. Replace "ssh-rsa AAAAC5Mx{snip}ikjmI3w" with the content of the .pub file of your choice. If you do not have one, create one by running this: ssh-keygen -t rsa -P ""
Press enter to the prompt. You should know have an id_rsa.pub file. Use the content of this file (despite it being very long) as the key_data value.
3. Run terraform init
again. Run terraform apply
again. Now the username as specified with admin_username
in the .tf file will allow you to log into the Azure VM from the server you created the id_rsa.pub file when you use ssh. From other Windows workstations, you will probably not be allowed to log in the new Azure VM with that admin_username; so you will probably want to create some new users on the new Azure VM.