diff options
| author | Paul Buetow <paul@buetow.org> | 2024-01-02 10:14:15 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-01-02 10:14:15 +0200 |
| commit | 079534030e4e52a2ae29d49bbacdb474c27292d5 (patch) | |
| tree | 71009284942d84e1cedb99543e101f0f5c6046bf | |
| parent | c1518d8c32d9abc5de84c7d0dd69b29f38eace02 (diff) | |
initial variable controlling whether a service should be deployed or
not.
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | org-buetow-ecs/ankiservice.tf | 12 | ||||
| -rw-r--r-- | org-buetow-ecs/variables.tf | 7 |
3 files changed, 15 insertions, 5 deletions
@@ -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 +} |
