Skip to content

Commit

Permalink
Adding Options for Enabling ECS Service Connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Navfarm committed Feb 23, 2024
1 parent bd57d32 commit 4d7ff33
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 22 deletions.
1 change: 0 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ module "service" {
capacity_provider_strategy = var.default_capacity_provider_strategy

service_connect_configuration = length(var.service_connect_defaults) > 0 ? var.service_connect_configuration : {}
service_connect_namespace = length(var.service_connect_defaults) > 0 && length(var.service_connect_configuration) > 0 ? module.cluster.ecs_service_connect_namespace_arn : null
}

module "service_cpu_autoscaling_policy" {
Expand Down
2 changes: 0 additions & 2 deletions modules/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ No modules.
| [aws_ecs_cluster_capacity_providers.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster_capacity_providers) | resource |
| [aws_kms_key.cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
| [aws_kms_key.cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
| [aws_service_discovery_http_namespace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/service_discovery_http_namespace) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.cloudwatch_logs_allow_kms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
Expand Down Expand Up @@ -66,5 +65,4 @@ No modules.
| <a name="output_ecs_cluster_id"></a> [ecs\_cluster\_id](#output\_ecs\_cluster\_id) | ID of the ECS Cluster |
| <a name="output_ecs_cluster_kms_arn"></a> [ecs\_cluster\_kms\_arn](#output\_ecs\_cluster\_kms\_arn) | The AWS Key Management Service key ID to encrypt the data between the local client and the container |
| <a name="output_ecs_cluster_name"></a> [ecs\_cluster\_name](#output\_ecs\_cluster\_name) | The name of the ECS cluster |
| <a name="output_ecs_service_connect_namespace_arn"></a> [ecs\_service\_connect\_namespace\_arn](#output\_ecs\_service\_connect\_namespace\_arn) | ARN of ECS Service Connect Namespace |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7 changes: 1 addition & 6 deletions modules/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ resource "aws_ecs_cluster_capacity_providers" "this" {
}
}

resource "aws_service_discovery_http_namespace" "this" {
count = length(var.service_connect_defaults) > 0 ? 1 : 0
name = format("ecs-%s", var.name)
}

resource "aws_ecs_cluster" "this" {
name = format("ecs-%s", var.name)
setting {
Expand All @@ -89,7 +84,7 @@ resource "aws_ecs_cluster" "this" {
for_each = length(var.service_connect_defaults) > 0 ? [var.service_connect_defaults] : []

content {
namespace = try(service_connect_defaults.value.namespace, aws_service_discovery_http_namespace.this[0].arn)
namespace = service_connect_defaults.value.namespace
}
}

Expand Down
5 changes: 0 additions & 5 deletions modules/cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ output "ecs_cluster_kms_arn" {
value = try(aws_kms_key.cluster.arn, "")
}

output "ecs_service_connect_namespace_arn" {
description = "ARN of ECS Service Connect Namespace"
value = try(aws_service_discovery_http_namespace.this[0].arn, "")
}

output "ecs_cloudwatch_log_group_name" {
description = "The cloudwatch log group to be used by the cluster"
value = try(aws_cloudwatch_log_group.this.*.name, "")
Expand Down
1 change: 0 additions & 1 deletion modules/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ No modules.
| <a name="input_propagate_tags"></a> [propagate\_tags](#input\_propagate\_tags) | Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK\_DEFINITION | `string` | `"TASK_DEFINITION"` | no |
| <a name="input_security_groups"></a> [security\_groups](#input\_security\_groups) | Security group IDs to attach to your ECS Service | `list(string)` | `null` | no |
| <a name="input_service_connect_configuration"></a> [service\_connect\_configuration](#input\_service\_connect\_configuration) | The ECS Service Connect configuration to discover and connect to services | `map(any)` | `{}` | no |
| <a name="input_service_connect_namespace"></a> [service\_connect\_namespace](#input\_service\_connect\_namespace) | Namespace in which ECS Service Connect to be created | `string` | `null` | no |
| <a name="input_service_placement_constraints"></a> [service\_placement\_constraints](#input\_service\_placement\_constraints) | The rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10. | <pre>list(object({<br> type = string<br> expression = string<br> }))</pre> | `[]` | no |
| <a name="input_service_registries"></a> [service\_registries](#input\_service\_registries) | Service discovery registries for the service. The maximum number of service\_registries blocks is 1 | `list(any)` | `[]` | no |
| <a name="input_subnets"></a> [subnets](#input\_subnets) | Private subnets for ECS | `list(string)` | `null` | no |
Expand Down
2 changes: 1 addition & 1 deletion modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ resource "aws_ecs_service" "this" {
}
}

namespace = lookup(service_connect_configuration.value, "namespace", var.service_connect_namespace)
namespace = lookup(service_connect_configuration.value, "namespace", null)

dynamic "service" {
for_each = try([service_connect_configuration.value.service], [])
Expand Down
6 changes: 0 additions & 6 deletions modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ variable "service_connect_configuration" {
default = {}
}

variable "service_connect_namespace" {
description = "Namespace in which ECS Service Connect to be created"
type = string
default = null
}

################################################################################
# ECS Task Definition
################################################################################
Expand Down

0 comments on commit 4d7ff33

Please sign in to comment.