Skip to content

Commit c87e431

Browse files
committed
Option to disable MongoDB node - shutting down the ecs service
1 parent bf841bc commit c87e431

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ module "mongodb_cluster" {
8282
| [aws_iam_policy_document.mongodb_node](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
8383
| [aws_iam_policy_document.mongodb_tasks_execution_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
8484
| [aws_subnet.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | data source |
85-
| [aws_vpc.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
8685

8786
## Inputs
8887

8988
| Name | Description | Type | Default | Required |
9089
|------|-------------|------|---------|:--------:|
90+
| <a name="input_disable_mongodb_service"></a> [disable\_mongodb\_service](#input\_disable\_mongodb\_service) | Whether to run MongoDB service or not | `bool` | `false` | no |
9191
| <a name="input_env_code"></a> [env\_code](#input\_env\_code) | Short environment name tag (e.g. dev, stg, prod) | `string` | n/a | yes |
9292
| <a name="input_environment"></a> [environment](#input\_environment) | Environment indicator where the MongoDB will be instantiated. E.g. Development, Staging, QA, Production | `string` | n/a | yes |
9393
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Type of ECS container instance type | `string` | n/a | yes |

main.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ data "aws_subnet" "this" {
2323
id = var.mongodb_nodes.0.subnet_id
2424
}
2525

26-
data "aws_vpc" "this" {
27-
id = data.aws_subnet.this.vpc_id
28-
}
29-
3026
resource "aws_ecs_cluster" "mongodb" {
3127
name = local.cluster_name
3228
setting {
@@ -115,6 +111,8 @@ module "mongodb_nodes" {
115111
env_code = var.env_code
116112
environment = var.environment
117113

114+
disable_mongodb_service = var.disable_mongodb_service
115+
118116
name = each.value.unique_name
119117
primary_node_name = local.primary_node_name
120118
subnet_id = each.value.subnet_id

modules/mongodb-node/ecs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ resource "aws_ecs_service" "mongodb_node" {
9696
name = var.name
9797
cluster = data.aws_ecs_cluster.this.arn
9898
task_definition = aws_ecs_task_definition.mongodb_node.arn
99-
desired_count = 1
99+
desired_count = var.disable_mongodb_service ? 0 : 1
100100
deployment_minimum_healthy_percent = 0
101101
deployment_maximum_percent = 100
102102
launch_type = "EC2"

modules/mongodb-node/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ variable "additional_security_group_ids" {
9595
description = "List of security groups attached to the MongoDB node"
9696
}
9797

98+
variable "disable_mongodb_service" {
99+
type = bool
100+
default = false
101+
}
102+
98103
variable "ecs_cluster_name" {
99104
type = string
100105
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ variable "instance_type" {
3434
description = "Type of ECS container instance type"
3535
}
3636

37+
variable "disable_mongodb_service" {
38+
description = "Whether to run MongoDB service or not"
39+
type = bool
40+
default = false
41+
}
42+
3743
variable "mongodb_nodes" {
3844
type = list(object({
3945
type : string,

0 commit comments

Comments
 (0)