terraform: add instance_id to trigger reinstall

This commit is contained in:
Jörg Thalheim 2023-02-22 17:40:56 +01:00
parent ed0ab16c58
commit 29b0f1b5f2
4 changed files with 17 additions and 1 deletions

View File

@ -20,6 +20,7 @@ module "install" {
nixos_system = module.system-build.result.out
ssh_private_key = var.ssh_private_key
debug_logging = var.debug_logging
instance_id = var.instance_id
}
module "nixos-rebuild" {

View File

@ -39,6 +39,12 @@ variable "target_port" {
default = 22
}
variable "instance_id" {
type = string
description = "The instance id of the target_host, used to track when to reinstall the machine"
default = null
}
variable "ssh_private_key" {
type = string
description = "Content of private key used to connect to the target_host"

View File

@ -1,8 +1,11 @@
locals {
nixos_anywhere_flags = "${var.debug_logging ? "--debug" : ""} ${var.kexec_tarball_url != "" ? "--kexec ${var.kexec_tarball_url}" : "" } --store-paths ${var.nixos_partitioner} ${var.nixos_system} ${var.target_user}@${var.target_host}"
nixos_anywhere_flags = "${var.debug_logging ? "--debug" : ""} ${var.kexec_tarball_url != null ? "--kexec ${var.kexec_tarball_url}" : "" } --store-paths ${var.nixos_partitioner} ${var.nixos_system} ${var.target_user}@${var.target_host}"
}
resource "null_resource" "nixos-remote" {
triggers = {
instance_id = var.instance_id
}
provisioner "local-exec" {
environment = {
SSH_PRIVATE_KEY = var.ssh_private_key

View File

@ -39,6 +39,12 @@ variable "ssh_private_key" {
default = ""
}
variable "instance_id" {
type = string
description = "The instance id of the target_host, used to track when to reinstall the machine"
default = null
}
variable "debug_logging" {
type = bool
description = "Enable debug logging"