diff --git a/iac/cloud/openstack/lib/openstack-keypair/main.tf b/iac/cloud/openstack/lib/openstack-keypair/main.tf index 7ecb6d0..1a0f3a9 100644 --- a/iac/cloud/openstack/lib/openstack-keypair/main.tf +++ b/iac/cloud/openstack/lib/openstack-keypair/main.tf @@ -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 + } +} \ No newline at end of file