我想使用terraform在azure虚拟机上创建一个新的ssh密钥。
我试过了,但不起作用。
provisioner "remote-exec" {
inline = [
"sudo apt-get update",
"cat /dev/zero | ssh-keygen -q -N ''"
]
}
}它会给出这个错误。
azurerm_virtual_machine.terraform-app-VM: Still creating... [5m30s elapsed]
azurerm_virtual_machine.terraform-app-VM (remote-exec): Connecting to remote host via SSH...
azurerm_virtual_machine.terraform-app-VM (remote-exec): Host:
azurerm_virtual_machine.terraform-app-VM (remote-exec): User: root
azurerm_virtual_machine.terraform-app-VM (remote-exec): Password: false
azurerm_virtual_machine.terraform-app-VM (remote-exec): Private key: false
azurerm_virtual_machine.terraform-app-VM (remote-exec): Certificate: false
azurerm_virtual_machine.terraform-app-VM (remote-exec): SSH Agent: true
azurerm_virtual_machine.terraform-app-VM (remote-exec): Checking Host Key: false
azurerm_virtual_machine.terraform-app-VM: Still creating... [5m40s elapsed]
Error: timeout - last error: SSH authentication failed (root@:22): ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain发布于 2019-09-14 09:01:14
您应该使用resource "azurerm_virtual_machine_extension"。它不需要SSH密钥。如下所示:
resource "azurerm_virtual_machine_extension" "test" {
name = "<some_name>"
location = "<resource_group_location>"
resource_group_name = "${azurerm_resource_group.<resource_group>.name}"
virtual_machine_name = "${azurerm_virtual_machine.<vm>.name}"
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.0"
settings = <<SETTINGS
{
"commandToExecute": "<your_command>"
}
SETTINGS
}请注意,这只是一个命令执行。如果您想要执行多个命令,您可以创建一个shell脚本,上载它(以便它可以公开访问),然后执行以下操作:
resource "azurerm_virtual_machine_extension" "test" {
name = "<some_name>"
location = "<resource_group_location>"
resource_group_name = "${azurerm_resource_group.<resource_group>.name}"
virtual_machine_name = "${azurerm_virtual_machine.<vm>.name}"
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.0"
settings = <<SETTINGS
{
"fileUris": ["https://url/to/file/<file>.sh"],
"commandToExecute": "sh <file>.sh"
}
SETTINGS
}https://stackoverflow.com/questions/57928490
复制相似问题