Removing atlas host

This commit is contained in:
shockrah 2022-12-09 21:49:17 -08:00
parent 9d426917f7
commit 6212a7d8cc
3 changed files with 101 additions and 70 deletions

View File

@ -5,16 +5,66 @@
# Logging Configuration for services inside the cluster # Logging Configuration for services inside the cluster
####################################################### #######################################################
resource "aws_cloudwatch_log_group" "alpha" { locals {
name = "alpha-log" subnet = "subnet-09302319a6678643f"
} }
# Alpha Cloudwatch logging configuration
########################################
resource "aws_cloudwatch_log_group" "alpha" {
name = "${var.athens_prefix}-alpha-log"
retention_in_days = 7
}
# Alpha logging role
#####################
resource "aws_iam_role" "alpha_iam_role" {
name = "${var.athens_prefix}-alpha-iam-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = [ "ecs-tasks.amazonaws.com" ]
}
Effect = "Allow"
}
]
})
}
resource "aws_iam_policy" "alpha_iam_policy" {
name = "${var.athens_prefix}-alpha-iam-policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
]
"Resource" = "*"
}
]
})
}
resource "aws_iam_role_policy_attachment" "alpha_logs" {
role = aws_iam_role.alpha_iam_role.name
policy_arn = aws_iam_policy.alpha_iam_policy.arn
}
# Alpha cluster definition # Alpha cluster definition
########################### ###########################
resource "aws_ecs_cluster" "alpha" { resource "aws_ecs_cluster" "alpha" {
name = "alpha" name = "${var.athens_prefix}-athens-alpha"
configuration { configuration {
execute_command_configuration { execute_command_configuration {
logging = "OVERRIDE"
log_configuration { log_configuration {
cloud_watch_log_group_name = aws_cloudwatch_log_group.alpha.name cloud_watch_log_group_name = aws_cloudwatch_log_group.alpha.name
} }
@ -25,36 +75,58 @@ resource "aws_ecs_cluster" "alpha" {
# Lewdlad Service Definition # Lewdlad Service Definition
############################ ############################
resource "aws_ecs_task_definition" "lewdlad" { resource "aws_ecs_task_definition" "sample" {
family = "lewdlad-task-definition" family = "${var.athens_prefix}-sample"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
execution_role_arn = aws_iam_role.alpha_iam_role.arn
cpu = 256
memory = 512
container_definitions = jsonencode([ container_definitions = jsonencode([
{ {
name = "lewdlad-container" name = "${var.athens_prefix}-sample-container"
image = "registry.gitlab.com/shockrah/left-coast-server-bot:latest" image = "nginxdemos/nginx-hello:latest"
# Literally the smallest amount that fargate will allow cpu = 128
cpu = 256 memory = 256
memory = 512
essential = true essential = true
environment = [ portMappings = [
{ name: DISCORD_ID, value: var.DISCORD_ID }, {
{ name: DISCORD_TOKEN, value: var.DISCORD_TOKEN }, containerPort = 8080
{ name: AWS_API_ID, value: var.AWS_API_ID }, hostPort = 8080
{ name: AWS_API_STAGE, value: var.AWS_API_STAGE }, }
{ name: AWS_API_REGION, value: var.AWS_API_REGION },
{ name: AWS_API_KEY, value: var.AWS_API_KEY },
{ name: DEV_GUILD_ID, value: var.DEV_GUILD_ID },
{ name: BEEHIVE_ID, value: var.BEEHIVE_ID },
] ]
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = aws_cloudwatch_log_group.alpha.name
awslogs-region = "us-west-1"
awslogs-stream-prefix = "sample-container"
}
}
} }
]) ])
tags = {
Name = "${var.athens_prefix}-sample-task-def-container"
}
} }
resource "aws_ecs_service" "lewdlad" { # Service level definition
name = "lewdlad" ##########################
cluster = aws_ecs_cluster.alpha.arn resource "aws_ecs_service" "sample" {
task_definition = aws_ecs_task_definition.lewdlad.arn name = "${var.athens_prefix}-sample-service"
cluster = aws_ecs_cluster.alpha.id
task_definition = aws_ecs_task_definition.sample.arn
desired_count = 1 desired_count = 1
launch_type = "FARGATE"
network_configuration {
assign_public_ip = true
subnets = [ local.subnet ]
security_groups = [
aws_security_group.ecs_web_ingress.id,
aws_security_group.base_ecs.id
]
}
} }

View File

@ -1,3 +1,6 @@
# NOTE: this will no longer be used and is getting removed once we seutp the
# new alpha cluster correctly
# This is the continuation of the old alpha host but with much cleaner code # This is the continuation of the old alpha host but with much cleaner code
# and less manual infra setup involved. Key differences are that block storage # and less manual infra setup involved. Key differences are that block storage
# is now completely kept in this module instead of yolo'd out like before. # is now completely kept in this module instead of yolo'd out like before.
@ -29,38 +32,3 @@ resource "aws_ebs_volume" "clips-shockrah-xyz" {
Description = "Used for the clippable instance" Description = "Used for the clippable instance"
} }
} }
######################### ATTACHMENT FOR files.leftcoast.space #################
resource "aws_volume_attachment" "files-leftcoast-space" {
device_name = "/dev/sdf"
volume_id = aws_ebs_volume.files-leftcoast-space.id
instance_id = aws_instance.atlas.id
}
######################### ATTACHMENT FOR clips.shockrah.xyz ####################
resource "aws_volume_attachment" "clips-shockrah-xyz" {
device_name = "/dev/sdg"
volume_id = aws_ebs_volume.clips-shockrah-xyz.id
instance_id = aws_instance.atlas.id
}
######################### INSTANCE CONFIGURATION ###############################
resource "aws_instance" "atlas" {
ami = var.atlas_ami_id
instance_type = var.atlas_instance_type
key_name = var.atlas_ssh_key_name
private_ip = "10.0.1.20"
vpc_security_group_ids = [
aws_security_group.general_web_req.id,
aws_security_group.remote_ssh_rec.id
]
subnet_id = aws_subnet.crete_subnet.id
tags = {
Name = "Atlas Host"
Description = "Simple Docker host for some personal stuff"
}
}

View File

@ -1,12 +1,3 @@
resource "aws_eip" "alpha_eip" {
instance = aws_instance.atlas.id
vpc = true
tags = {
Name = "Atlas EIP"
}
}
resource "aws_eip" "beta_eip" { resource "aws_eip" "beta_eip" {
vpc = true vpc = true
instance = aws_instance.beta.id instance = aws_instance.beta.id