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

support raw value for ssh keys in addition to paths #159

Merged
merged 12 commits into from
Dec 15, 2020
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ More specifically this provisions:
When ssh keys are enabled you can either
- use the default "~/.ssh/id_rsa.pub"
- set one key by setting a path in ssh_key variable. e.g "joey_id_rsa.pub"
- set shh_key and add zero or more files paths in extra_ssh_keys variable e.g. ["ross_id_rsa.pub", "rachel_id_rsa.pub"] (since v3.8.0)
- set ssh_key and add zero or more files paths in extra_ssh_keys variable e.g. ["ross_id_rsa.pub", "rachel_id_rsa.pub"] (since v3.8.0)
- set ssh_key and/or extra_ssh_keys as raw public ssh key value or refer it to a data source with the public key value, e.g. `ssh_key="ssh-rsa AAAAB3NzaC1yc..."`
AliAllomani marked this conversation as resolved.
Show resolved Hide resolved

4 - You can install custom certificates / secrets on the virtual machine from Key Vault by using the variable `os_profile_secrets`.

Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ resource "azurerm_virtual_machine" "vm-linux" {
for_each = var.enable_ssh_key ? local.ssh_keys : []
content {
path = "/home/${var.admin_username}/.ssh/authorized_keys"
key_data = file(ssh_keys.value)
key_data = lower(substr(ssh_keys.value,-4,4)) == ".pub" ? file(ssh_keys.value) : ssh_keys.value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using an old variable to represent both directory and value, I'd like to suggest add a new variable ssh_key_value?

}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module "debianservers" {
vnet_subnet_id = azurerm_subnet.subnet2.id
allocation_method = "Static"
enable_ssh_key = true
ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8GIRF1Snlg9NKCmM74RHXqRGMXyui088+ntQqkQkFIL/BrlgP3CzOgHQmJ+3f0Up/+9UY9vX7AmT7WxVTyqBHT/Aes3VmU3wLO5/MMV/HRrT4z2QV/80futhxjk2unNdWGvbFcR6Y3I44EJFmr8GMbyXRtr0ibuv8BlTYx/K6AXSJ3V+kBqXMOF1QRvVoX9fJKPKjMsebe0cB1IYlm9KLqtciMy+aFOEsSNfrw5cNVsQfK3BgOUKAHsLfBiR7imA2ca+hh005GEtcVJvpvFzcM+bZggUpdqQwIzk1Kv/tROiJiGS0NnyzoxIZYeM3z/mQ5qnglp+174XGCG66EAnVdf5kbaI0Iu7FpAmVhJ92N+MNKoP6vT8cMkYYZf3RaiMMnzjswK/VLbb5ks6Qe9qEPXW1IBtkaaF7+0PCWbPr86I0G2bOa2tFyOHm046Z9sRlkaOO95hmer6Y6MUbMpfeprmjR87u6MVOPglnARfV3UI9i6wOUhVVIi6Wb424HWU="
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here please add a new linux module instance to test ssh_key_value. Because we have ubuntuservers to test enable_ssh_key is false, "debian" to test ssh_key is directory, and we need one more to test ssh_key_value.

extra_ssh_keys = ["monica_id_rsa.pub"]
extra_disks = [
{
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ variable "extra_ssh_keys" {
}

variable "ssh_key" {
description = "Path to the public key to be used for ssh access to the VM. Only used with non-Windows vms and can be left as-is even if using Windows vms. If specifying a path to a certification on a Windows machine to provision a linux vm use the / in the path versus backslash. e.g. c:/home/id_rsa.pub."
description = "Public SSH Key value or path to the public key file (.pub) to be used for ssh access to the VM. Only used with non-Windows vms and can be left as-is even if using Windows vms. If specifying a path to a certification on a Windows machine to provision a linux vm use the / in the path versus backslash. e.g. c:/home/id_rsa.pub."
AliAllomani marked this conversation as resolved.
Show resolved Hide resolved
type = string
default = "~/.ssh/id_rsa.pub"
}
Expand Down