diff --git a/modules/backend/api-gateway/README.md b/modules/backend/api-gateway/README.md index 90b14835..a1d5b43e 100644 --- a/modules/backend/api-gateway/README.md +++ b/modules/backend/api-gateway/README.md @@ -33,6 +33,7 @@ | [cognito\_enabled](#input\_cognito\_enabled) | Allow cognito authorization on api gateway routes | `bool` | no | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | no | | [domain\_name](#input\_domain\_name) | A domain name for which the certificate should be issued | `string` | no | +| [force\_redeploy](#input\_force\_redeploy) | When set to true, forces a redeployment of the api gateway on every apply. this is done by a timestamp | `bool` | no | | [integration\_http\_method](#input\_integration\_http\_method) | The integration HTTP method (GET, POST, PUT, DELETE, HEAD, OPTIONs, ANY, PATCH) specifying how API Gateway will interact with the back end. | `string` | no | | [integration\_request\_parameters](#input\_integration\_request\_parameters) | Allowed request headers on api gateway routes integrations | `map(string)` | no | | [method\_request\_parameters](#input\_method\_request\_parameters) | Allowed request headers on api gateway routes methods | `map(bool)` | no | diff --git a/modules/backend/api-gateway/main.tf b/modules/backend/api-gateway/main.tf index fbe4766b..5fe422fe 100644 --- a/modules/backend/api-gateway/main.tf +++ b/modules/backend/api-gateway/main.tf @@ -76,12 +76,10 @@ resource "aws_api_gateway_deployment" "main" { rest_api_id = aws_api_gateway_rest_api.main.id depends_on = [aws_api_gateway_integration.main] - variables = { - # just to trigger redeploy on resource changes - resources = join(", ", [aws_api_gateway_resource.main.id]) - - # note: redeployment might be required with other gateway changes. - # when necessary run `terraform taint ` + triggers = { + redeployment = sha1(jsonencode(aws_api_gateway_rest_api.main.body)) + # this var, when true, will make the api gateway redeploy every Terraform Apply. + force_redeploy = var.force_redeploy ? timestamp() : null } lifecycle { diff --git a/modules/backend/api-gateway/variables.tf b/modules/backend/api-gateway/variables.tf index 82a18cf4..5fac3bbd 100644 --- a/modules/backend/api-gateway/variables.tf +++ b/modules/backend/api-gateway/variables.tf @@ -182,3 +182,9 @@ variable "integration_request_parameters" { "integration.request.header.Content-Type" = "method.request.header.Content-Type" } } + +variable "force_redeploy" { + description = "When set to true, forces a redeployment of the api gateway on every apply. this is done by a timestamp" + type = bool + default = false +} \ No newline at end of file diff --git a/modules/database/atlas-cluster/README.md b/modules/database/atlas-cluster/README.md index 95eca3b5..837db618 100644 --- a/modules/database/atlas-cluster/README.md +++ b/modules/database/atlas-cluster/README.md @@ -20,7 +20,11 @@ | [mongo\_db\_major\_version](#input\_mongo\_db\_major\_version) | Version of the cluster to deploy. Atlas supports the following MongoDB versions for M10+ clusters: 4.2, 4.4, 5.0, or 6.0. | `string` | yes | | [provider\_instance\_size\_name](#input\_provider\_instance\_size\_name) | Atlas provides different instance sizes, each with a default storage capacity and RAM size | `string` | yes | | [region](#input\_region) | AWS region | `string` | yes | +| [auto\_scaling\_compute\_enabled](#input\_auto\_scaling\_compute\_enabled) | Enables auto-scaling UP for the atlas cluster's compute power | `bool` | no | +| [auto\_scaling\_compute\_scale\_down\_enabled](#input\_auto\_scaling\_compute\_scale\_down\_enabled) | Enables auto-scaling DOWN for the atlas cluster's compute power | `bool` | no | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | no | +| [provider\_auto\_scaling\_compute\_max\_instance\_size](#input\_provider\_auto\_scaling\_compute\_max\_instance\_size) | MAXIMUM Compute for autoscaling. Note - Need to set auto\_scaling\_compute\_enabled to true. make sure this value is BIGGER than provider\_auto\_scaling\_compute\_min\_instance\_size | `string` | no | +| [provider\_auto\_scaling\_compute\_min\_instance\_size](#input\_provider\_auto\_scaling\_compute\_min\_instance\_size) | MINIMUM Compute for autoscaling. Note - Need to set auto\_scaling\_compute\_scale\_down\_enabled to true. make sure this value is SMALLER than provider\_auto\_scaling\_compute\_max\_instance\_size | `string` | no | ## Outputs diff --git a/modules/database/atlas-cluster/main.tf b/modules/database/atlas-cluster/main.tf index ee64759b..abcff999 100644 --- a/modules/database/atlas-cluster/main.tf +++ b/modules/database/atlas-cluster/main.tf @@ -7,6 +7,20 @@ resource "mongodbatlas_cluster" "cluster-atlas" { auto_scaling_disk_gb_enabled = true mongo_db_major_version = var.mongo_db_major_version cluster_type = "REPLICASET" + + #Autoscaling sections + auto_scaling_compute_enabled = var.auto_scaling_compute_enabled + + # when the autoscaling compute enabled set to true, this var is initiated (default to M20). otherwise - null + provider_auto_scaling_compute_max_instance_size = var.auto_scaling_compute_enabled ? var.provider_auto_scaling_compute_max_instance_size : null + + # when the autoscaling compute enabled set to true, this var is initiated (default to true). otherwise - null + auto_scaling_compute_scale_down_enabled = var.auto_scaling_compute_enabled ? var.auto_scaling_compute_scale_down_enabled : null + + # when the autoscaling compute enabled set to true, this var is initiated (default to M10). otherwise - null + provider_auto_scaling_compute_min_instance_size = var.auto_scaling_compute_enabled ? var.provider_auto_scaling_compute_min_instance_size : null + + replication_specs { num_shards = 1 regions_config { diff --git a/modules/database/atlas-cluster/variables.tf b/modules/database/atlas-cluster/variables.tf index 8ee9113b..5361e542 100644 --- a/modules/database/atlas-cluster/variables.tf +++ b/modules/database/atlas-cluster/variables.tf @@ -65,3 +65,27 @@ variable "atlas_project_id" { description = "The ID of your MongoDB Atlas project" type = string } + +variable "auto_scaling_compute_enabled" { + description = "Enables auto-scaling UP for the atlas cluster's compute power" + type = bool + default = false +} + +variable "provider_auto_scaling_compute_max_instance_size" { + description = "MAXIMUM Compute for autoscaling. Note - Need to set auto_scaling_compute_enabled to true. make sure this value is BIGGER than provider_auto_scaling_compute_min_instance_size" + type = string + default = "M20" +} + +variable "auto_scaling_compute_scale_down_enabled" { + description = "Enables auto-scaling DOWN for the atlas cluster's compute power" + type = bool + default = true +} + +variable "provider_auto_scaling_compute_min_instance_size" { + description = "MINIMUM Compute for autoscaling. Note - Need to set auto_scaling_compute_scale_down_enabled to true. make sure this value is SMALLER than provider_auto_scaling_compute_max_instance_size" + type = string + default = "M10" +} \ No newline at end of file