about summary refs log tree commit diff
path: root/ops
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-01T14·11+0100
committerclbot <clbot@tvl.fyi>2023-03-03T14·53+0000
commit774194652b57f47197e270c62dabf863e7aa8241 (patch)
treeb340d55686e092aa0dd17f653d3779b2a1beb0c7 /ops
parentc3750079f75662a6d01a79c0a1c6335456b2d40a (diff)
feat(ops/terraform): add trigger to deploy-nixos, remove target_name r/5872
This allows passing in custom triggers to trigger a (re)deploy.

For example, a caller can put an AWS instance ID into the triggers to
cause a redeploy whenever the instance ID has changed.

The `target_name` terraform variable was doing something similar, but
`triggers` is more generic, allowing multiple triggers, without having
to stringify them.

We also don't need to trigger on the attrpath - it can be changed, and
as long as it still evaluates to the same
`data.external.nixos_system.result.drv` (which is checked on every
plan), no redeploy needs to be made.

Change-Id: I94ce787a50830b87b6f53c08e042e4abe4036bdd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8191
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'ops')
-rw-r--r--ops/terraform/deploy-nixos/README.md1
-rw-r--r--ops/terraform/deploy-nixos/main.tf17
2 files changed, 8 insertions, 10 deletions
diff --git a/ops/terraform/deploy-nixos/README.md b/ops/terraform/deploy-nixos/README.md
index a51e6bdb5f..ae876b45b9 100644
--- a/ops/terraform/deploy-nixos/README.md
+++ b/ops/terraform/deploy-nixos/README.md
@@ -21,7 +21,6 @@ deploy is necessary.
 module "deploy_somehost" {
   source              = "git::https://code.tvl.fyi/depot.git:/ops/terraform/deploy-nixos.git"
   attrpath            = "ops.nixos.somehost"
-  target_name         = "somehost"
   target_host         = "somehost.tvl.su"
   target_user         = "someone"
   target_user_ssh_key = tls_private_key.somehost.private_key_pem
diff --git a/ops/terraform/deploy-nixos/main.tf b/ops/terraform/deploy-nixos/main.tf
index d39610327a..4a3dc08f6c 100644
--- a/ops/terraform/deploy-nixos/main.tf
+++ b/ops/terraform/deploy-nixos/main.tf
@@ -14,11 +14,6 @@ variable "attrpath" {
   type        = string
 }
 
-variable "target_name" {
-  description = "unique name of the target machine"
-  type        = string
-}
-
 variable "target_host" {
   description = "address (IP or hostname) at which the target is reachable"
   type        = string
@@ -45,6 +40,12 @@ variable "target_user_ssh_key" {
   sensitive   = true
 }
 
+variable "triggers" {
+  type        = map(string)
+  description = "Triggers for deploy"
+  default     = {}
+}
+
 # Fetch the derivation hash for the NixOS system.
 data "external" "nixos_system" {
   program = ["${path.module}/nixos-eval.sh"]
@@ -96,12 +97,10 @@ resource "null_resource" "nixos_deploy" {
     ]
   }
 
-  triggers = {
+  triggers = merge({
     nixos_drv   = data.external.nixos_system.result.drv
-    attrpath    = var.attrpath
     target_host = var.target_host
-    target_name = var.target_name
-  }
+  }, var.triggers)
 }
 
 output "nixos_drv" {