From 079534030e4e52a2ae29d49bbacdb474c27292d5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 2 Jan 2024 10:14:15 +0200 Subject: initial variable controlling whether a service should be deployed or not. --- README.md | 1 + org-buetow-ecs/ankiservice.tf | 12 +++++++++--- org-buetow-ecs/variables.tf | 7 +++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b503aa8..ab2ee88 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ## TODO's +* Input variables which services (ECS) to start. * Cloudwatch monitoring with E-Mail alert of the services. ## Manual steps diff --git a/org-buetow-ecs/ankiservice.tf b/org-buetow-ecs/ankiservice.tf index 3def73b..6150d2c 100644 --- a/org-buetow-ecs/ankiservice.tf +++ b/org-buetow-ecs/ankiservice.tf @@ -1,4 +1,5 @@ resource "aws_route53_record" "a_record_anki" { + count = var.deploy_anki ? 1 : 0 zone_id = data.terraform_remote_state.base.outputs.zone_id name = "anki.${data.terraform_remote_state.base.outputs.zone_name}." type = "A" @@ -11,6 +12,7 @@ resource "aws_route53_record" "a_record_anki" { } resource "aws_route53_record" "aaaa_record_anki" { + count = var.deploy_anki ? 1 : 0 zone_id = data.terraform_remote_state.base.outputs.zone_id name = "anki.${data.terraform_remote_state.base.outputs.zone_name}." type = "AAAA" @@ -23,6 +25,7 @@ resource "aws_route53_record" "aaaa_record_anki" { } resource "aws_ecs_task_definition" "anki" { + count = var.deploy_anki ? 1 : 0 family = "anki" network_mode = "awsvpc" requires_compatibilities = ["FARGATE"] @@ -74,9 +77,10 @@ resource "aws_ecs_task_definition" "anki" { } resource "aws_ecs_service" "anki" { + count = var.deploy_anki ? 1 : 0 name = "anki" cluster = aws_ecs_cluster.ecs_cluster.id - task_definition = aws_ecs_task_definition.anki.arn + task_definition = aws_ecs_task_definition.anki[0].arn launch_type = "FARGATE" deployment_maximum_percent = 100 deployment_minimum_healthy_percent = 0 @@ -87,7 +91,7 @@ resource "aws_ecs_service" "anki" { } load_balancer { - target_group_arn = aws_lb_target_group.anki_tg.arn + target_group_arn = aws_lb_target_group.anki_tg[0].arn container_name = "anki" # Must match the name in your container definition container_port = 8080 # The port your container is listening on } @@ -104,6 +108,7 @@ resource "aws_ecs_service" "anki" { } resource "aws_lb_target_group" "anki_tg" { + count = var.deploy_anki ? 1 : 0 name = "anki-tg" port = 8080 protocol = "HTTP" @@ -127,12 +132,13 @@ resource "aws_lb_target_group" "anki_tg" { } resource "aws_lb_listener_rule" "anki_https_listener_rule" { + count = var.deploy_anki ? 1 : 0 listener_arn = data.terraform_remote_state.elb.outputs.alb_https_listener_arn priority = 107 action { type = "forward" - target_group_arn = aws_lb_target_group.anki_tg.arn + target_group_arn = aws_lb_target_group.anki_tg[0].arn } condition { diff --git a/org-buetow-ecs/variables.tf b/org-buetow-ecs/variables.tf index 139597f..bb3fffa 100644 --- a/org-buetow-ecs/variables.tf +++ b/org-buetow-ecs/variables.tf @@ -1,2 +1,5 @@ - - +variable "deploy_anki" { + description = "Deploy Anki Sync Server?" + type = bool + default = false +} -- cgit v1.2.3