Skip to content

Commit

Permalink
Add service config options to env-config (#503)
Browse files Browse the repository at this point in the history
* Add env-config settings for service CPU, memory, and desired instance
count
* Set prod to 1 vCPU, 4 GB memory, and 3 instances
* Add instructions

## Context

Add env-config settings for setting an environment's service's CPU,
memory, and desired instance count. This allows a project to have
separate settings for each environment.
  • Loading branch information
lorenyu authored Dec 14, 2023
1 parent bee7558 commit 2b91202
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/infra/set-up-app-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Before setting up the application's environments you'll need to have:

1. [A compatible application in the app folder](https://github.com/navapbc/template-infra/blob/main/template-only-docs/application-requirements.md)
2. [Configure the app](/infra/app/app-config/main.tf). Make sure you update `has_database` to `true` or `false` depending on whether or not your application has a database to integrate with.
1. If you're configuring your production environment, make sure to update the `service_cpu`, `service_memory`, and `service_desired_instance_count` settings based on the project's needs. If your application is sensitive to performance, consider doing a load test.
3. [Create a nondefault VPC to be used by the application](./set-up-network.md)
4. (If the application has a database) [Set up the database for the application](./set-up-database.md)
5. (If you have an incident management service) [Set up monitoring](./set-up-monitoring-alerts.md)
Expand Down
5 changes: 4 additions & 1 deletion infra/app/app-config/env-config/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ output "network_name" {

output "service_config" {
value = {
region = var.default_region
region = var.default_region
cpu = var.service_cpu
memory = var.service_memory
desired_instance_count = var.service_desired_instance_count
}
}

Expand Down
15 changes: 15 additions & 0 deletions infra/app/app-config/env-config/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ variable "has_database" {
variable "has_incident_management_service" {
type = bool
}

variable "service_cpu" {
type = number
default = 256
}

variable "service_memory" {
type = number
default = 512
}

variable "service_desired_instance_count" {
type = number
default = 1
}
7 changes: 7 additions & 0 deletions infra/app/app-config/prod.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ module "prod_config" {
network_name = "prod"
has_database = local.has_database
has_incident_management_service = local.has_incident_management_service

# These numbers are a starting point based on this article
# Update the desired instance size and counts based on the project's specific needs
# https://conchchow.medium.com/aws-ecs-fargate-compute-capacity-planning-a5025cb40bd0
service_cpu = 1024
service_memory = 4096
service_desired_instance_count = 3
}
4 changes: 4 additions & 0 deletions infra/app/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ module "service" {
public_subnet_ids = data.aws_subnets.public.ids
private_subnet_ids = data.aws_subnets.private.ids

cpu = local.service_config.cpu
memory = local.service_config.memory
desired_instance_count = local.service_config.desired_instance_count

aws_services_security_group_id = data.aws_security_groups.aws_services.ids[0]

db_vars = module.app_config.has_database ? {
Expand Down

0 comments on commit 2b91202

Please sign in to comment.