mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 00:45:17 -05:00
* feat(ses): implement v1 receipt rule set actions (stored-but-inert)
Add the SES v1 receipt-rule-set management actions: CreateReceiptRuleSet,
DescribeReceiptRuleSet, ListReceiptRuleSets, DeleteReceiptRuleSet,
SetActiveReceiptRuleSet, and DescribeActiveReceiptRuleSet. Floci has no inbound-mail
endpoint, so rule sets are stored inertly — a set never holds any receipt rules and
routes no mail — but the management API round-trips so tools like Terraform can declare
a rule set during bootstrap without hitting UnsupportedOperation.
Behavior matches AWS (verified): RuleSetDoesNotExist for a missing set, AlreadyExists
for a duplicate name, idempotent DeleteReceiptRuleSet, and an empty
DescribeActiveReceiptRuleSet when no rule set is active. Individual receipt rules and
receipt filters are out of scope.
* fix(ses): reject deleting the active receipt rule set and read active state under lock
DeleteReceiptRuleSet removed the active rule set unconditionally; AWS rejects it with
CannotDelete/400 (verified), so reject it and preserve the set. DescribeActiveReceiptRuleSet
read without the lock, so a concurrent set-active replacement (clear-then-set) could expose
its intermediate no-active state; read under receiptRuleSetLock so the reader sees the old or
new active set, never the gap.
* fix(ses): validate the receipt rule set name against AWS's constraints
RuleSetName was only checked for non-blank, so Floci accepted names AWS rejects. Validate
it as AWS does (verified): a character outside ^[a-zA-Z0-9_.-]+$ is a ValidationError, and a
name over 64 characters or that does not start and end with an alphanumeric is an
InvalidParameterValue ("Not a valid ruleSetName"). Applied on create/describe/delete and on
set-active when a name is given.
* chore(ses): tidy receipt rule set import order and record the RuleSetName probe provenance
Address review nits: move the ReceiptRuleSet import into alphabetical position in
SesQueryHandler, and expand the RuleSetName validation comment to record that the
constraints come from probing live SES (the botocore model has no pattern), so the
next reader can re-verify rather than treat them as settled.
439 lines
11 KiB
Terraform
439 lines
11 KiB
Terraform
# NOTE: Keep resource definitions in sync with ../compat-opentofu/main.tf
|
|
|
|
# -- S3 Bucket ------------------------------------------------------------------
|
|
resource "aws_s3_bucket" "app" {
|
|
bucket = "floci-compat-app"
|
|
}
|
|
|
|
resource "aws_s3_bucket_versioning" "app" {
|
|
bucket = aws_s3_bucket.app.id
|
|
versioning_configuration {
|
|
status = "Enabled"
|
|
}
|
|
}
|
|
|
|
# -- SQS Queue -----------------------------------------------------------------
|
|
resource "aws_sqs_queue" "jobs" {
|
|
name = "floci-compat-jobs"
|
|
visibility_timeout_seconds = 30
|
|
message_retention_seconds = 86400
|
|
}
|
|
|
|
resource "aws_sqs_queue" "jobs_dlq" {
|
|
name = "floci-compat-jobs-dlq"
|
|
}
|
|
|
|
resource "aws_sqs_queue_redrive_policy" "jobs" {
|
|
queue_url = aws_sqs_queue.jobs.id
|
|
redrive_policy = jsonencode({
|
|
deadLetterTargetArn = aws_sqs_queue.jobs_dlq.arn
|
|
maxReceiveCount = 3
|
|
})
|
|
}
|
|
|
|
# -- SNS Topic -----------------------------------------------------------------
|
|
resource "aws_sns_topic" "events" {
|
|
name = "floci-compat-events"
|
|
}
|
|
|
|
resource "aws_sns_topic_subscription" "events_to_sqs" {
|
|
topic_arn = aws_sns_topic.events.arn
|
|
protocol = "sqs"
|
|
endpoint = aws_sqs_queue.jobs.arn
|
|
}
|
|
|
|
# -- DynamoDB Table -------------------------------------------------------------
|
|
resource "aws_dynamodb_table" "items" {
|
|
name = "floci-compat-items"
|
|
billing_mode = "PAY_PER_REQUEST"
|
|
hash_key = "pk"
|
|
range_key = "sk"
|
|
|
|
attribute {
|
|
name = "pk"
|
|
type = "S"
|
|
}
|
|
|
|
attribute {
|
|
name = "sk"
|
|
type = "S"
|
|
}
|
|
|
|
ttl {
|
|
attribute_name = "expires_at"
|
|
enabled = true
|
|
}
|
|
|
|
tags = {
|
|
Environment = "compat-test"
|
|
}
|
|
}
|
|
|
|
# -- IAM Role (for Lambda) -----------------------------------------------------
|
|
data "aws_iam_policy_document" "lambda_assume_role" {
|
|
statement {
|
|
actions = ["sts:AssumeRole"]
|
|
effect = "Allow"
|
|
|
|
principals {
|
|
type = "Service"
|
|
identifiers = ["lambda.amazonaws.com"]
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "aws_iam_role" "lambda_exec" {
|
|
name = "floci-compat-lambda-exec"
|
|
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
|
|
}
|
|
|
|
# -- SSM Parameters ------------------------------------------------------------
|
|
resource "aws_ssm_parameter" "db_url" {
|
|
name = "/floci-compat/db-url"
|
|
type = "String"
|
|
value = "jdbc:postgresql://localhost:5432/app"
|
|
}
|
|
|
|
resource "aws_ssm_parameter" "api_key" {
|
|
name = "/floci-compat/api-key"
|
|
type = "SecureString"
|
|
value = "super-secret-key"
|
|
}
|
|
|
|
# -- Secrets Manager -----------------------------------------------------------
|
|
resource "aws_secretsmanager_secret" "db_creds" {
|
|
name = "floci-compat/db-creds"
|
|
}
|
|
|
|
resource "aws_secretsmanager_secret_version" "db_creds" {
|
|
secret_id = aws_secretsmanager_secret.db_creds.id
|
|
secret_string = jsonencode({
|
|
username = "admin"
|
|
password = "s3cret"
|
|
})
|
|
}
|
|
|
|
# -- RDS DB Instance -----------------------------------------------------------
|
|
resource "aws_db_instance" "app" {
|
|
identifier = "floci-compat-db"
|
|
engine = "postgres"
|
|
engine_version = "15"
|
|
instance_class = "db.t3.micro"
|
|
allocated_storage = 20
|
|
username = "admin"
|
|
password = "Password1!"
|
|
skip_final_snapshot = true
|
|
}
|
|
|
|
# -- Outputs -------------------------------------------------------------------
|
|
output "bucket_id" {
|
|
value = aws_s3_bucket.app.id
|
|
}
|
|
|
|
output "queue_url" {
|
|
value = aws_sqs_queue.jobs.url
|
|
}
|
|
|
|
output "topic_arn" {
|
|
value = aws_sns_topic.events.arn
|
|
}
|
|
|
|
output "table_name" {
|
|
value = aws_dynamodb_table.items.name
|
|
}
|
|
|
|
output "secret_arn" {
|
|
value = aws_secretsmanager_secret.db_creds.arn
|
|
}
|
|
|
|
# -- Cognito User Pool ---------------------------------------------------------
|
|
resource "aws_cognito_user_pool" "pool" {
|
|
name = "floci-compat-pool"
|
|
|
|
password_policy {
|
|
minimum_length = 12
|
|
require_lowercase = true
|
|
require_numbers = true
|
|
require_symbols = true
|
|
require_uppercase = true
|
|
}
|
|
|
|
auto_verified_attributes = ["email"]
|
|
username_attributes = ["email"]
|
|
|
|
admin_create_user_config {
|
|
allow_admin_create_user_only = false
|
|
}
|
|
|
|
verification_message_template {
|
|
default_email_option = "CONFIRM_WITH_CODE"
|
|
email_message = "Your code is {####}"
|
|
email_subject = "Verify your account"
|
|
}
|
|
|
|
account_recovery_setting {
|
|
recovery_mechanism {
|
|
name = "verified_email"
|
|
priority = 1
|
|
}
|
|
}
|
|
}
|
|
|
|
output "user_pool_id" {
|
|
value = aws_cognito_user_pool.pool.id
|
|
}
|
|
|
|
output "user_pool_arn" {
|
|
value = aws_cognito_user_pool.pool.arn
|
|
}
|
|
|
|
# -- Cognito User Pool Client --------------------------------------------------
|
|
resource "aws_cognito_user_pool_client" "client" {
|
|
name = "floci-compat-pool-client"
|
|
user_pool_id = aws_cognito_user_pool.pool.id
|
|
}
|
|
|
|
# -- CloudWatch Alarms ---------------------------------------------------------
|
|
resource "aws_cloudwatch_metric_alarm" "cpu" {
|
|
alarm_name = "floci-compat-cpu-alarm"
|
|
comparison_operator = "GreaterThanThreshold"
|
|
evaluation_periods = 1
|
|
metric_name = "CPUUtilization"
|
|
namespace = "AWS/EC2"
|
|
period = 60
|
|
statistic = "Average"
|
|
threshold = 80
|
|
alarm_description = "CPU alarm for compat test"
|
|
|
|
tags = {
|
|
env = "compat-test"
|
|
}
|
|
}
|
|
|
|
output "alarm_arn" {
|
|
value = aws_cloudwatch_metric_alarm.cpu.arn
|
|
}
|
|
|
|
# -- VPC networking (issues #468, #401: VpcAttribute, RouteTableAssociation, DescribeTags) ------
|
|
resource "aws_vpc" "compat" {
|
|
cidr_block = "10.0.0.0/16"
|
|
enable_dns_support = false
|
|
enable_dns_hostnames = false
|
|
|
|
tags = {
|
|
Name = "floci-compat-vpc"
|
|
Environment = "compat-test"
|
|
}
|
|
}
|
|
|
|
resource "aws_internet_gateway" "compat" {
|
|
vpc_id = aws_vpc.compat.id
|
|
|
|
tags = {
|
|
Name = "floci-compat-igw"
|
|
}
|
|
}
|
|
|
|
resource "aws_subnet" "compat" {
|
|
vpc_id = aws_vpc.compat.id
|
|
cidr_block = "10.0.1.0/24"
|
|
availability_zone = "us-east-1a"
|
|
|
|
tags = {
|
|
Name = "floci-compat-subnet"
|
|
}
|
|
}
|
|
|
|
resource "aws_route_table" "compat" {
|
|
vpc_id = aws_vpc.compat.id
|
|
|
|
route {
|
|
cidr_block = "0.0.0.0/0"
|
|
gateway_id = aws_internet_gateway.compat.id
|
|
}
|
|
|
|
tags = {
|
|
Name = "floci-compat-rt"
|
|
}
|
|
}
|
|
|
|
# Exercises AssociateRouteTable + DescribeRouteTables(association.route-table-association-id)
|
|
resource "aws_route_table_association" "compat" {
|
|
subnet_id = aws_subnet.compat.id
|
|
route_table_id = aws_route_table.compat.id
|
|
}
|
|
|
|
resource "aws_security_group" "compat" {
|
|
name = "floci-compat-sg"
|
|
description = "Compat test security group"
|
|
vpc_id = aws_vpc.compat.id
|
|
|
|
ingress {
|
|
from_port = 80
|
|
to_port = 80
|
|
protocol = "tcp"
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
}
|
|
|
|
egress {
|
|
from_port = 0
|
|
to_port = 0
|
|
protocol = "-1"
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
}
|
|
|
|
tags = {
|
|
Name = "floci-compat-sg"
|
|
}
|
|
}
|
|
|
|
output "vpc_id" {
|
|
value = aws_vpc.compat.id
|
|
}
|
|
|
|
output "subnet_id" {
|
|
value = aws_subnet.compat.id
|
|
}
|
|
|
|
output "route_table_id" {
|
|
value = aws_route_table.compat.id
|
|
}
|
|
|
|
output "security_group_id" {
|
|
value = aws_security_group.compat.id
|
|
}
|
|
|
|
# -- Route53 -------------------------------------------------------------------
|
|
resource "aws_route53_zone" "compat" {
|
|
name = "floci-compat.internal"
|
|
force_destroy = true
|
|
|
|
tags = {
|
|
Environment = "compat-test"
|
|
}
|
|
}
|
|
|
|
resource "aws_route53_record" "app" {
|
|
zone_id = aws_route53_zone.compat.zone_id
|
|
name = "app.floci-compat.internal"
|
|
type = "A"
|
|
ttl = 300
|
|
records = ["10.0.1.10"]
|
|
}
|
|
|
|
resource "aws_route53_health_check" "app" {
|
|
fqdn = "app.floci-compat.internal"
|
|
port = 80
|
|
type = "HTTP"
|
|
resource_path = "/health"
|
|
failure_threshold = 3
|
|
request_interval = 30
|
|
|
|
tags = {
|
|
Environment = "compat-test"
|
|
}
|
|
}
|
|
|
|
output "zone_id" {
|
|
value = aws_route53_zone.compat.zone_id
|
|
}
|
|
|
|
output "health_check_id" {
|
|
value = aws_route53_health_check.app.id
|
|
}
|
|
|
|
# -- Kinesis Firehose Delivery Stream (extended_s3, issue #1043) ---------------
|
|
resource "aws_kinesis_firehose_delivery_stream" "events" {
|
|
name = "floci-compat-firehose"
|
|
destination = "extended_s3"
|
|
|
|
extended_s3_configuration {
|
|
role_arn = aws_iam_role.lambda_exec.arn
|
|
bucket_arn = aws_s3_bucket.app.arn
|
|
prefix = "events/data/"
|
|
error_output_prefix = "events/errors/"
|
|
compression_format = "GZIP"
|
|
buffering_size = 64
|
|
buffering_interval = 120
|
|
}
|
|
|
|
tags = {
|
|
Environment = "compat-test"
|
|
}
|
|
}
|
|
|
|
output "firehose_stream_arn" {
|
|
value = aws_kinesis_firehose_delivery_stream.events.arn
|
|
}
|
|
|
|
# -- Application Auto Scaling (scalable target + target-tracking policies) -----
|
|
resource "aws_appautoscaling_target" "ecs_service" {
|
|
max_capacity = 20
|
|
min_capacity = 2
|
|
resource_id = "service/floci-compat-cluster/floci-compat-service"
|
|
scalable_dimension = "ecs:service:DesiredCount"
|
|
service_namespace = "ecs"
|
|
|
|
tags = {
|
|
Environment = "compat-test"
|
|
}
|
|
}
|
|
|
|
resource "aws_appautoscaling_policy" "ecs_cpu" {
|
|
name = "floci-compat-cpu-tracking"
|
|
policy_type = "TargetTrackingScaling"
|
|
resource_id = aws_appautoscaling_target.ecs_service.resource_id
|
|
scalable_dimension = aws_appautoscaling_target.ecs_service.scalable_dimension
|
|
service_namespace = aws_appautoscaling_target.ecs_service.service_namespace
|
|
|
|
target_tracking_scaling_policy_configuration {
|
|
predefined_metric_specification {
|
|
predefined_metric_type = "ECSServiceAverageCPUUtilization"
|
|
}
|
|
target_value = 65
|
|
}
|
|
}
|
|
|
|
# resource_label round-trips only if every nested field is echoed back, so this
|
|
# resource is the canary for target-tracking drift.
|
|
resource "aws_appautoscaling_policy" "ecs_alb_requests" {
|
|
name = "floci-compat-alb-request-count"
|
|
policy_type = "TargetTrackingScaling"
|
|
resource_id = aws_appautoscaling_target.ecs_service.resource_id
|
|
scalable_dimension = aws_appautoscaling_target.ecs_service.scalable_dimension
|
|
service_namespace = aws_appautoscaling_target.ecs_service.service_namespace
|
|
|
|
target_tracking_scaling_policy_configuration {
|
|
target_value = 1000
|
|
scale_in_cooldown = 240
|
|
scale_out_cooldown = 60
|
|
|
|
predefined_metric_specification {
|
|
predefined_metric_type = "ALBRequestCountPerTarget"
|
|
resource_label = "app/floci-compat-alb/abc123/targetgroup/floci-compat-tg/def456"
|
|
}
|
|
}
|
|
}
|
|
|
|
output "appautoscaling_target_arn" {
|
|
value = aws_appautoscaling_target.ecs_service.arn
|
|
}
|
|
|
|
output "appautoscaling_alb_policy_arn" {
|
|
value = aws_appautoscaling_policy.ecs_alb_requests.arn
|
|
}
|
|
|
|
# ── SES Receipt Rule Set ───────────────────────────────────────────────────
|
|
# floci stores it inertly (no inbound-mail routing); the management API just round-trips.
|
|
resource "aws_ses_receipt_rule_set" "compat" {
|
|
rule_set_name = "floci-compat-rule-set"
|
|
}
|
|
|
|
resource "aws_ses_active_receipt_rule_set" "compat" {
|
|
rule_set_name = aws_ses_receipt_rule_set.compat.rule_set_name
|
|
}
|
|
|
|
output "ses_rule_set_name" {
|
|
value = aws_ses_receipt_rule_set.compat.rule_set_name
|
|
}
|