diff options
| author | Paul Buetow <paul@buetow.org> | 2023-12-18 21:59:43 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-12-18 21:59:43 +0200 |
| commit | b887e2a1f77e5694d20f59703500a15b90e378b9 (patch) | |
| tree | 8c4995ae3c6cc985c0d9fa1d43eb227bdff8819c | |
| parent | 64da1e2d02eb5d157091542cce1b6c5c412bdfac (diff) | |
added audiobookshelf
| -rw-r--r-- | org-buetow-ecs/audiobookshelfservice.tf | 150 | ||||
| -rw-r--r-- | org-buetow-ecs/ecs.tf | 44 |
2 files changed, 172 insertions, 22 deletions
diff --git a/org-buetow-ecs/audiobookshelfservice.tf b/org-buetow-ecs/audiobookshelfservice.tf new file mode 100644 index 0000000..50290df --- /dev/null +++ b/org-buetow-ecs/audiobookshelfservice.tf @@ -0,0 +1,150 @@ +resource "aws_route53_record" "my_a_record_audiobookshelf" { + zone_id = data.aws_route53_zone.my_zone.zone_id + name = "audiobookshelf.aws.buetow.org." + type = "A" + + alias { + name = aws_lb.my_alb.dns_name + zone_id = aws_lb.my_alb.zone_id + evaluate_target_health = true + } +} + +resource "aws_ecs_task_definition" "audiobookshelf_task" { + family = "audiobookshelf" + network_mode = "awsvpc" + requires_compatibilities = ["FARGATE"] + cpu = "256" + memory = "512" + execution_role_arn = aws_iam_role.ecs_execution_role.arn + + volume { + name = "audiobookshelf-config-efs-volume" + efs_volume_configuration { + file_system_id = data.terraform_remote_state.base.outputs.my_self_hosted_services_efs_id + root_directory = "/ecs/audiobookshelf/config" + } + } + + volume { + name = "audiobookshelf-metadata-efs-volume" + efs_volume_configuration { + file_system_id = data.terraform_remote_state.base.outputs.my_self_hosted_services_efs_id + root_directory = "/ecs/audiobookshelf/metadata" + } + } + + volume { + name = "audiobookshelf-audiobooks-efs-volume" + efs_volume_configuration { + file_system_id = data.terraform_remote_state.base.outputs.my_self_hosted_services_efs_id + root_directory = "/ecs/audiobookshelf/audiobooks" + } + } + + volume { + name = "audiobookshelf-podcasts-efs-volume" + efs_volume_configuration { + file_system_id = data.terraform_remote_state.base.outputs.my_self_hosted_services_efs_id + root_directory = "/ecs/audiobookshelf/podcasts" + } + } + + container_definitions = jsonencode([{ + name = "audiobookshelf", + image = "ghcr.io/advplyr/audiobookshelf" + portMappings = [{ + containerPort = 80, + hostPort = 80 + }], + mountPoints = [ + { + sourceVolume = "audiobookshelf-config-efs-volume" + containerPath = "/config" + readOnly = false + }, + { + sourceVolume = "audiobookshelf-metadata-efs-volume" + containerPath = "/metadata" + readOnly = false + }, + { + sourceVolume = "audiobookshelf-audiobooks-efs-volume" + containerPath = "/audiobooks" + readOnly = false + }, + { + sourceVolume = "audiobookshelf-podcasts-efs-volume" + containerPath = "/podcasts" + readOnly = false + }, + ], + "logConfiguration" : { + "logDriver" : "awslogs", + "options" : { + "awslogs-group" : "/ecs/containers", + "awslogs-region" : "eu-central-1", + "awslogs-stream-prefix" : "audiobookshelf" + } + } + }]) +} + +resource "aws_ecs_service" "audiobookshelf_service" { + name = "audiobookshelf-service" + cluster = aws_ecs_cluster.my_ecs_cluster.id + task_definition = aws_ecs_task_definition.audiobookshelf_task.arn + launch_type = "FARGATE" + desired_count = 1 + + load_balancer { + target_group_arn = aws_lb_target_group.my_audiobookshelf_tg.arn + container_name = "audiobookshelf" # Must match the name in your container definition + container_port = 80 # The port your container is listening on + } + + network_configuration { + subnets = [ + data.terraform_remote_state.base.outputs.my_public_subnet_a_id, + data.terraform_remote_state.base.outputs.my_public_subnet_b_id, + data.terraform_remote_state.base.outputs.my_public_subnet_c_id, + ] + security_groups = [data.terraform_remote_state.base.outputs.allow_web_sg_id] + assign_public_ip = true + } +} + +resource "aws_lb_target_group" "my_audiobookshelf_tg" { + name = "my-audiobookshelf-tg" + port = 80 + protocol = "HTTP" + vpc_id = data.terraform_remote_state.base.outputs.my_vpc_id + target_type = "ip" + + health_check { + enabled = true + healthy_threshold = 2 + unhealthy_threshold = 2 + interval = 30 + path = "/" + protocol = "HTTP" + timeout = 3 + matcher = "200-299" + } +} + +resource "aws_lb_listener_rule" "my_audiobookshelf_https_listener_rule" { + listener_arn = aws_lb_listener.my_https_listener.arn + priority = 102 + + action { + type = "forward" + target_group_arn = aws_lb_target_group.my_audiobookshelf_tg.arn + } + + condition { + host_header { + values = ["audiobookshelf.aws.buetow.org"] + } + } +} diff --git a/org-buetow-ecs/ecs.tf b/org-buetow-ecs/ecs.tf index 3cbdcfe..7c678d4 100644 --- a/org-buetow-ecs/ecs.tf +++ b/org-buetow-ecs/ecs.tf @@ -23,25 +23,25 @@ resource "aws_iam_role_policy_attachment" "ecs_execution_role_policy_attach" { } # For EFS mounts -resource "aws_iam_role" "ecs_task_execution_role" { - name = "ecs_task_execution_role" - - assume_role_policy = jsonencode({ - Version = "2012-10-17", - Statement = [ - { - Action = "sts:AssumeRole", - Effect = "Allow", - Principal = { - Service = "ecs-tasks.amazonaws.com" - }, - }, - ], - }) -} - -# For EFS mounts -resource "aws_iam_role_policy_attachment" "ecs_efs_access" { - role = aws_iam_role.ecs_task_execution_role.name - policy_arn = "arn:aws:iam::aws:policy/AmazonElasticFileSystemFullAccess" -} +#resource "aws_iam_role" "ecs_task_execution_role" { +# name = "ecs_task_execution_role" +# +# assume_role_policy = jsonencode({ +# Version = "2012-10-17", +# Statement = [ +# { +# Action = "sts:AssumeRole", +# Effect = "Allow", +# Principal = { +# Service = "ecs-tasks.amazonaws.com" +# }, +# }, +# ], +# }) +#} +# +## For EFS mounts +#resource "aws_iam_role_policy_attachment" "ecs_efs_access" { +# role = aws_iam_role.ecs_task_execution_role.name +# policy_arn = "arn:aws:iam::aws:policy/AmazonElasticFileSystemFullAccess" +#} |
