Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 5524abf

Browse files
henworthMao-hsiang Lien
authored and
Mao-hsiang Lien
committed
feat: Allow for an existing ECS cluster to be used (terraform-aws-modules#233)
1 parent 1e390b6 commit 5524abf

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,15 @@ allow_github_webhooks = true
336336
| <a name="input_container_depends_on"></a> [container\_depends\_on](#input\_container\_depends\_on) | The dependencies defined for container startup and shutdown. A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY | <pre>list(object({<br> containerName = string<br> condition = string<br> }))</pre> | `null` | no |
337337
| <a name="input_container_memory"></a> [container\_memory](#input\_container\_memory) | The amount (in MiB) of memory used by the atlantis container. If not specified ecs\_task\_memory will be used | `number` | `null` | no |
338338
| <a name="input_container_memory_reservation"></a> [container\_memory\_reservation](#input\_container\_memory\_reservation) | The amount of memory (in MiB) to reserve for the container | `number` | `128` | no |
339+
| <a name="input_create_ecs_cluster"></a> [create\_ecs\_cluster](#input\_create\_ecs\_cluster) | Whether to create an ECS cluster or not | `bool` | `true` | no |
339340
| <a name="input_create_route53_record"></a> [create\_route53\_record](#input\_create\_route53\_record) | Whether to create Route53 record for Atlantis | `bool` | `true` | no |
340341
| <a name="input_custom_container_definitions"></a> [custom\_container\_definitions](#input\_custom\_container\_definitions) | A list of valid container definitions provided as a single valid JSON document. By default, the standard container definition is used. | `string` | `""` | no |
341342
| <a name="input_custom_environment_secrets"></a> [custom\_environment\_secrets](#input\_custom\_environment\_secrets) | List of additional secrets the container will use (list should contain maps with `name` and `valueFrom`) | <pre>list(object(<br> {<br> name = string<br> valueFrom = string<br> }<br> ))</pre> | `[]` | no |
342343
| <a name="input_custom_environment_variables"></a> [custom\_environment\_variables](#input\_custom\_environment\_variables) | List of additional environment variables the container will use (list should contain maps with `name` and `value`) | <pre>list(object(<br> {<br> name = string<br> value = string<br> }<br> ))</pre> | `[]` | no |
343344
| <a name="input_default_security_group_egress"></a> [default\_security\_group\_egress](#input\_default\_security\_group\_egress) | List of maps of egress rules to set on the default security group | `list(map(string))` | `[]` | no |
344345
| <a name="input_default_security_group_ingress"></a> [default\_security\_group\_ingress](#input\_default\_security\_group\_ingress) | List of maps of ingress rules to set on the default security group | `list(map(string))` | `[]` | no |
345346
| <a name="input_docker_labels"></a> [docker\_labels](#input\_docker\_labels) | The configuration options to send to the `docker_labels` | `map(string)` | `null` | no |
347+
| <a name="input_ecs_cluster_id"></a> [ecs\_cluster\_id](#input\_ecs\_cluster\_id) | ID of an existing ECS cluster where resources will be created | `string` | `""` | no |
346348
| <a name="input_ecs_container_insights"></a> [ecs\_container\_insights](#input\_ecs\_container\_insights) | Controls if ECS Cluster has container insights enabled | `bool` | `false` | no |
347349
| <a name="input_ecs_fargate_spot"></a> [ecs\_fargate\_spot](#input\_ecs\_fargate\_spot) | Whether to run ECS Fargate Spot or not | `bool` | `false` | no |
348350
| <a name="input_ecs_service_assign_public_ip"></a> [ecs\_service\_assign\_public\_ip](#input\_ecs\_service\_assign\_public\_ip) | Should be true, if ECS service is using public subnets (more info: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_cannot_pull_image.html) | `bool` | `false` | no |

main.tf

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ locals {
2727
# determine if the alb has authentication enabled, otherwise forward the traffic unauthenticated
2828
alb_authentication_method = length(keys(var.alb_authenticate_oidc)) > 0 ? "authenticate-oidc" : length(keys(var.alb_authenticate_cognito)) > 0 ? "authenticate-cognito" : "forward"
2929

30+
# ECS - existing or new?
31+
ecs_cluster_id = var.create_ecs_cluster ? module.ecs.ecs_cluster_id : var.ecs_cluster_id
32+
3033
# Container definitions
3134
container_definitions = var.custom_container_definitions == "" ? var.atlantis_bitbucket_user_token != "" ? jsonencode(concat([module.container_definition_bitbucket.json_map_object], var.extra_container_definitions)) : jsonencode(concat([module.container_definition_github_gitlab.json_map_object], var.extra_container_definitions)) : var.custom_container_definitions
3235

@@ -494,6 +497,8 @@ module "ecs" {
494497
source = "terraform-aws-modules/ecs/aws"
495498
version = "v3.3.0"
496499

500+
create_ecs = var.create_ecs_cluster
501+
497502
name = var.name
498503
container_insights = var.ecs_container_insights
499504

@@ -780,7 +785,7 @@ data "aws_ecs_task_definition" "atlantis" {
780785

781786
resource "aws_ecs_service" "atlantis" {
782787
name = var.name
783-
cluster = module.ecs.ecs_cluster_id
788+
cluster = local.ecs_cluster_id
784789

785790
task_definition = "${var.name}:${local.latest_task_definition_rev}"
786791
desired_count = var.ecs_service_desired_count

outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ output "ecs_security_group" {
5353

5454
output "ecs_cluster_id" {
5555
description = "ECS cluster id"
56-
value = module.ecs.ecs_cluster_id
56+
value = local.ecs_cluster_id
5757
}
5858

5959
output "ecs_cluster_arn" {

variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,18 @@ variable "trusted_entities" {
324324
default = []
325325
}
326326

327+
variable "create_ecs_cluster" {
328+
description = "Whether to create an ECS cluster or not"
329+
type = bool
330+
default = true
331+
}
332+
333+
variable "ecs_cluster_id" {
334+
description = "ID of an existing ECS cluster where resources will be created"
335+
type = string
336+
default = ""
337+
}
338+
327339
variable "ecs_fargate_spot" {
328340
description = "Whether to run ECS Fargate Spot or not"
329341
type = bool

0 commit comments

Comments
 (0)