I'm trying to create a Openstack instance using Terraform, and after that, I want to configure the user "ubuntu" with my ssh-key.
So far I'm doing:
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"
}
}
So after run:
terraform apply
The instance is created, with my ssh-key for the root user, but not with the ubuntu user.
How can I deploy my ssh-key for the ubuntu user?