Skip to content

Commit d69b4f7

Browse files
updated module structure, review and tested
1 parent 202838a commit d69b4f7

File tree

6 files changed

+53
-57
lines changed

6 files changed

+53
-57
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2023 SquareOps Technologies Pvt. Ltd.
189+
Copyright 2023 SquareOps Technologies Pvt. Ltd.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
@@ -198,4 +198,4 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

README.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,25 @@ Terraform Module to create Redis on AWS Cloud.
1515
1616
module "redis" {
1717
source = "gitlab.com/sq-ia/aws/redis.git"
18-
environment = "production"
19-
name = "SKAF"
20-
engine_version = "6.x"
21-
port = 6379
18+
environment = "production"
19+
name = "SKAF"
20+
family = "redis6.x"
2221
node_type = "cache.t3.small"
2322
num_cache_nodes = 2
24-
family = "redis6.x"
25-
availability_zones = [for n in range(0, 2) : data.aws_availability_zones.available.names[n]]
23+
engine_version = "6.x"
24+
availability_zones = 2
2625
automatic_failover_enabled = true
2726
snapshot_retention_limit = 7
28-
multi_az_enabled = false
2927
at_rest_encryption_enabled = true
3028
transit_encryption_enabled = false
3129
notification_topic_arn = null
32-
vpc_id = "vpc-06e37f0786b7eskaf"
33-
subnets = ["subnet-0bfc23c64ea3eskaf","subnet-0140024df275bskaf"]
34-
allowed_cidr_blocks = []
35-
allowed_security_groups = [sg-0132a41b5cd18skaf]
30+
vpc_id = "vpc-06eb7eskaf"
31+
subnets = ["subnet-0bfa3eskaf","subnet-0140bskaf"]
32+
kms_key_arn = "arn:aws:kms:us-east-2:222222222222:key/kms_key_arn"
33+
multi_az_enabled = false
34+
allowed_security_groups = [sg-0132a18skaf]
3635
maintenance_window = "sun:09:00-sun:10:00"
3736
snapshot_window = "07:00-08:00"
38-
kms_key_arn = "arn:aws:kms:us-east-2:222222222222:key/kms_key_arn"
3937
}
4038
4139
```
@@ -85,6 +83,7 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
8583
| [aws_security_group_rule.cidr_ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
8684
| [aws_security_group_rule.default_ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
8785
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
86+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
8887

8988
## Inputs
9089

@@ -93,16 +92,16 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
9392
| <a name="input_allowed_cidr_blocks"></a> [allowed\_cidr\_blocks](#input\_allowed\_cidr\_blocks) | A list of CIDR blocks which are allowed to access the database | `list(any)` | `[]` | no |
9493
| <a name="input_allowed_security_groups"></a> [allowed\_security\_groups](#input\_allowed\_security\_groups) | A list of Security Group ID's to allow access to | `list(any)` | `[]` | no |
9594
| <a name="input_at_rest_encryption_enabled"></a> [at\_rest\_encryption\_enabled](#input\_at\_rest\_encryption\_enabled) | (Optional) Whether to enable encryption at rest | `bool` | `true` | no |
96-
| <a name="input_automatic_failover_enabled"></a> [automatic\_failover\_enabled](#input\_automatic\_failover\_enabled) | Enable automatic failover | `bool` | `false` | no |
97-
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | The list of AZs | `list(string)` | `[]` | no |
95+
| <a name="input_automatic_failover_enabled"></a> [automatic\_failover\_enabled](#input\_automatic\_failover\_enabled) | Enable automatic failover | `bool` | `true` | no |
96+
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | The list of AZs | `string` | `2` | no |
9897
| <a name="input_engine_log_destination"></a> [engine\_log\_destination](#input\_engine\_log\_destination) | The destination for engine logs(eg. Cloudwatch log-group name or kinesis firehose stream name) | `string` | `null` | no |
9998
| <a name="input_engine_log_destination_type"></a> [engine\_log\_destination\_type](#input\_engine\_log\_destination\_type) | The type of destination for engine logs(eg . cloudwatch-logs or kinesis-firehose) | `string` | `""` | no |
10099
| <a name="input_engine_log_format"></a> [engine\_log\_format](#input\_engine\_log\_format) | the format for logs eg. json/text | `string` | `"json"` | no |
101100
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | The redis engine version | `string` | `""` | no |
102101
| <a name="input_environment"></a> [environment](#input\_environment) | The name of environment | `string` | `""` | no |
103102
| <a name="input_family"></a> [family](#input\_family) | Redis family | `string` | `"redis4.0"` | no |
104103
| <a name="input_final_snapshot_identifier"></a> [final\_snapshot\_identifier](#input\_final\_snapshot\_identifier) | The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made. | `string` | `null` | no |
105-
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if at\_rest\_encryption\_enabled = true | `string` | `""` | no |
104+
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if at\_rest\_encryption\_enabled = true | `string` | `""` | no |
106105
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period | `string` | `"fri:08:00-fri:09:00"` | no |
107106
| <a name="input_multi_az_enabled"></a> [multi\_az\_enabled](#input\_multi\_az\_enabled) | Enable multi az | `bool` | `false` | no |
108107
| <a name="input_name"></a> [name](#input\_name) | The name of the redis cluster | `string` | `""` | no |
@@ -116,7 +115,7 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
116115
| <a name="input_slow_log_destination_type"></a> [slow\_log\_destination\_type](#input\_slow\_log\_destination\_type) | The type of destination for slow logs(eg . cloudwatch-logs or kinesis-firehose) | `string` | `""` | no |
117116
| <a name="input_slow_log_format"></a> [slow\_log\_format](#input\_slow\_log\_format) | the format for logs eg. json/text | `string` | `"json"` | no |
118117
| <a name="input_snapshot_arns"></a> [snapshot\_arns](#input\_snapshot\_arns) | (Optional) A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my\_bucket/snapshot1.rdb . This will be used to add data to a fresh new instance. | `list(string)` | `[]` | no |
119-
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot\_retention\_limit is not supported on cache.t1.micro or cache.t2.* cache nodes | `number` | `0` | no |
118+
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot\_retention\_limit is not supported on cache.t1.micro or cache.t2.* cache nodes | `number` | `7` | no |
120119
| <a name="input_snapshot_window"></a> [snapshot\_window](#input\_snapshot\_window) | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum maintenance window is a 60 minute period. Example: 05:00-09:00 | `string` | `"03:00-05:00"` | no |
121120
| <a name="input_subnets"></a> [subnets](#input\_subnets) | The subnets where the redis cluster is deployed | `list(string)` | `[]` | no |
122121
| <a name="input_transit_encryption_enabled"></a> [transit\_encryption\_enabled](#input\_transit\_encryption\_enabled) | (Optional) Whether to enable encryption in transit | `bool` | `true` | no |
@@ -200,4 +199,3 @@ We believe that the key to success in the digital age is the ability to deliver
200199
We provide [support](https://squareops.com/contact-us/) on all of our projects, no matter how small or large they may be.
201200

202201
You can find more information about our company on this [squareops.com](https://squareops.com/), follow us on [linkdin](https://www.linkedin.com/company/squareops-technologies-pvt-ltd/), or fill out a [job application](https://squareops.com/careers/). If you have any questions or would like assistance with your cloud strategy and implementation, please don't hesitate to [contact us](https://squareops.com/contact-us/).
203-

examples/complete/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ No providers.
1414

1515
| Name | Source | Version |
1616
|------|--------|---------|
17-
| <a name="module_redis"></a> [redis](#module\_redis) | ../../ | n/a |
17+
| <a name="module_redis"></a> [redis](#module\_redis) | git@github.com:sq-ia/terraform-aws-elasticache-redis.git | n/a |
1818

1919
## Resources
2020

@@ -28,7 +28,9 @@ No inputs.
2828

2929
| Name | Description |
3030
|------|-------------|
31-
| <a name="output_elastic-cache-redis-endpoint"></a> [elastic-cache-redis-endpoint](#output\_elastic-cache-redis-endpoint) | Elasticache-redis cluster primary endpoint address |
31+
| <a name="output_auth_token_password"></a> [auth\_token\_password](#output\_auth\_token\_password) | Elasticache-redis auth token password(this password may be old, because Terraform doesn't track it after initial creation) |
32+
| <a name="output_elastic_cache_redis_endpoint"></a> [elastic\_cache\_redis\_endpoint](#output\_elastic\_cache\_redis\_endpoint) | Elasticache-redis cluster primary endpoint address |
33+
| <a name="output_elastic_cache_redis_security_group"></a> [elastic\_cache\_redis\_security\_group](#output\_elastic\_cache\_redis\_security\_group) | The security group ID of the cluster |
3234
| <a name="output_id_of_redis_cluster"></a> [id\_of\_redis\_cluster](#output\_id\_of\_redis\_cluster) | ID of the elasticache-redis cluster |
3335
| <a name="output_port_no"></a> [port\_no](#output\_port\_no) | Port number of Redis |
3436
| <a name="output_primary_endpoint_address"></a> [primary\_endpoint\_address](#output\_primary\_endpoint\_address) | Primary endpoint address of redis |

examples/complete/main.tf

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
locals {
2-
name = "skaf"
3-
region = "us-east-2"
4-
environment = "production"
5-
redis_engine_version = "6.x"
2+
name = "skaf"
3+
region = "us-east-1"
4+
family = "redis6.x"
5+
node_type = "cache.t3.small"
6+
vpc_id = "vpc-06f1a2f3a7"
7+
subnet_ids = ["subnet-0bb128ab", "subnet-0b54928666a"]
8+
kms_key_arn = "arn:aws:kms:us-east-1:2222222222:key/bcfdc1c5-1bbbdb467d90"
9+
environment = "prod"
10+
redis_engine_version = "6.0"
11+
allowed_security_groups = ["sg-0e8dab08e40"]
612
}
713

8-
data "aws_availability_zones" "available" {}
9-
1014
module "redis" {
11-
source = "../../"
12-
environment = local.environment
13-
name = local.name
14-
engine_version = local.redis_engine_version
15-
port = 6379
16-
node_type = "cache.t3.small"
17-
num_cache_nodes = 2
18-
family = "redis6.x"
19-
availability_zones = [for n in range(0, 2) : data.aws_availability_zones.available.names[n]]
20-
automatic_failover_enabled = true
21-
snapshot_retention_limit = 7
22-
multi_az_enabled = false
23-
at_rest_encryption_enabled = true
24-
transit_encryption_enabled = false
25-
notification_topic_arn = null
26-
vpc_id = "vpc-06e37f0786b7efaab"
27-
subnets = ["subnet-021320ad57f4ef6bb","subnet-04ec8cb5f9abd4941"]
28-
allowed_cidr_blocks = []
29-
allowed_security_groups = ["sg-028cc84f7ff452dfd"]
30-
maintenance_window = "sun:09:00-sun:10:00"
31-
snapshot_window = "07:00-08:00"
32-
kms_key_arn = "arn:aws:kms:us-east-2:271251951598:key/7fa600be-9c08-4502-a67a-ed7e8bc332cb"
15+
source = "git@github.com:sq-ia/terraform-aws-elasticache-redis.git"
16+
environment = local.environment
17+
name = local.name
18+
family = local.family
19+
node_type = local.node_type
20+
engine_version = local.redis_engine_version
21+
num_cache_nodes = 2
22+
vpc_id = local.vpc_id
23+
subnets = local.subnet_ids
24+
kms_key_arn = local.kms_key_arn
25+
multi_az_enabled = false
26+
availability_zones = 2
27+
snapshot_window = "07:00-08:00"
28+
maintenance_window = "sun:09:00-sun:10:00"
29+
allowed_security_groups = local.allowed_security_groups
3330
}
34-

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
locals {
42
tags = {
53
Environment = var.environment
@@ -8,6 +6,8 @@ locals {
86
engine_log = var.engine_log_destination == null ? [] : [1]
97
}
108

9+
data "aws_availability_zones" "available" {}
10+
1111
resource "random_password" "password" {
1212
length = 16
1313
special = false
@@ -40,7 +40,7 @@ resource "aws_elasticache_replication_group" "redis" {
4040
parameter_group_name = join("", aws_elasticache_parameter_group.default.*.name) #var.parameter_group_name
4141
security_group_ids = [module.security_group_redis.security_group_id]
4242
subnet_group_name = aws_elasticache_subnet_group.elasticache.id
43-
availability_zones = var.availability_zones
43+
availability_zones = [for n in range(0, var.availability_zones) : data.aws_availability_zones.available.names[n]]
4444
automatic_failover_enabled = var.automatic_failover_enabled
4545
snapshot_window = var.snapshot_window
4646
snapshot_retention_limit = var.snapshot_retention_limit

variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ variable "port" {
5757

5858
variable "automatic_failover_enabled" {
5959
description = "Enable automatic failover "
60-
default = false
60+
default = true
6161
type = bool
6262
}
6363

@@ -70,8 +70,8 @@ variable "multi_az_enabled" {
7070

7171
variable "availability_zones" {
7272
description = "The list of AZs"
73-
default = []
74-
type = list(string)
73+
default = 2
74+
type = string
7575
}
7676

7777
variable "snapshot_window" {
@@ -82,7 +82,7 @@ variable "snapshot_window" {
8282

8383
variable "snapshot_retention_limit" {
8484
description = "The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot_retention_limit is not supported on cache.t1.micro or cache.t2.* cache nodes"
85-
default = 0
85+
default = 7
8686
type = number
8787
}
8888

0 commit comments

Comments
 (0)