我试图使用Terraform创建一个Openstack实例,然后,我想用ssh-key配置用户“ ubuntu”。
到目前为止,我正在这样做:
terraform-instances.tf
resource "openstack_compute_keypair_v2" "tf-keypair" {
name = "${var.openstack_keypair}"
public_key = "${file("~/.ssh/id_rsa.pub")}"
}
resource "openstack_compute_instance_v2" "k8s-master" {
name = "k8s-master"
region = "${var.openstack_region}"
image_id = "${var.openstack_image_id}"
flavor_id = "${var.openstack_flavor_id}"
key_pair = "${var.openstack_keypair}"
depends_on = ["openstack_compute_keypair_v2.tf-keypair"]
network {
uuid = "00000000-0000-0000-0000-000000000000"
name = "public"
}
network {
uuid = "11111111-1111-1111-1111-111111111111"
name = "private"
}
}
resource "null_resource" "authkeys" {
depends_on = ["openstack_compute_instance_v2.k8s-master"]
provisioner "file" {
source = "authorized_keys"
destination = "/home/ubuntu/.ssh/authorized_keys"
}
connection {
host = "${openstack_compute_instance_v2.k8s-master.network.0.fixed_ip_v4}"
type = "ssh"
user = "root"
private_key = "${file("~/.ssh/id_rsa")}"
timeout = "45s"
}
}
因此,运行后:
terraform apply
使用我的ssh键为root用户创建实例,但不为ubuntu用户创建实例。
如何为ubuntu用户部署ssh-key?
答案 0 :(得分:0)
我建议使用cloud-init,因为没有任何东西可以放入openstack中(它实际上是使用cloud-init本身来预先植入密钥的。)