Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform: allow nixos-rebuild to use specified private key for deployment #78

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion terraform/all-in-one/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module "install" {
target_port = var.target_port
nixos_partitioner = module.partitioner-build.result.out
nixos_system = module.system-build.result.out
ssh_private_key = var.ssh_private_key
ssh_private_key = var.install_ssh_key
debug_logging = var.debug_logging
instance_id = var.instance_id
}
Expand All @@ -33,6 +33,7 @@ module "nixos-rebuild" {
]
source = "../nixos-rebuild"
nixos_system = module.system-build.result.out
ssh_private_key = var.deployment_ssh_key
target_host = var.target_host
target_user = var.target_user
}
10 changes: 8 additions & 2 deletions terraform/all-in-one/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ variable "instance_id" {
default = null
}

variable "ssh_private_key" {
variable "install_ssh_key" {
type = string
description = "Content of private key used to connect to the target_host"
description = "Content of private key used to connect to the target_host during initial installation"
default = null
}

variable "deployment_ssh_key" {
type = string
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"
default = null
}

Expand Down
4 changes: 4 additions & 0 deletions terraform/nixos-rebuild/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ resource "null_resource" "nixos-rebuild" {
store_path = var.nixos_system
}
provisioner "local-exec" {
environment = {
SSH_KEY = var.ssh_private_key
}

command = "${path.module}/deploy.sh ${var.nixos_system} ${var.target_user}@${var.target_host} ${var.target_port}"
}
}
6 changes: 6 additions & 0 deletions terraform/nixos-rebuild/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ variable "target_port" {
description = "SSH port used to connect to the target_host"
default = 22
}

variable "ssh_private_key" {
type = string
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"
default = "-"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why the dash is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@srounce srounce Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "-" check for though?

Copy link
Contributor

@Lassulus Lassulus Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because not setting the value is more complicated in terraform than setting a dummy value which basically means: "no value"

}