Skip to content

Commit

Permalink
update to use shortname of target group
Browse files Browse the repository at this point in the history
  • Loading branch information
ships committed May 7, 2024
1 parent fbfcf8e commit 3580cd3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion infrastructure/terraform/modules/container-generic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ locals {
# null-guard here is annoying but necessary
public = var.listener != null ? var.listener.public : false

# a shortname for placaes where name lengths are constrained
shortname = substr(sha1(var.service_name), 0, 4)

# a block to DRY out
log_configuration = {
logDriver = "awslogs",
Expand Down Expand Up @@ -93,6 +96,8 @@ module "ecs_service" {
}] : []

environment = [
{ name = "OTEL_SERVICE_NAME",
value = "${var.service_name}.nginx" },
{ name = "NGINX_LISTEN_PORT",
value = "8080" },
{ name = "NGINX_PREFIX",
Expand Down Expand Up @@ -129,12 +134,16 @@ module "ecs_service" {
tags = {
Environment = "${var.cluster_info.name}-${var.cluster_info.environment}"
Project = "Pubpub-v7"
LogicalName = var.service_name
Shortname = local.shortname
ShortnameAnnotation = "Shortname is calculated as first four characters of the sha1sum of the Logical Name."
}
}

resource "aws_lb_target_group" "this" {
count = local.public ? 1 : 0
name = "${var.cluster_info.name}-${var.service_name}"
# use shortname here because this string is max 32 chars
name = "${var.cluster_info.name}-${local.shortname}"
port = 80
protocol = "HTTP"
vpc_id = var.cluster_info.vpc_id
Expand Down

0 comments on commit 3580cd3

Please sign in to comment.