Skip to content

Commit 863fc27

Browse files
Prod terraform definitions (#125)
Create prod terraform definitions Deploy to prod redirect ALB requests to CMS strategy page Co-authored-by: Blaine Price <william.price@cms.hhs.gov>
1 parent 2f4c890 commit 863fc27

File tree

6 files changed

+177
-3
lines changed

6 files changed

+177
-3
lines changed

infrastructure/envs/prod/main.tf

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
output "api_alb_dns_name" {
2+
value = module.fhir-api.api_alb_dns_name
3+
}
4+
5+
output "api_db_instance_endpoint" {
6+
value = module.api-db.db_instance_endpoint
7+
}
8+
9+
output "etl_db_instance_endpoint" {
10+
value = module.etl-db.db_instance_endpoint
11+
}

infrastructure/envs/prod/terraform.tfvars

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "region" {
2+
default = "us-east-1"
3+
}
4+
5+
variable "tier" {
6+
default = "prod"
7+
}
8+
9+
variable "migration_image" { default = "596240962403.dkr.ecr.us-east-1.amazonaws.com/npd-east-prod-fhir-api-migrations:latest" }
10+
variable "fhir_api_image" { default = "596240962403.dkr.ecr.us-east-1.amazonaws.com/npd-east-prod-fhir-api:latest" }
11+
variable "redirect_to_strategy_page" { default = true }

infrastructure/modules/fhir-api/main.tf

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ resource "aws_ecs_task_definition" "app" {
235235

236236
# API ECS Service
237237
resource "aws_ecs_service" "app" {
238+
count = var.redirect_to_strategy_page == true ? 0 : 1
238239
name = "${var.account_name}-fhir-api-service"
239240
cluster = var.ecs_cluster_id
240241
task_definition = aws_ecs_task_definition.app.arn
@@ -248,7 +249,7 @@ resource "aws_ecs_service" "app" {
248249
}
249250

250251
load_balancer {
251-
target_group_arn = aws_lb_target_group.fhir_api_tg.arn
252+
target_group_arn = aws_lb_target_group.fhir_api_tg[0].arn
252253
container_name = "${var.account_name}-fhir-api"
253254
container_port = var.fhir_api_port
254255
}
@@ -264,6 +265,7 @@ resource "aws_lb" "fhir_api_alb" {
264265
}
265266

266267
resource "aws_lb_target_group" "fhir_api_tg" {
268+
count = var.redirect_to_strategy_page ? 0 : 1
267269
name = "${var.account_name}-fhir-api-tg"
268270
port = var.fhir_api_port
269271
protocol = "HTTP"
@@ -281,13 +283,30 @@ resource "aws_lb_target_group" "fhir_api_tg" {
281283
}
282284
}
283285

284-
resource "aws_lb_listener" "http" {
286+
resource "aws_lb_listener" "forward_to_task_group" {
287+
count = var.redirect_to_strategy_page ? 0 : 1
285288
load_balancer_arn = aws_lb.fhir_api_alb.arn
286289
port = 80
287290
protocol = "HTTP"
288291

289292
default_action {
290293
type = "forward"
291-
target_group_arn = aws_lb_target_group.fhir_api_tg.arn
294+
target_group_arn = aws_lb_target_group.fhir_api_tg[1].arn
295+
}
296+
}
297+
298+
resource "aws_lb_listener" "forward_to_strategy_page" {
299+
count = var.redirect_to_strategy_page ? 1 : 0
300+
load_balancer_arn = aws_lb.fhir_api_alb.arn
301+
port = 80
302+
protocol = "HTTP"
303+
304+
default_action {
305+
type = "redirect"
306+
redirect {
307+
status_code = "HTTP_302"
308+
host = "www.cms.gov"
309+
path = "/priorities/health-technology-ecosystem/overview"
310+
}
292311
}
293312
}

infrastructure/modules/fhir-api/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ variable "fhir_api_migration_image" {}
44
variable "fhir_api_port" {
55
default = 8000
66
}
7+
variable "redirect_to_strategy_page" {}
78
variable "ecs_cluster_id" {}
89
variable "db" {
910
type = object({

0 commit comments

Comments
 (0)