Skip to content

Add Service Discovery + dependencies #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ module "efs" {

}

resource "aws_service_discovery_service" "main" {
count = var.public == true ? 0 : 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add one more additional bool variable like var.service_discovery_enabled true/false

name = "${var.namespace}-${var.env}-${local.ecs_service_name}"

tags = {
env = var.env
Env = var.env
Name = local.ecs_service_name
}

dns_config {
namespace_id = var.service_discovery_id
routing_policy = "MULTIVALUE"

dns_records {
ttl = 10
type = "A"
}
}

health_check_custom_config {
failure_threshold = 1
}
}

module "service" {
source = "./ecs-modules/ecs-service"

Expand Down Expand Up @@ -184,6 +209,13 @@ module "service" {
PROXY_ENABLED = var.web_proxy_enabled ? "true" : "false"
}
)

dynamic service_registries {
for_each = var.public ? [] : [1]
content {
registry_arn = aws_service_discovery_service.main[0].arn
}
}
}

resource "aws_route53_record" "alb" {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,12 @@ variable "cpu_architecture" {
default = "X86_64"
}

variable "service_discovery_id" {
type = string
description = "When you use Service Discovery"
default = ""
}

variable "ecr_force_delete" {
default = false
description = "If true, will delete the ECR repository even if it contains images."
Expand Down