Skip to content

Commit 9fb3540

Browse files
mikeruudevx
authored andcommitted
fix: use null_resource vs local_file for id_rsa (#40)
1 parent 33ecda1 commit 9fb3540

File tree

1 file changed

+13
-10
lines changed
  • iac/cloud/openstack/lib/openstack-keypair

1 file changed

+13
-10
lines changed

iac/cloud/openstack/lib/openstack-keypair/main.tf

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ resource "openstack_compute_keypair_v2" "ssh_keypair" {
22
name = replace(format("%skey", var.naming_prefix), ".", "-")
33
}
44

5-
resource "local_file" "private_key" {
6-
content = openstack_compute_keypair_v2.ssh_keypair.private_key
7-
filename = "${path.root}/id_rsa"
8-
file_permission = "0600"
9-
}
5+
resource "null_resource" "save_ssh_keys" {
6+
triggers = {
7+
key_id = openstack_compute_keypair_v2.ssh_keypair.id
8+
}
109

11-
resource "local_file" "public_key" {
12-
content = openstack_compute_keypair_v2.ssh_keypair.public_key
13-
filename = "${path.root}/id_rsa.pub"
14-
file_permission = "0644"
15-
}
10+
provisioner "local-exec" {
11+
command = <<-EOT
12+
echo '${openstack_compute_keypair_v2.ssh_keypair.private_key}' > ${path.root}/id_rsa
13+
chmod 600 ${path.root}/id_rsa
14+
echo '${openstack_compute_keypair_v2.ssh_keypair.public_key}' > ${path.root}/id_rsa.pub
15+
chmod 644 ${path.root}/id_rsa.pub
16+
EOT
17+
}
18+
}

0 commit comments

Comments
 (0)