-
-
Notifications
You must be signed in to change notification settings - Fork 625
Description
Description
The cluster_service_connect_defaults variable accepts a namespace string and is documented to "Configure a default Service Connect namespace", but the module fails to create the required AWS Service Discovery namespace resource, causing Terraform to fail with an "invalid ARN" error.
Module Version
terraform-aws-ecs version: v6.2.2
Terraform version: v1.5.7
AWS provider: v6.9.0
- [ x] ✋ I have searched the open/closed issues and my issue is not listed.
Expected Behavior
When providing a cluster_service_connect_defaults configuration with a namespace string:
The module should:
Create an aws_service_discovery_http_namespace resource with the provided name
Use the ARN of the created namespace in the aws_ecs_cluster.service_connect_defaults.namespace field
Actual Behavior
The module directly passes the namespace string to the aws_ecs_cluster resource, which fails because AWS expects an ARN, not a string name.
Error Message
Root Cause Analysis
Current Implementation (Broken)
In main.tf:
dynamic "service_connect_defaults" {
for_each = var.service_connect_defaults != null ? [var.service_connect_defaults] : []
content {
namespace = service_connect_defaults.value.namespace # Passing string directly
}
}
Variable Definition
In variables.tf
variable "service_connect_defaults" {
description = "Configures a default Service Connect namespace" # ❌ Misleading description
type = object({
namespace = string
})
default = null
}
(lines 58-64):
AWS API Requirement
According to AWS documentation, service_connect_defaults.namespace must be a Service Discovery namespace ARN, not a name string.
Proposed Solution: Implement Namespace Creation
Add namespace creation capability to the cluster module:
In main.tf add before the cluster resource:
resource "aws_service_discovery_http_namespace" "service_connect" {
count = var.service_connect_defaults != null ? 1 : 0
name = var.service_connect_defaults.namespace
description = "Service Connect namespace for ${var.name} ECS cluster"
tags = var.tags
}
Update the cluster resource to use the created namespace ARN:
dynamic "service_connect_defaults" {
for_each = var.service_connect_defaults != null ? [var.service_connect_defaults] : []
content {
namespace = aws_service_discovery_http_namespace.service_connect[0].arn
}
}
Add output in :
output "service_connect_namespace_arn" {
description = "ARN of the Service Connect namespace"
value = try(aws_service_discovery_http_namespace.service_connect[0].arn, null)
}
output "service_connect_namespace_name" {
description = "Name of the Service Connect namespace"
value = try(aws_service_discovery_http_namespace.service_connect[0].name, null)
}
if this is just a miss configuration on my part (which is always a possibility) please let me know.