Skip to content

Commit ee5c39f

Browse files
bors[bot]jfrochesrounce
authored
Merge #78
78: terraform: allow nixos-rebuild to use specified private key for deployment r=Lassulus a=jfroche Co-authored-by: Jean-François Roche <jfroche@affinitic.be> Co-authored-by: Samuel Rounce <srounce@users.noreply.github.com>
2 parents ad954de + 5adb698 commit ee5c39f

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

terraform/all-in-one/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module "install" {
2222
target_port = var.target_port
2323
nixos_partitioner = module.partitioner-build.result.out
2424
nixos_system = module.system-build.result.out
25-
ssh_private_key = var.ssh_private_key
25+
ssh_private_key = var.install_ssh_key
2626
debug_logging = var.debug_logging
2727
instance_id = var.instance_id
2828
}
@@ -33,6 +33,7 @@ module "nixos-rebuild" {
3333
]
3434
source = "../nixos-rebuild"
3535
nixos_system = module.system-build.result.out
36+
ssh_private_key = var.deployment_ssh_key
3637
target_host = var.target_host
3738
target_user = var.target_user
3839
}

terraform/all-in-one/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ variable "instance_id" {
5151
default = null
5252
}
5353

54-
variable "ssh_private_key" {
54+
variable "install_ssh_key" {
5555
type = string
56-
description = "Content of private key used to connect to the target_host"
56+
description = "Content of private key used to connect to the target_host during initial installation"
57+
default = null
58+
}
59+
60+
variable "deployment_ssh_key" {
61+
type = string
62+
description = "Content of private key used to deploy to the target_host after initial installation. To ensure maximum security, it is advisable to connect to your host using ssh-agent instead of relying on this variable"
5763
default = null
5864
}
5965

terraform/nixos-rebuild/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ resource "null_resource" "nixos-rebuild" {
33
store_path = var.nixos_system
44
}
55
provisioner "local-exec" {
6+
environment = {
7+
SSH_KEY = var.ssh_private_key
8+
}
9+
610
command = "${path.module}/deploy.sh ${var.nixos_system} ${var.target_user}@${var.target_host} ${var.target_port}"
711
}
812
}

terraform/nixos-rebuild/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ variable "target_port" {
1919
description = "SSH port used to connect to the target_host"
2020
default = 22
2121
}
22+
23+
variable "ssh_private_key" {
24+
type = string
25+
description = "Content of private key used to connect to the target_host. If set to - no key is passed to openssh and ssh will back to its own configuration"
26+
default = "-"
27+
}

0 commit comments

Comments
 (0)