2

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?

Luis Cacho
  • 21
  • 1
  • 3

1 Answers1

0

I'd suggest going with cloud-init, as there's nothing baked into openstack (and it literally uses cloud-init itself to pre-seed the key).

4b0
  • 21,981
  • 30
  • 95
  • 142
towo
  • 101
  • 3