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

r/linux_virtual_machine: support for parsing ssh2 keys #10167

Open
AleFazio opened this issue Jan 13, 2021 · 8 comments
Open

r/linux_virtual_machine: support for parsing ssh2 keys #10167

AleFazio opened this issue Jan 13, 2021 · 8 comments

Comments

@AleFazio
Copy link

AleFazio commented Jan 13, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Good morning,

We have an infrastructure generated in Azure which we are trying to terraform.
In particular, we have a problem with admin_ssh_key "public_key" in "azurerm_linux_virtual_machine" when the key imported is in the following format:
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20200715"
ssh-rsa AAA....
---- END SSH2 PUBLIC KEY --

We have several virtual machines with their linked ssh key in different format and we reference to them using the file function:

admin_ssh_key {
username = "azureuser"
public_key = file(<path_to_ssh_key>)
}

After performing the command terraform plan, it manages to compare information with keys in string format but not in the ---- BEGIN SSH2 PUBLIC KEY ---- format.

I tried using file either with or without .pub extension but I didn't get any result.
Below a screenshot of the error:
decoding_error

I also tried using an input key even in the ssh-rsa common format (ignoring the 'BEGIN/END' and 'comment' keyword) but Terraform tries to forces replacement in this case.

Terraform (and AzureRM Provider) Version

Versions:
Terraform v0.13.2
Provider azurerm: 2.82.0

Affected Resource(s)

azurerm_linux_virtual_machine

Expected Behaviour

The input key should be correctly decoded and matched with the one imported along with the vm configuration in the state file

Actual Behaviour

Decoding error (Error: Error decoding "admin_ssh_key.0.public_key" for public key data) when running terraform plan/apply

Steps to Reproduce

  1. Get your key in the following format:
    '---- BEGIN SSH2 PUBLIC KEY ----
    Comment: "rsa-key-20200715"
    ssh-rsa AAA....
    ---- END SSH2 PUBLIC KEY --'
  2. Copy/paste the key in a file (or just use the original key file if you have it) and refer to it using file(path) function (public_key field).
  3. run terraform plan/apply

References

In #9238 I mentioned this issue along with the 'forces replacement' issue (when the key is created through the portal) since I thought they could be related to the same problem but unfortunately they're not.

@AleFazio AleFazio changed the title ssh public key decoding error "azurerm_linux_virtual_machine" ssh public key decoding error "azurerm_linux_virtual_machine" [bug] [service/virtual-machine] Jan 13, 2021
@AleFazio

This comment was marked as off-topic.

@AleFazio

This comment was marked as off-topic.

@bhuisgen

This comment was marked as off-topic.

@CruzanCaramele
Copy link

@AleFazio hello, please did you find a solution yet, i am having the same problem as well

@AleFazio

This comment was marked as off-topic.

@tombuildsstuff tombuildsstuff changed the title ssh public key decoding error "azurerm_linux_virtual_machine" [bug] [service/virtual-machine] r/linux_virtual_machine: support for parsing ssh2 keys Mar 7, 2022
@balintbako
Copy link

balintbako commented Mar 24, 2022

I have the same issue in v2.99 azure provider

It seems to be fine if the file format is as per Linux ssh-keygen, i.e. a single line like this:
ssh-rsa AAA....

@karthikvenkat17
Copy link

Hi, Are there any workarounds for this issue to avoid terraform forcing replacement when importing existing virtual machines which has public key in this format
'---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20200115"
ssh-rsa AAA....
---- END SSH2 PUBLIC KEY --'

@AleFazio
Copy link
Author

AleFazio commented Jul 5, 2023

Indeed, it’s unbelievable Microsoft hasn’t fixed this yet

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

No branches or pull requests

7 participants