-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip_ssh.tf
52 lines (42 loc) · 1.63 KB
/
ip_ssh.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# SSH keys for admin user
module "sshkey_admin" {
source = "git::https://github.com/Schwitzd/terraform-modules.git//ssh-keygen"
algorithm = "ED25519"
keys_name = local.static_hosts[0].hostname
write_to_file = true
}
resource "routeros_file" "ssh_publickey_admin" {
name = basename(module.sshkey_admin.public_key_filename)
contents = module.sshkey_admin.public_key
}
resource "null_resource" "import_publickey_admin" {
provisioner "local-exec" {
command = <<EOT
ssh ${local.router_user}@${local.router_hostname} '/user/ssh-keys import user=${local.router_user} public-key-file=${routeros_file.ssh_publickey_admin.name} key-owner=${local.router_user}'
EOT
}
depends_on = [routeros_file.ssh_publickey_admin]
}
# SSH for lego user
module "sshkey_lego" {
source = "git::https://github.com/Schwitzd/terraform-modules.git//ssh-keygen"
algorithm = "ED25519"
keys_name = "container_lego"
write_to_file = false
}
resource "routeros_file" "ssh_publickey_lego" {
name = "container_lego.pub"
contents = module.sshkey_lego.public_key
}
resource "routeros_file" "ssh_privatekey_lego" {
name = "${local.containers_path}/lego/ssh/id_ed25519"
contents = module.sshkey_lego.private_key
}
resource "null_resource" "import_publickey_lego" {
provisioner "local-exec" {
command = <<EOT
ssh ${local.router_user}@${local.router_hostname} '/user/ssh-keys import user=${local.users_data.lego.user} public-key-file=${routeros_file.ssh_publickey_lego.name} key-owner=${local.users_data.lego.user}'
EOT
}
depends_on = [routeros_file.ssh_publickey_lego, routeros_system_user.users["lego"]]
}