carlos / platform Public

infra: EC2 auto-recovery alarm on region-host boxes (HA rung 0)

Paul Campbell 3c3fadb24c170eaa4a7b745efb14143df56a19dd parent 53c55aa
2 files changed, +26 −0
  • infra/modules/region-host/main.tf +20 −0
  • infra/modules/region-host/variables.tf +6 −0
diff --git a/infra/modules/region-host/main.tf b/infra/modules/region-host/main.tf
index 21afdcbca..8c0966392 100644
--- a/infra/modules/region-host/main.tf
+++ b/infra/modules/region-host/main.tf
@@ -9,6 +9,8 @@
# not include this region's bucket — a wrong-region wake fails loudly at
# the IAM layer.
+data "aws_region" "current" {}
+
data "aws_ami" "debian_arm64" {
most_recent = true
owners = [var.ami_owner]
@@ -180,3 +182,21 @@ resource "aws_eip" "host" {
instance = aws_instance.host.id
tags = { Name = var.name }
}
+
+# HA ladder rung 0 (2026-08-12 spec): system-status failure recovers the
+# instance onto healthy hardware, keeping instance id, EIP and volumes.
+resource "aws_cloudwatch_metric_alarm" "host_auto_recover" {
+ count = var.enable_auto_recovery ? 1 : 0
+ alarm_name = "${var.name}-auto-recover"
+ namespace = "AWS/EC2"
+ metric_name = "StatusCheckFailed_System"
+ statistic = "Maximum"
+ period = 60
+ evaluation_periods = 2
+ threshold = 1
+ comparison_operator = "GreaterThanOrEqualToThreshold"
+ alarm_actions = ["arn:aws:automate:${data.aws_region.current.name}:ec2:recover"]
+ dimensions = {
+ InstanceId = aws_instance.host.id
+ }
+}
diff --git a/infra/modules/region-host/variables.tf b/infra/modules/region-host/variables.tf
index 5003e4d35..bd84cc76c 100644
--- a/infra/modules/region-host/variables.tf
+++ b/infra/modules/region-host/variables.tf
@@ -76,3 +76,9 @@ variable "route53_zone_ids" {
error_message = "route53_zone_ids entries must be bare hosted-zone ids (Z...), not /hostedzone/-prefixed paths or wildcards."
}
}
+
+variable "enable_auto_recovery" {
+ description = "Arm an EC2 auto-recovery alarm on the host (HA ladder rung 0)."
+ type = bool
+ default = true
+}