From 26bd0b5bc1d91ef4d3cefa8a473641635e595943 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Thu, 5 Sep 2024 12:31:56 +0000 Subject: [PATCH] TF changes --- yarn-project/aztec/terraform/node/main.tf | 78 ++++++++++++++++++++--- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/yarn-project/aztec/terraform/node/main.tf b/yarn-project/aztec/terraform/node/main.tf index 6304b37ab45..906155087f7 100644 --- a/yarn-project/aztec/terraform/node/main.tf +++ b/yarn-project/aztec/terraform/node/main.tf @@ -126,14 +126,68 @@ resource "aws_efs_mount_target" "public_az2" { security_groups = [data.terraform_remote_state.setup_iac.outputs.security_group_public_id] } + +data "template_file" "user_data" { + count = local.node_count + template = <> /etc/ecs/ecs.config +echo 'ECS_INSTANCE_ATTRIBUTES={"group": "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}"}' >> /etc/ecs/ecs.config +EOF +} + +# Launch template for our prover agents +# 4 cores and 16 GB memory +resource "aws_launch_template" "aztec-node-launch-template" { + count = local.node_count + name = "${var.DEPLOY_TAG}-aztec-node-launch-template-${count.index + 1}" + image_id = "ami-0cd4858f2b923aa6b" + instance_type = "m6a.xlarge" + vpc_security_group_ids = [data.terraform_remote_state.setup_iac.outputs.security_group_private_id] + + iam_instance_profile { + name = data.terraform_remote_state.setup_iac.outputs.ecs_instance_profile_name + } + + key_name = data.terraform_remote_state.setup_iac.outputs.ecs_instance_key_pair_name + + user_data = base64encode(data.template_file.user_data[count.index].rendered) + + tag_specifications { + resource_type = "instance" + tags = { + Name = "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}" + prometheus = "" + } + } +} + +resource "aws_ec2_fleet" "aztec_node_fleet" { + count = local.node_count + launch_template_config { + launch_template_specification { + launch_template_id = aws_launch_template.aztec-node-launch-template[count.index].id + version = aws_launch_template.aztec-node-launch-template[count.index].latest_version + } + } + + target_capacity_specification { + default_target_capacity_type = "on-demand" + total_target_capacity = 1 + spot_target_capacity = 0 + on_demand_target_capacity = 1 + } + + terminate_instances = true + terminate_instances_with_expiration = true +} + # Define task definitions for each node. resource "aws_ecs_task_definition" "aztec-node" { count = local.node_count family = "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}" - requires_compatibilities = ["FARGATE"] + requires_compatibilities = ["EC2"] network_mode = "awsvpc" - cpu = "2048" - memory = "4096" execution_role_arn = data.terraform_remote_state.setup_iac.outputs.ecs_task_execution_role_arn task_role_arn = data.terraform_remote_state.aztec2_iac.outputs.cloudwatch_logging_ecs_role_arn @@ -151,7 +205,8 @@ resource "aws_ecs_task_definition" "aztec-node" { image = "${var.DOCKERHUB_ACCOUNT}/aztec:${var.IMAGE_TAG}" command = ["start", "--node", "--archiver", "--sequencer"] essential = true - memoryReservation = 3776 + cpu = 4096 + memoryReservation = 16384 portMappings = [ { containerPort = 80 @@ -390,17 +445,17 @@ resource "aws_ecs_service" "aztec-node" { count = local.node_count name = "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}" cluster = data.terraform_remote_state.setup_iac.outputs.ecs_cluster_id - launch_type = "FARGATE" + launch_type = "EC2" desired_count = 1 deployment_maximum_percent = 100 deployment_minimum_healthy_percent = 0 - platform_version = "1.4.0" - force_new_deployment = true - enable_execute_command = true + #platform_version = "1.4.0" + force_new_deployment = true + enable_execute_command = true network_configuration { - assign_public_ip = true + #assign_public_ip = true subnets = [ data.terraform_remote_state.setup_iac.outputs.subnet_az1_id ] @@ -419,6 +474,11 @@ resource "aws_ecs_service" "aztec-node" { container_port = 80 } + placement_constraints { + type = "memberOf" + expression = "attribute:group == ${var.DEPLOY_TAG}-aztec-node-${count.index + 1}" + } + task_definition = aws_ecs_task_definition.aztec-node[count.index].family }