# Terraform configuration for ISO-20022 Combo Flow infrastructure terraform { required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } provider "aws" { region = var.aws_region } # VPC resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" enable_dns_hostnames = true enable_dns_support = true tags = { Name = "comboflow-vpc" } } # Subnets resource "aws_subnet" "public" { vpc_id = aws_vpc.main.id cidr_block = "10.0.1.0/24" availability_zone = "${var.aws_region}a" tags = { Name = "comboflow-public" } } resource "aws_subnet" "private" { vpc_id = aws_vpc.main.id cidr_block = "10.0.2.0/24" availability_zone = "${var.aws_region}b" tags = { Name = "comboflow-private" } } # RDS PostgreSQL resource "aws_db_instance" "postgres" { identifier = "comboflow-db" engine = "postgres" engine_version = "15.4" instance_class = "db.t3.micro" allocated_storage = 20 max_allocated_storage = 100 storage_encrypted = true db_name = "comboflow" username = "comboflow" password = var.db_password vpc_security_group_ids = [aws_security_group.rds.id] db_subnet_group_name = aws_db_subnet_group.main.name backup_retention_period = 7 backup_window = "03:00-04:00" maintenance_window = "mon:04:00-mon:05:00" skip_final_snapshot = false final_snapshot_identifier = "comboflow-final-snapshot" tags = { Name = "comboflow-database" } } # ElastiCache Redis resource "aws_elasticache_cluster" "redis" { cluster_id = "comboflow-redis" engine = "redis" node_type = "cache.t3.micro" num_cache_nodes = 1 parameter_group_name = "default.redis7" port = 6379 subnet_group_name = aws_elasticache_subnet_group.main.name security_group_ids = [aws_security_group.redis.id] } # ECS Cluster resource "aws_ecs_cluster" "main" { name = "comboflow-cluster" setting { name = "containerInsights" value = "enabled" } } # Load Balancer resource "aws_lb" "main" { name = "comboflow-lb" internal = false load_balancer_type = "application" security_groups = [aws_security_group.lb.id] subnets = [aws_subnet.public.id] enable_deletion_protection = false } # Security Groups resource "aws_security_group" "rds" { name = "comboflow-rds-sg" description = "Security group for RDS" vpc_id = aws_vpc.main.id ingress { from_port = 5432 to_port = 5432 protocol = "tcp" cidr_blocks = [aws_vpc.main.cidr_block] } } resource "aws_security_group" "redis" { name = "comboflow-redis-sg" description = "Security group for Redis" vpc_id = aws_vpc.main.id ingress { from_port = 6379 to_port = 6379 protocol = "tcp" cidr_blocks = [aws_vpc.main.cidr_block] } } resource "aws_security_group" "lb" { name = "comboflow-lb-sg" description = "Security group for Load Balancer" vpc_id = aws_vpc.main.id ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 443 to_port = 443 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"] } } # Variables variable "aws_region" { description = "AWS region" default = "us-east-1" } variable "db_password" { description = "Database password" type = string sensitive = true }