terraform-azurerm-terraform-enterprise icon indicating copy to clipboard operation
terraform-azurerm-terraform-enterprise copied to clipboard

`import_key` variable does not insert public ssh key into ~/.ssh/authorized_keys

Open scarolan opened this issue 4 years ago • 3 comments

I configured the module below using a variable to define the import_key input:

module "terraform-enterprise" {
  source  = "hashicorp/terraform-enterprise/azurerm"
  version = "0.1.0"
  # insert the 8 required variables here
  domain                        = "${var.domain}"
  key_vault_name                = "${var.key_vault_name}"
  license_file                  = "${var.license_file}"
  tls_pfx_certificate           = "${var.tls_pfx_certificate}"
  tls_pfx_certificate_password  = "${var.tls_pfx_certificate_password}"
  key_vault_resource_group_name = "${var.key_vault_resource_group_name}"
  domain_resource_group_name    = "${var.domain_resource_group_name}"
  resource_group_name           = "${data.terraform_remote_state.azure-tfe-infra.tfe_rg}"
  virtual_network_name          = "${data.terraform_remote_state.azure-tfe-infra.tfe_vnet}"
  subnet                        = "${data.terraform_remote_state.azure-tfe-infra.tfe_subnet}"
  import_key                    = "${var.import_key}"
}

But the VMs never get the content of the import_key variable inserted into ~/.ssh/authorized_keys

scarolan avatar Nov 06 '19 23:11 scarolan

So that variable looks like it might only work on Ubuntu (which is a thing we'll need to call out) but also follows the schema defined here:

https://cloudinit.readthedocs.io/en/latest/topics/modules.html#ssh-import-id

Are you passing the public ssh key in directly?

erindatkinson avatar Nov 06 '19 23:11 erindatkinson

Yes, this needs to be documented more about the format that the value should take, namely conforming to the docs @erindatkinson listed above.

evanphx avatar Nov 07 '19 00:11 evanphx

Can I second what @scarolan has stated above? I have supplied my own public key via the import_key var and the public key is not being inserted into the ~ubuntu/.ssh/authorized_keys file.

I took at a look in the cloud-init-output.log for some ssh content and this is what it came back with:

root@tfe-vpkqok5r-primary-0:/var/log# cat cloud-init-output.log | grep -i ssh
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.
Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.
Your identification has been saved in /etc/ssh/ssh_host_ed25519_key.
Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub.
/tmp/ssh-auth-key-check36ddrtk3.pub is not a public key file.
/tmp/ssh-auth-key-checkxpspvjwr.pub is not a public key file.
/tmp/ssh-auth-key-checkk85nj4m6.pub is not a public key file.
/tmp/ssh-auth-key-checkq5onvx6y.pub is not a public key file.
2019-12-09 02:45:19,010 INFO [0] SSH keys [Authorized]
2019-12-09 02:45:19,011 ERROR No matching keys found for [ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAA/gCfGswRr/BzYSsjEv1kCZ4Pdhc/a/OL2zAf3q+ORYnt2CLVxD/61ptbVRFTnHN2+DBdvWifwivRdIivKWUmQuX7vAQx7oEAs6rgAHlBmjhTy6q8sOZHnW2qz7vXyXKsApR5QfNHU/1RC2GnPTEUn2atD1tz6dA9TzCLhEMWiifxfniaXgSEExtyD8pWhQ6CRz6vtQkBGPY5hCwUChJkfzantTbViCLn8ieGAFYRQ8Ch4XbtixKoP8EhjC73mOSYmgJfHUd9vWf/npDtMkaBHIfCX6rnQU4Chy1Vcyy3HW2B3Ivr9G8jym46BsjdBtd0MxOMsCsP4SvkOqHQlVkz [email protected]]
2019-12-09 02:45:19,012 - util.py[WARNING]: Failed to run command to import ubuntu ssh ids
2019-12-09 02:45:19,039 - util.py[WARNING]: ssh-import-id failed for: ubuntu ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAA/gCfGswRr/BzYSsjEv1kCZ4Pdhc/a/OL2zAf3q+ORYnt2CLVxD/61ptbVRFTnHN2+DBdvWifwivRdIivKWUmQuX7vAQx7oEAs6rgAHlBmjhTy6q8sOZHnW2qz7vXyXKsApR5QfNHU/1RC2GnPTEUn2atD1tz6dA9TzCLhEMWiifxfniaXgSEExtyD8pWhQ6CRz6vtQkBGPY5hCwUChJkfzantTbViCLn8ieGAFYRQ8Ch4XbtixKoP8EhjC73mOSYmgJfHUd9vWf/npDtMkaBHIfCX6rnQU4Chy1Vcyy3HW2B3Ivr9G8jym46BsjdBtd0MxOMsCsP4SvkOqHQlVkz [email protected]']
2019-12-09 02:45:19,040 - util.py[WARNING]: Running module ssh-import-id (<module 'cloudinit.config.cc_ssh_import_id' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_ssh_import_id.py'>) failed

ausfestivus avatar Dec 09 '19 02:12 ausfestivus