Skip to content

Commit

Permalink
Merge pull request #62 from tryretool/vee/service-discovery-var
Browse files Browse the repository at this point in the history
Parameterize service discovery namespace
  • Loading branch information
golfdish authored Oct 30, 2024
2 parents 9fc2bba + 614fec1 commit 16be9cd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
8 changes: 5 additions & 3 deletions modules/aws_ecs/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ locals {
}
]

service_discovery_namespace = var.service_discovery_namespace != "" ? var.service_discovery_namespace : format("%s%s", replace(var.deployment_name, "-", ""), "svc")

// Use var.ecs_code_executor_image if defined, otherwise fallback to the same tag as var.ecs_retool_image
ecs_code_executor_image = var.ecs_code_executor_image != "" ? var.ecs_code_executor_image : format("%s:%s", "tryretool/code-executor-service", split(":", var.ecs_retool_image)[1])

Expand All @@ -24,7 +26,7 @@ locals {
var.code_executor_enabled ? [
{
name = "CODE_EXECUTOR_INGRESS_DOMAIN"
value = "http://code-executor.retoolsvc:3004"
value = format("http://code-executor.%s:3004", local.service_discovery_namespace)
}
] : [],
[
Expand Down Expand Up @@ -71,15 +73,15 @@ locals {
# Workflows-specific
{
"name" : "WORKFLOW_BACKEND_HOST",
"value" : "http://workflow-backend.retoolsvc:3000"
"value" : format("http://workflow-backend.%s:3000", local.service_discovery_namespace)
},
{
"name" : "WORKFLOW_TEMPORAL_CLUSTER_NAMESPACE",
"value" : var.temporal_cluster_config.namespace
},
{
"name" : "WORKFLOW_TEMPORAL_CLUSTER_FRONTEND_HOST",
"value" : var.temporal_cluster_config.host
"value" : format("%s.%s", var.temporal_cluster_config.hostname, local.service_discovery_namespace)
},
{
"name" : "WORKFLOW_TEMPORAL_CLUSTER_FRONTEND_PORT",
Expand Down
13 changes: 7 additions & 6 deletions modules/aws_ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ resource "aws_ecs_task_definition" "retool_code_executor" {
)
}

resource "aws_service_discovery_private_dns_namespace" "retoolsvc" {
count = var.workflows_enabled ? 1 : 0
name = "retoolsvc"
resource "aws_service_discovery_private_dns_namespace" "retool_namespace" {
count = (var.code_executor_enabled || var.workflows_enabled) ? 1 : 0
name = local.service_discovery_namespace
description = "Service Discovery namespace for Retool deployment"
vpc = var.vpc_id
}
Expand All @@ -492,7 +492,7 @@ resource "aws_service_discovery_service" "retool_workflow_backend_service" {
name = "workflow-backend"

dns_config {
namespace_id = aws_service_discovery_private_dns_namespace.retoolsvc[0].id
namespace_id = aws_service_discovery_private_dns_namespace.retool_namespace[0].id

dns_records {
ttl = 60
Expand All @@ -512,7 +512,7 @@ resource "aws_service_discovery_service" "retool_code_executor_service" {
name = "code-executor"

dns_config {
namespace_id = aws_service_discovery_private_dns_namespace.retoolsvc[0].id
namespace_id = aws_service_discovery_private_dns_namespace.retool_namespace[0].id

dns_records {
ttl = 60
Expand All @@ -533,7 +533,7 @@ module "temporal" {
deployment_name = "${var.deployment_name}-temporal"
vpc_id = var.vpc_id
subnet_ids = var.private_subnet_ids
private_dns_namespace_id = aws_service_discovery_private_dns_namespace.retoolsvc[0].id
private_dns_namespace_id = aws_service_discovery_private_dns_namespace.retool_namespace[0].id
aws_cloudwatch_log_group_id = aws_cloudwatch_log_group.this.id
temporal_services_config = {
frontend = {
Expand Down Expand Up @@ -574,4 +574,5 @@ module "temporal" {
container_sg_id = aws_security_group.containers.id
aws_ecs_capacity_provider_name = var.launch_type == "EC2" ? aws_ecs_capacity_provider.this[0].name : null
task_propagate_tags = var.task_propagate_tags
service_discovery_namespace = local.service_discovery_namespace
}
2 changes: 1 addition & 1 deletion modules/aws_ecs/temporal/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ resource "aws_ecs_task_definition" "retool_temporal" {
],
each.key != "frontend" ? [{
"name" : "PUBLIC_FRONTEND_ADDRESS",
"value" : "${var.temporal_cluster_config.host}:${var.temporal_cluster_config.port}"
"value" : "${var.temporal_cluster_config.hostname}.${var.service_discovery_namespace}:${var.temporal_cluster_config.port}"
}
] : []
)
Expand Down
10 changes: 7 additions & 3 deletions modules/aws_ecs/temporal/variables.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# namescape: temporal namespace to use for Retool Workflows. We recommend this is only used by Retool.
# host: hostname for Temporal Frontend service
# hostname: hostname for Temporal Frontend service
# port: port for Temporal Frontend service
# tls_enabled: Whether to use tls when connecting to Temporal Frontend. For mTLS, configure tls_crt and tls_key.
# tls_crt: For mTLS only. Base64 encoded string of public tls certificate
# tls_key: For mTLS only. Base64 encoded string of private tls key
variable "temporal_cluster_config" {
type = object({
namespace = string
host = string
hostname = string
port = string
tls_enabled = bool
tls_crt = optional(string)
Expand All @@ -16,7 +16,7 @@ variable "temporal_cluster_config" {

default = {
namespace = "workflows"
host = "temporal.retoolsvc"
hostname = "temporal"
port = "7233"
tls_enabled = false
}
Expand Down Expand Up @@ -206,3 +206,7 @@ variable "task_propagate_tags" {
default = "TASK_DEFINITION"
}

variable "service_discovery_namespace" {
type = string
description = "Service discovery namespace DNS name for Retool ECS cluster."
}
12 changes: 9 additions & 3 deletions modules/aws_ecs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ variable "deployment_name" {
default = "retool"
}

variable "service_discovery_namespace" {
type = string
description = "Service discovery namespace DNS name. Default is based on deployment name (see locals.tf)."
default = ""
}

variable "task_propagate_tags" {
type = string
description = "Which resource to propagate tags from for ECS service tasks. Defaults to `TASK_DEFINITION`"
Expand Down Expand Up @@ -246,15 +252,15 @@ variable "launch_type" {
# namescape: temporal namespace to use for Retool Workflows. We recommend this is only used by Retool.
# If use_existing_temporal_cluster == true this should be config for currently existing cluster.
# If use_existing_temporal_cluster == false, you should use the defaults.
# host: hostname for Temporal Frontend service
# hostname: hostname for Temporal Frontend service
# port: port for Temporal Frontend service
# tls_enabled: Whether to use tls when connecting to Temporal Frontend. For mTLS, configure tls_crt and tls_key.
# tls_crt: For mTLS only. Base64 encoded string of public tls certificate
# tls_key: For mTLS only. Base64 encoded string of private tls key
variable "temporal_cluster_config" {
type = object({
namespace = string
host = string
hostname = string
port = string
tls_enabled = bool
tls_crt = optional(string)
Expand All @@ -263,7 +269,7 @@ variable "temporal_cluster_config" {

default = {
namespace = "workflows"
host = "temporal.retoolsvc"
hostname = "temporal"
port = "7233"
tls_enabled = false
}
Expand Down

0 comments on commit 16be9cd

Please sign in to comment.