|
| 1 | +terraform { |
| 2 | + required_version = ">= 1.0" |
| 3 | + |
| 4 | + required_providers { |
| 5 | + aws = { |
| 6 | + source = "hashicorp/aws" |
| 7 | + version = "~> 6.0" |
| 8 | + } |
| 9 | + } |
| 10 | + |
| 11 | + backend "s3" { |
| 12 | + bucket = "npd-east-prod-terraform" |
| 13 | + key = "terraform.prod.tfstate" |
| 14 | + region = "us-east-1" |
| 15 | + use_lockfile = true |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +provider "aws" { |
| 20 | + region = var.region |
| 21 | +} |
| 22 | + |
| 23 | +locals { |
| 24 | + account_name = "npd-east-${var.tier}" |
| 25 | +} |
| 26 | + |
| 27 | +data "aws_vpc" "default" { |
| 28 | + filter { |
| 29 | + name = "tag:Name" |
| 30 | + values = [local.account_name] |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +module "networking" { |
| 35 | + source = "../../modules/networking" |
| 36 | + |
| 37 | + vpc_id = data.aws_vpc.default.id |
| 38 | + account_name = local.account_name |
| 39 | +} |
| 40 | + |
| 41 | +# Application Database |
| 42 | +module "api-db" { |
| 43 | + source = "terraform-aws-modules/rds/aws" |
| 44 | + version = "6.12.0" |
| 45 | + |
| 46 | + identifier = "${local.account_name}-fhir-api-db" |
| 47 | + engine = "postgres" |
| 48 | + engine_version = "17" |
| 49 | + family = "postgres17" |
| 50 | + instance_class = "db.t3.micro" |
| 51 | + allocated_storage = 20 |
| 52 | + publicly_accessible = false |
| 53 | + username = "npd" |
| 54 | + db_name = "npd" |
| 55 | + vpc_security_group_ids = [module.networking.db_security_group_id] |
| 56 | + db_subnet_group_name = module.networking.db_subnet_group_name |
| 57 | + backup_retention_period = 7 # Remove automated snapshots after 7 days |
| 58 | + backup_window = "03:00-04:00" # 11PM EST |
| 59 | +} |
| 60 | + |
| 61 | +# ETL Database |
| 62 | +module "etl-db" { |
| 63 | + source = "terraform-aws-modules/rds/aws" |
| 64 | + version = "6.12.0" |
| 65 | + |
| 66 | + identifier = "${local.account_name}-etl-db" |
| 67 | + engine = "postgres" |
| 68 | + engine_version = "17" |
| 69 | + family = "postgres17" |
| 70 | + instance_class = "db.t3.micro" |
| 71 | + allocated_storage = 100 |
| 72 | + publicly_accessible = false |
| 73 | + username = "npd_etl" |
| 74 | + vpc_security_group_ids = [module.networking.db_security_group_id] |
| 75 | + db_subnet_group_name = module.networking.db_subnet_group_name |
| 76 | + backup_retention_period = 7 # Remove automated snapshots after 7 days |
| 77 | + backup_window = "03:00-04:00" # 11PM EST |
| 78 | +} |
| 79 | + |
| 80 | +# ECS Cluster |
| 81 | +module "ecs" { |
| 82 | + source = "terraform-aws-modules/ecs/aws" |
| 83 | + version = "6.6.2" |
| 84 | + |
| 85 | + cluster_name = "${local.account_name}-ecs-cluster" |
| 86 | + default_capacity_provider_strategy = { |
| 87 | + FARGATE = { |
| 88 | + weight = 50 |
| 89 | + base = 20 |
| 90 | + } |
| 91 | + FARGATE_SPOT = { |
| 92 | + weight = 50 |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +# FHIR API Module |
| 98 | +module "fhir-api" { |
| 99 | + source = "../../modules/fhir-api" |
| 100 | + |
| 101 | + account_name = local.account_name |
| 102 | + fhir_api_migration_image = var.migration_image |
| 103 | + fhir_api_image = var.fhir_api_image |
| 104 | + redirect_to_strategy_page = var.redirect_to_strategy_page |
| 105 | + ecs_cluster_id = module.ecs.cluster_id |
| 106 | + db = { |
| 107 | + db_instance_master_user_secret_arn = module.api-db.db_instance_master_user_secret_arn |
| 108 | + db_instance_address = module.api-db.db_instance_address |
| 109 | + db_instance_port = module.api-db.db_instance_port |
| 110 | + db_instance_name = module.api-db.db_instance_name |
| 111 | + } |
| 112 | + networking = { |
| 113 | + db_subnet_ids = module.networking.db_subnet_ids |
| 114 | + public_subnet_ids = module.networking.public_subnet_ids |
| 115 | + alb_security_group_id = module.networking.alb_security_group_id |
| 116 | + api_security_group_id = module.networking.api_security_group_id |
| 117 | + vpc_id = module.networking.vpc_id |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +# ETL Module |
| 122 | +module "etl" { |
| 123 | + source = "../../modules/etl" |
| 124 | + |
| 125 | + account_name = local.account_name |
| 126 | +} |
| 127 | + |
| 128 | +# Frontend Module |
| 129 | +module "frontend" { |
| 130 | + source = "../../modules/frontend" |
| 131 | + account_name = local.account_name |
| 132 | +} |
0 commit comments