Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions iac/cloud/openstack/lib/openstack-keypair/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ resource "openstack_compute_keypair_v2" "ssh_keypair" {
name = replace(format("%skey", var.naming_prefix), ".", "-")
}

resource "local_file" "private_key" {
content = openstack_compute_keypair_v2.ssh_keypair.private_key
filename = "${path.root}/id_rsa"
file_permission = "0600"
}
resource "null_resource" "save_ssh_keys" {
triggers = {
key_id = openstack_compute_keypair_v2.ssh_keypair.id
}

resource "local_file" "public_key" {
content = openstack_compute_keypair_v2.ssh_keypair.public_key
filename = "${path.root}/id_rsa.pub"
file_permission = "0644"
}
provisioner "local-exec" {
command = <<-EOT
echo '${openstack_compute_keypair_v2.ssh_keypair.private_key}' > ${path.root}/id_rsa
chmod 600 ${path.root}/id_rsa
echo '${openstack_compute_keypair_v2.ssh_keypair.public_key}' > ${path.root}/id_rsa.pub
chmod 644 ${path.root}/id_rsa.pub
EOT
}
}