From 4dd0165f0e70eb8bbd3b28ac42bb398130f3eca7 Mon Sep 17 00:00:00 2001 From: Mark Bundschuh Date: Wed, 12 Feb 2025 22:50:24 -0500 Subject: [PATCH] refactor --- Taskfile.yml | 68 +------------------ flake.nix | 1 - .../.terraform.lock.hcl | 0 auth.tf => terraform/auth.tf | 0 ctfd.tf => terraform/ctfd.tf | 0 ecr.tf => terraform/ecr.tf | 0 ecs.tf => terraform/ecs.tf | 0 locals.tf => terraform/locals.tf | 0 main.tf => terraform/main.tf | 0 networking.tf => terraform/networking.tf | 0 traefik.tf => terraform/traefik.tf | 0 11 files changed, 2 insertions(+), 67 deletions(-) rename .terraform.lock.hcl => terraform/.terraform.lock.hcl (100%) rename auth.tf => terraform/auth.tf (100%) rename ctfd.tf => terraform/ctfd.tf (100%) rename ecr.tf => terraform/ecr.tf (100%) rename ecs.tf => terraform/ecs.tf (100%) rename locals.tf => terraform/locals.tf (100%) rename main.tf => terraform/main.tf (100%) rename networking.tf => terraform/networking.tf (100%) rename traefik.tf => terraform/traefik.tf (100%) diff --git a/Taskfile.yml b/Taskfile.yml index 76a9591..4d21a8e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -4,71 +4,7 @@ vars: cluster: "infra2-cluster" tasks: - bastion: - desc: SSH into the bastion host - dir: terraform/out - cmds: - - ssh -i bastion_key.pem admin@$(cat bastion_public_ip) - - traefik: - desc: SSH into the traefik host - dir: terraform/out - cmds: - - ssh -i traefik_key.pem ec2-user@$(cat traefik_public_ip) - - challenges: - desc: List all running ECS tasks by name + ecs-services: + desc: List all running ECS services by name cmds: - aws ecs list-services --cluster {{.cluster }} | jq .serviceArns[] -r | awk -F '/' '{print $NF}' - - connect-to: - desc: get shell in the container running challenge - dir: terraform/out - cmds: - - | - # Check if task_name is set - if [ -z "{{.CLI_ARGS}}" ]; then - echo "Error: task_name is not set. Please provide a valid task name." >&2 - exit 1 - fi - - echo "Fetching task Arn..." - task_arn=$(aws ecs list-tasks --cluster {{.cluster }} --service-name {{.CLI_ARGS}} | jq -r '.taskArns[]') - - echo "Describing tasks for $task_arn..." - container_instance_arn=$(aws ecs describe-tasks --cluster {{.cluster }} --tasks "$task_arn" | jq '.tasks[].containerInstanceArn' -r) - - echo "Describing Container Instances for ARN: $container_instance_arn" - ec2_instance_id=$(aws ecs describe-container-instances --cluster {{.cluster }} --container-instances "$container_instance_arn" | jq '.containerInstances[].ec2InstanceId' -r) - - echo "EC2 Instance ID: $ec2_instance_id" - private_ip=$(aws ec2 describe-instances --instance-ids $ec2_instance_id | jq '.Reservations[].Instances[].PrivateIpAddress' -r) - - echo "Private IP Address: $private_ip" - ssh -o ProxyCommand="ssh -i bastion_key.pem -W %h:%p admin@$(cat bastion_public_ip)" -i challenges_key.pem ec2-user@$private_ip -t 'docker exec -it $(docker ps --filter "name={{.CLI_ARGS}}" | awk "NR==2 {print \$1}") /bin/sh' - - - connect-to-ec2: - desc: ssh into the ec2 instance running the challenge - dir: terraform/out - cmds: - - | - # Check if task_name is set - if [ -z "{{.CLI_ARGS}}" ]; then - echo "Error: task_name is not set. Please provide a valid task name." >&2 - exit 1 - fi - - echo "Fetching task Arn..." - task_arn=$(aws ecs list-tasks --cluster {{.cluster }} --service-name {{.CLI_ARGS}} | jq -r '.taskArns[]') - - echo "Describing tasks for $task_arn..." - container_instance_arn=$(aws ecs describe-tasks --cluster {{.cluster }} --tasks "$task_arn" | jq '.tasks[].containerInstanceArn' -r) - - echo "Describing Container Instances for ARN: $container_instance_arn" - ec2_instance_id=$(aws ecs describe-container-instances --cluster {{.cluster }} --container-instances "$container_instance_arn" | jq '.containerInstances[].ec2InstanceId' -r) - - echo "EC2 Instance ID: $ec2_instance_id" - private_ip=$(aws ec2 describe-instances --instance-ids $ec2_instance_id | jq '.Reservations[].Instances[].PrivateIpAddress' -r) - echo "Private IP Address: $private_ip" - ssh -o ProxyCommand="ssh -i bastion_key.pem -W %h:%p admin@$(cat bastion_public_ip)" -i challenges_key.pem ec2-user@$private_ip \ No newline at end of file diff --git a/flake.nix b/flake.nix index 2bfec91..03d2c98 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,6 @@ terraform terraform-ls go-task - infracost ]; }; } diff --git a/.terraform.lock.hcl b/terraform/.terraform.lock.hcl similarity index 100% rename from .terraform.lock.hcl rename to terraform/.terraform.lock.hcl diff --git a/auth.tf b/terraform/auth.tf similarity index 100% rename from auth.tf rename to terraform/auth.tf diff --git a/ctfd.tf b/terraform/ctfd.tf similarity index 100% rename from ctfd.tf rename to terraform/ctfd.tf diff --git a/ecr.tf b/terraform/ecr.tf similarity index 100% rename from ecr.tf rename to terraform/ecr.tf diff --git a/ecs.tf b/terraform/ecs.tf similarity index 100% rename from ecs.tf rename to terraform/ecs.tf diff --git a/locals.tf b/terraform/locals.tf similarity index 100% rename from locals.tf rename to terraform/locals.tf diff --git a/main.tf b/terraform/main.tf similarity index 100% rename from main.tf rename to terraform/main.tf diff --git a/networking.tf b/terraform/networking.tf similarity index 100% rename from networking.tf rename to terraform/networking.tf diff --git a/traefik.tf b/terraform/traefik.tf similarity index 100% rename from traefik.tf rename to terraform/traefik.tf