| new file mode 100644 |
| index 000000000..bc6084714 |
| --- /dev/null |
| +++ b/infra/modules/region-host/tests/alerts_topic.tftest.hcl |
| @@ -0,0 +1,569 @@ |
| +mock_provider "aws" { |
| + mock_resource "aws_launch_template" { defaults = { id = "lt-0123456789abcdef0" } } |
| + mock_resource "aws_security_group" { defaults = { id = "sg-0123456789abcdef1" } } |
| +} |
| +override_data { |
| + target = data.aws_region.current |
| + values = { region = "eu-west-1" } |
| +} |
| +override_data { |
| + target = data.aws_partition.current |
| + values = { partition = "aws", dns_suffix = "amazonaws.com" } |
| +} |
| +override_data { |
| + target = data.aws_caller_identity.current |
| + values = { account_id = "123456789012" } |
| +} |
| +override_data { |
| + target = data.aws_vpc.host |
| + values = { cidr_block = "10.0.0.0/16", cidr_block_associations = [] } |
| +} |
| +override_data { |
| + target = data.aws_subnets.group |
| + values = { ids = ["subnet-00000000000000001", "subnet-00000000000000002"] } |
| +} |
| +override_data { |
| + target = data.aws_route_table.group |
| + values = { routes = [{ cidr_block = "0.0.0.0/0", gateway_id = "igw-0123456789abcdef0", carrier_gateway_id = "", core_network_arn = "", destination_prefix_list_id = "", egress_only_gateway_id = "", instance_id = "", ipv6_cidr_block = "", local_gateway_id = "", nat_gateway_id = "", network_interface_id = "", odb_network_arn = "", transit_gateway_id = "", vpc_endpoint_id = "", vpc_peering_connection_id = "" }] } |
| +} |
| +override_data { |
| + target = data.aws_lb.group |
| + values = { |
| + vpc_id = "vpc-0123456789abcdef0" |
| + internal = false |
| + load_balancer_type = "network" |
| + ip_address_type = "ipv4" |
| + enable_cross_zone_load_balancing = true |
| + security_groups = ["sg-0123456789abcdef0"] |
| + subnet_mapping = [ |
| + { subnet_id = "subnet-00000000000000001", allocation_id = "eipalloc-00000000000000001", ipv6_address = "", outpost_id = "", private_ipv4_address = "" }, |
| + { subnet_id = "subnet-00000000000000002", allocation_id = "eipalloc-00000000000000002", ipv6_address = "", outpost_id = "", private_ipv4_address = "" } |
| + ] |
| + } |
| +} |
| +override_data { |
| + target = data.aws_lb_target_group.group_http |
| + values = { vpc_id = "vpc-0123456789abcdef0", port = 80, protocol = "TCP", target_type = "instance", load_balancer_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234"], preserve_client_ip = "true" } |
| +} |
| +override_data { |
| + target = data.aws_lb_target_group.group_https |
| + values = { vpc_id = "vpc-0123456789abcdef0", port = 443, protocol = "TCP", target_type = "instance", load_balancer_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234"], preserve_client_ip = "true" } |
| +} |
| +override_data { |
| + target = data.aws_eip.group["eu-west-1a"] |
| + values = { public_ip = "198.51.100.10" } |
| +} |
| +override_data { |
| + target = data.aws_eip.group["eu-west-1b"] |
| + values = { public_ip = "198.51.100.11" } |
| +} |
| +override_resource { |
| + target = aws_sqs_queue.terminations |
| + values = { arn = "arn:aws:sqs:eu-west-1:123456789012:carlos-dev-ie-group-terminations", id = "https://sqs.eu-west-1.amazonaws.com/123456789012/carlos-dev-ie-group-terminations" } |
| +} |
| +override_resource { |
| + target = aws_cloudwatch_event_rule.terminations |
| + values = { arn = "arn:aws:events:eu-west-1:123456789012:rule/carlos-dev-ie-group-terminations" } |
| +} |
| +override_resource { |
| + target = aws_iam_role.host |
| + values = { id = "carlos-dev-ie-group", arn = "arn:aws:iam::123456789012:role/carlos-dev-ie-group" } |
| +} |
| +variables { |
| + mode = "group" |
| + name = "carlos-dev-ie-group" |
| + iam_name = "carlos-dev-ie-group" |
| + sg_description = "test group" |
| + instance_type = "t4g.micro" |
| + root_volume_size = 20 |
| + user_data = "" |
| + deployment_bucket_arn = "arn:aws:s3:::carlos-dev-platform" |
| + data_bucket_arn = "arn:aws:s3:::carlos-dev-ie" |
| + ssm_parameter_arn = "" |
| + vpc_id = "vpc-0123456789abcdef0" |
| + box_count = 2 |
| + group_config = { |
| + deployment = "dev" |
| + region = "ie" |
| + placement_region = "ie" |
| + pools = ["default"] |
| + ami_id = "ami-0123456789abcdef0" |
| + release = "v0.100.0" |
| + configuration_kms_key_arn = "arn:aws:kms:eu-west-1:123456789012:key/00000000-0000-0000-0000-000000000001" |
| + } |
| + group_zones = { |
| + eu-west-1a = { subnet_id = "subnet-00000000000000001", allocation_id = "eipalloc-00000000000000001" } |
| + eu-west-1b = { subnet_id = "subnet-00000000000000002", allocation_id = "eipalloc-00000000000000002" } |
| + } |
| + group_ingress = { |
| + nlb_arn = "arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234" |
| + nlb_security_group_id = "sg-0123456789abcdef0" |
| + target_group_arns = { |
| + "80" = "arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/test-80/1234" |
| + "443" = "arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/test-443/1234" |
| + } |
| + public_ips = { eu-west-1a = "198.51.100.10", eu-west-1b = "198.51.100.11" } |
| + } |
| +} |
| + |
| +override_data { |
| + target = data.aws_ami.group |
| + values = { id = "ami-0123456789abcdef0", root_device_name = "/dev/xvda", root_device_type = "ebs" } |
| +} |
| +override_data { |
| + target = data.aws_ami.debian_arm64 |
| + values = { id = "ami-0123456789abcdef0" } |
| +} |
| +override_resource { |
| + target = aws_instance.host |
| + values = { id = "i-0123456789abcdef0" } |
| +} |
| +override_resource { |
| + target = aws_security_group.host |
| + values = { id = "sg-0123456789abcdef0" } |
| +} |
| +override_resource { |
| + target = aws_sns_topic.alerts |
| + values = { arn = "arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts" } |
| +} |
| + |
| +override_resource { |
| + target = aws_cloudwatch_event_rule.group_launch_failed |
| + values = { arn = "arn:aws:events:eu-west-1:123456789012:rule/carlos-dev-ie-group-launch-failed" } |
| +} |
| + |
| +run "fixed_existing_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 0 && length(aws_sns_topic_subscription.alerts_email) == 0 && length(aws_sns_topic_policy.group_launch_failed) == 0 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 1 && length(aws_cloudwatch_event_target.group_launch_failed) == 0 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.host_memory_low[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && aws_cloudwatch_metric_alarm.host_memory_low[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) |
| + error_message = "fixed memory notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 1 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| + assert { |
| + condition = aws_iam_role_policy.alert_publish[0].role == aws_iam_role.host.id && aws_iam_role_policy.alert_publish[0].policy == jsonencode({ |
| + Version = "2012-10-17" |
| + Statement = [{ Effect = "Allow", Action = ["sns:Publish"], Resource = sort(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) }] |
| + }) |
| + error_message = "host role must receive only publish access to the exact selected topics" |
| + } |
| +} |
| + |
| +run "fixed_email_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + alerts_email = "ops@example.com" |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 1 && length(aws_sns_topic_subscription.alerts_email) == 1 && length(aws_sns_topic_policy.group_launch_failed) == 0 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == "arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts" |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) && aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 1 && length(aws_cloudwatch_event_target.group_launch_failed) == 0 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.host_memory_low[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) && aws_cloudwatch_metric_alarm.host_memory_low[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) |
| + error_message = "fixed memory notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = aws_sns_topic_subscription.alerts_email[0].topic_arn == "arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts" && aws_sns_topic_subscription.alerts_email[0].protocol == "email" && aws_sns_topic_subscription.alerts_email[0].endpoint == "ops@example.com" |
| + error_message = "email path must retain its topic and subscription" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 1 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| + assert { |
| + condition = aws_iam_role_policy.alert_publish[0].role == aws_iam_role.host.id && aws_iam_role_policy.alert_publish[0].policy == jsonencode({ |
| + Version = "2012-10-17" |
| + Statement = [{ Effect = "Allow", Action = ["sns:Publish"], Resource = sort(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) }] |
| + }) |
| + error_message = "host role must receive only publish access to the exact selected topics" |
| + } |
| +} |
| + |
| +run "fixed_disabled_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 0 && length(aws_sns_topic_subscription.alerts_email) == 0 && length(aws_sns_topic_policy.group_launch_failed) == 0 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == null |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions) == 0 && length(aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions) == 0 |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 0 && length(aws_cloudwatch_event_target.group_launch_failed) == 0 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 0 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| +} |
| + |
| +run "fixed_existing_union_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + alert_publish_topic_arns = ["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts", "arn:aws:sns:eu-west-1:123456789012:additional-alerts"] |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 0 && length(aws_sns_topic_subscription.alerts_email) == 0 && length(aws_sns_topic_policy.group_launch_failed) == 0 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 1 && length(aws_cloudwatch_event_target.group_launch_failed) == 0 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.host_memory_low[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && aws_cloudwatch_metric_alarm.host_memory_low[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) |
| + error_message = "fixed memory notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 1 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| + assert { |
| + condition = aws_iam_role_policy.alert_publish[0].role == aws_iam_role.host.id && aws_iam_role_policy.alert_publish[0].policy == jsonencode({ |
| + Version = "2012-10-17" |
| + Statement = [{ Effect = "Allow", Action = ["sns:Publish"], Resource = sort(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts", "arn:aws:sns:eu-west-1:123456789012:additional-alerts"]) }] |
| + }) |
| + error_message = "host role must receive only publish access to the exact selected topics" |
| + } |
| +} |
| + |
| +run "group_existing_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 0 && length(aws_sns_topic_subscription.alerts_email) == 0 && length(aws_sns_topic_policy.group_launch_failed) == 0 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 0 && length(aws_cloudwatch_event_target.group_launch_failed) == 1 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = alltrue([for alarm in [aws_cloudwatch_metric_alarm.group_capacity[0], aws_cloudwatch_metric_alarm.group_memory[0], aws_cloudwatch_metric_alarm.group_clock[0], aws_cloudwatch_metric_alarm.group_clock_missing[0], aws_cloudwatch_metric_alarm.group_suspect_holder[0]] : alarm.alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && alarm.ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"])]) |
| + error_message = "all group alarm and recovery notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_event_target.group_launch_failed[0].arn == "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" && aws_cloudwatch_event_target.group_launch_failed[0].rule == aws_cloudwatch_event_rule.group_launch_failed[0].name |
| + error_message = "launch failure notifications must use the selected topic and rule" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 1 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| + assert { |
| + condition = aws_iam_role_policy.alert_publish[0].role == aws_iam_role.host.id && aws_iam_role_policy.alert_publish[0].policy == jsonencode({ |
| + Version = "2012-10-17" |
| + Statement = [{ Effect = "Allow", Action = ["sns:Publish"], Resource = sort(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) }] |
| + }) |
| + error_message = "host role must receive only publish access to the exact selected topics" |
| + } |
| +} |
| + |
| +run "group_email_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + alerts_email = "ops@example.com" |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 1 && length(aws_sns_topic_subscription.alerts_email) == 1 && length(aws_sns_topic_policy.group_launch_failed) == 1 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == "arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts" |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) && aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 0 && length(aws_cloudwatch_event_target.group_launch_failed) == 1 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = alltrue([for alarm in [aws_cloudwatch_metric_alarm.group_capacity[0], aws_cloudwatch_metric_alarm.group_memory[0], aws_cloudwatch_metric_alarm.group_clock[0], aws_cloudwatch_metric_alarm.group_clock_missing[0], aws_cloudwatch_metric_alarm.group_suspect_holder[0]] : alarm.alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) && alarm.ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"])]) |
| + error_message = "all group alarm and recovery notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_event_target.group_launch_failed[0].arn == "arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts" && aws_cloudwatch_event_target.group_launch_failed[0].rule == aws_cloudwatch_event_rule.group_launch_failed[0].name |
| + error_message = "launch failure notifications must use the selected topic and rule" |
| + } |
| + assert { |
| + condition = aws_sns_topic_subscription.alerts_email[0].topic_arn == "arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts" && aws_sns_topic_subscription.alerts_email[0].protocol == "email" && aws_sns_topic_subscription.alerts_email[0].endpoint == "ops@example.com" |
| + error_message = "email path must retain its topic and subscription" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 1 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| + assert { |
| + condition = aws_iam_role_policy.alert_publish[0].role == aws_iam_role.host.id && aws_iam_role_policy.alert_publish[0].policy == jsonencode({ |
| + Version = "2012-10-17" |
| + Statement = [{ Effect = "Allow", Action = ["sns:Publish"], Resource = sort(["arn:aws:sns:eu-west-1:123456789012:carlos-dev-ie-group-alerts"]) }] |
| + }) |
| + error_message = "host role must receive only publish access to the exact selected topics" |
| + } |
| +} |
| + |
| +run "group_disabled_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 0 && length(aws_sns_topic_subscription.alerts_email) == 0 && length(aws_sns_topic_policy.group_launch_failed) == 0 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == null |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions) == 0 && length(aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions) == 0 |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 0 && length(aws_cloudwatch_event_target.group_launch_failed) == 0 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = alltrue([for alarm in [aws_cloudwatch_metric_alarm.group_capacity[0], aws_cloudwatch_metric_alarm.group_memory[0], aws_cloudwatch_metric_alarm.group_clock[0], aws_cloudwatch_metric_alarm.group_clock_missing[0], aws_cloudwatch_metric_alarm.group_suspect_holder[0]] : length(alarm.alarm_actions) == 0 && length(alarm.ok_actions) == 0]) |
| + error_message = "all group alarm and recovery notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 0 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| +} |
| + |
| +run "group_existing_union_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + alert_publish_topic_arns = ["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts", "arn:aws:sns:eu-west-1:123456789012:additional-alerts"] |
| + } |
| + assert { |
| + condition = length(aws_sns_topic.alerts) == 0 && length(aws_sns_topic_subscription.alerts_email) == 0 && length(aws_sns_topic_policy.group_launch_failed) == 0 |
| + error_message = "topic ownership must remain with the selected source" |
| + } |
| + assert { |
| + condition = output.alerts_topic_arn == "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + error_message = "output must return the selected topic or null" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_metric_alarm.termination_queue_age[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && aws_cloudwatch_metric_alarm.termination_queue_age[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) |
| + error_message = "termination queue notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.host_memory_low) == 0 && length(aws_cloudwatch_event_target.group_launch_failed) == 1 |
| + error_message = "notification resources must follow the mode and topic selection" |
| + } |
| + assert { |
| + condition = alltrue([for alarm in [aws_cloudwatch_metric_alarm.group_capacity[0], aws_cloudwatch_metric_alarm.group_memory[0], aws_cloudwatch_metric_alarm.group_clock[0], aws_cloudwatch_metric_alarm.group_clock_missing[0], aws_cloudwatch_metric_alarm.group_suspect_holder[0]] : alarm.alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) && alarm.ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"])]) |
| + error_message = "all group alarm and recovery notifications must use the selected topic" |
| + } |
| + assert { |
| + condition = aws_cloudwatch_event_target.group_launch_failed[0].arn == "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" && aws_cloudwatch_event_target.group_launch_failed[0].rule == aws_cloudwatch_event_rule.group_launch_failed[0].name |
| + error_message = "launch failure notifications must use the selected topic and rule" |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.alert_publish) == 1 |
| + error_message = "publish grant must follow the configured topic" |
| + } |
| + assert { |
| + condition = aws_iam_role_policy.alert_publish[0].role == aws_iam_role.host.id && aws_iam_role_policy.alert_publish[0].policy == jsonencode({ |
| + Version = "2012-10-17" |
| + Statement = [{ Effect = "Allow", Action = ["sns:Publish"], Resource = sort(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts", "arn:aws:sns:eu-west-1:123456789012:additional-alerts"]) }] |
| + }) |
| + error_message = "host role must receive only publish access to the exact selected topics" |
| + } |
| +} |
| + |
| +run "fixed_conflict_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + alerts_email = "ops@example.com" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |
| + |
| +run "fixed_wildcard_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts*" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |
| + |
| +run "fixed_subscription_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts:subscription" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |
| + |
| +run "fixed_wrong_region_topic" { |
| + command = plan |
| + variables { |
| + mode = "fixed" |
| + user_data = "#!/bin/sh\n" |
| + subnet_id = "subnet-00000000000000001" |
| + group_config = null |
| + group_zones = {} |
| + group_ingress = null |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:us-east-1:123456789012:permanent-ha-alerts" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |
| + |
| +run "group_conflict_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts" |
| + alerts_email = "ops@example.com" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |
| + |
| +run "group_wildcard_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts*" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |
| + |
| +run "group_subscription_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts:subscription" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |
| + |
| +run "group_wrong_region_topic" { |
| + command = plan |
| + variables { |
| + termination_queue_alarm = true |
| + alerts_topic_arn = "arn:aws:sns:us-east-1:123456789012:permanent-ha-alerts" |
| + } |
| + expect_failures = [var.alerts_topic_arn] |
| +} |