From 76273c7b7cdce1ff34dd1d9572ecff8b61643d01 Mon Sep 17 00:00:00 2001 From: Marco Acierno Date: Thu, 28 Mar 2024 10:36:00 +0000 Subject: [PATCH] Change workers/nat instance instance types (#3794) --- .../applications/pycon_backend/worker.tf | 52 ++++++++++++++++--- infrastructure/global/vpc/nat.tf | 2 +- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/infrastructure/applications/pycon_backend/worker.tf b/infrastructure/applications/pycon_backend/worker.tf index a8643f01ad..5d83a41874 100644 --- a/infrastructure/applications/pycon_backend/worker.tf +++ b/infrastructure/applications/pycon_backend/worker.tf @@ -178,6 +178,7 @@ locals { }, ] } + resource "aws_ecs_cluster" "worker" { name = "pythonit-${terraform.workspace}-worker" } @@ -226,9 +227,9 @@ data "template_file" "user_data" { } -resource "aws_instance" "instance" { +resource "aws_instance" "instance_1" { ami = data.aws_ami.ecs.id - instance_type = "t4g.small" + instance_type = "t4g.nano" subnet_id = data.aws_subnet.private_1a.id availability_zone = "eu-central-1a" vpc_security_group_ids = [ @@ -244,7 +245,26 @@ resource "aws_instance" "instance" { tags = { Name = "pythonit-${terraform.workspace}-worker" } +} + +resource "aws_instance" "instance_2" { + ami = data.aws_ami.ecs.id + instance_type = "t4g.nano" + subnet_id = data.aws_subnet.private_1a.id + availability_zone = "eu-central-1a" + vpc_security_group_ids = [ + data.aws_security_group.rds.id, + data.aws_security_group.lambda.id, + aws_security_group.instance.id + ] + source_dest_check = false + user_data = data.template_file.user_data.rendered + iam_instance_profile = aws_iam_instance_profile.worker.name + key_name = "pretix" + tags = { + Name = "pythonit-${terraform.workspace}-worker-2" + } } resource "aws_cloudwatch_log_group" "worker_logs" { @@ -259,8 +279,8 @@ resource "aws_ecs_task_definition" "worker" { { name = "worker" image = "${data.aws_ecr_repository.be_repo.repository_url}@${data.aws_ecr_image.be_arm_image.image_digest}" - cpu = 1024 - memory = 900 + cpu = 2048 + memory = 400 essential = true entrypoint = [ "/home/app/.venv/bin/celery", @@ -300,12 +320,21 @@ resource "aws_ecs_task_definition" "worker" { } stopTimeout = 300 - }, + } + ]) + + requires_compatibilities = [] + tags = {} +} + +resource "aws_ecs_task_definition" "beat" { + family = "pythonit-${terraform.workspace}-beat" + container_definitions = jsonencode([ { name = "beat" image = "${data.aws_ecr_repository.be_repo.repository_url}@${data.aws_ecr_image.be_arm_image.image_digest}" - cpu = 1024 - memory = 900 + cpu = 2048 + memory = 400 essential = true entrypoint = [ "/home/app/.venv/bin/celery", @@ -360,3 +389,12 @@ resource "aws_ecs_service" "worker" { deployment_minimum_healthy_percent = 0 deployment_maximum_percent = 100 } + +resource "aws_ecs_service" "beat" { + name = "pythonit-${terraform.workspace}-beat" + cluster = aws_ecs_cluster.worker.id + task_definition = aws_ecs_task_definition.beat.arn + desired_count = 1 + deployment_minimum_healthy_percent = 0 + deployment_maximum_percent = 100 +} diff --git a/infrastructure/global/vpc/nat.tf b/infrastructure/global/vpc/nat.tf index 972e123001..b42d9faab7 100644 --- a/infrastructure/global/vpc/nat.tf +++ b/infrastructure/global/vpc/nat.tf @@ -26,7 +26,7 @@ resource "aws_eip_association" "nat_ip_assoc" { resource "aws_instance" "nat" { for_each = toset(keys(local.public_azs_cidr)) ami = "ami-001b36cbc16911c13" - instance_type = "t3.nano" + instance_type = "t3a.nano" subnet_id = aws_subnet.public[each.key].id availability_zone = each.key vpc_security_group_ids = [aws_security_group.nat.id]