Skip to content

Commit

Permalink
TF changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilWindle committed Sep 5, 2024
1 parent 53aea9c commit 26bd0b5
Showing 1 changed file with 69 additions and 9 deletions.
78 changes: 69 additions & 9 deletions yarn-project/aztec/terraform/node/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<EOF
#!/bin/bash
echo ECS_CLUSTER=${data.terraform_remote_state.setup_iac.outputs.ecs_cluster_name} >> /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

Expand All @@ -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
Expand Down Expand Up @@ -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
]
Expand All @@ -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
}

Expand Down

0 comments on commit 26bd0b5

Please sign in to comment.