Skip to content

Commit f84919d

Browse files
Merge pull request #6 from yuvraj-squareops1/main
added features for cluster mode enable
2 parents 453eb4f + 45f2b3a commit f84919d

File tree

13 files changed

+400
-39
lines changed

13 files changed

+400
-39
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
111111
| [aws_kms_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
112112
| [aws_lambda_permission.sns_lambda_slack_invoke](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
113113
| [aws_secretsmanager_secret.secret_redis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
114+
| [aws_secretsmanager_secret_version.redis_credentials](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
114115
| [aws_security_group_rule.cidr_ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
115116
| [aws_security_group_rule.default_ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
116117
| [aws_sns_topic.slack_topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
117118
| [aws_sns_topic_subscription.slack-endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |
118119
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
119120
| [archive_file.lambdazip](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |
120-
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
121121

122122
## Inputs
123123

@@ -130,8 +130,11 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
130130
| <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 |
131131
| <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 |
132132
| <a name="input_automatic_failover_enabled"></a> [automatic\_failover\_enabled](#input\_automatic\_failover\_enabled) | Enable automatic failover | `bool` | `true` | no |
133-
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | The no. of AZs | `string` | `2` | no |
133+
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | The no. of AZs | `list(string)` | `[]` | no |
134134
| <a name="input_cloudwatch_metric_alarms_enabled"></a> [cloudwatch\_metric\_alarms\_enabled](#input\_cloudwatch\_metric\_alarms\_enabled) | Boolean flag to enable/disable CloudWatch metrics alarms | `bool` | `false` | no |
135+
| <a name="input_cluster_mode_enabled"></a> [cluster\_mode\_enabled](#input\_cluster\_mode\_enabled) | Whether to enable/disable creation of a native redis cluster. | `bool` | `false` | no |
136+
| <a name="input_cluster_mode_num_node_groups"></a> [cluster\_mode\_num\_node\_groups](#input\_cluster\_mode\_num\_node\_groups) | Number of node groups (shards) for this Redis replication group. | `number` | `0` | no |
137+
| <a name="input_cluster_mode_replicas_per_node_group"></a> [cluster\_mode\_replicas\_per\_node\_group](#input\_cluster\_mode\_replicas\_per\_node\_group) | Number of replica nodes in each node group. Valid values are between 0 to 5. | `number` | `0` | no |
135138
| <a name="input_cw_sns_topic_arn"></a> [cw\_sns\_topic\_arn](#input\_cw\_sns\_topic\_arn) | The username to use when sending notifications to Slack. | `string` | `""` | no |
136139
| <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 |
137140
| <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 |
@@ -148,6 +151,7 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
148151
| <a name="input_notification_topic_arn"></a> [notification\_topic\_arn](#input\_notification\_topic\_arn) | (Optional) ARN of an SNS topic to send ElastiCache notifications | `string` | `null` | no |
149152
| <a name="input_num_cache_nodes"></a> [num\_cache\_nodes](#input\_num\_cache\_nodes) | The number of cache nodes | `number` | `1` | no |
150153
| <a name="input_ok_actions"></a> [ok\_actions](#input\_ok\_actions) | The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN) | `list(string)` | `[]` | no |
154+
| <a name="input_parameter"></a> [parameter](#input\_parameter) | A list of Redis parameters to apply. It can be different based on mode slection. | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
151155
| <a name="input_parameter_group_description"></a> [parameter\_group\_description](#input\_parameter\_group\_description) | Parameter group | `string` | `null` | no |
152156
| <a name="input_port"></a> [port](#input\_port) | The redis port | `number` | `6379` | no |
153157
| <a name="input_recovery_window_aws_secret"></a> [recovery\_window\_aws\_secret](#input\_recovery\_window\_aws\_secret) | Number of days that AWS Secrets Manager waits before it can delete the secret. This value can be 0 to force deletion without recovery or range from 7 to 30 days. | `number` | `0` | no |
@@ -170,11 +174,11 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
170174
|------|-------------|
171175
| <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) |
172176
| <a name="output_elastic_cache_redis_cluster_id"></a> [elastic\_cache\_redis\_cluster\_id](#output\_elastic\_cache\_redis\_cluster\_id) | ID of the elasticache-redis cluster |
173-
| <a name="output_elastic_cache_redis_endpoint"></a> [elastic\_cache\_redis\_endpoint](#output\_elastic\_cache\_redis\_endpoint) | Elasticache-redis cluster primary endpoint address |
174177
| <a name="output_elastic_cache_redis_port"></a> [elastic\_cache\_redis\_port](#output\_elastic\_cache\_redis\_port) | Port number of Redis |
175178
| <a name="output_elastic_cache_redis_primary_endpoint_address"></a> [elastic\_cache\_redis\_primary\_endpoint\_address](#output\_elastic\_cache\_redis\_primary\_endpoint\_address) | Primary endpoint address of redis |
176179
| <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 |
177180
| <a name="output_elastic_cache_redis_subnet_group_name"></a> [elastic\_cache\_redis\_subnet\_group\_name](#output\_elastic\_cache\_redis\_subnet\_group\_name) | Subnet group name of the elasticache\_redis cluster |
181+
| <a name="output_reader_endpoint_address"></a> [reader\_endpoint\_address](#output\_reader\_endpoint\_address) | The address of the endpoint for the reader node in the replication group, if the cluster mode is disabled. |
178182
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
179183

180184
## Contribute & Issue Report
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Redis Example With Cluster Mode Enable
2+
![squareops_avatar]
3+
4+
[squareops_avatar]: https://squareops.com/wp-content/uploads/2022/12/squareops-logo.png
5+
6+
### [SquareOps Technologies](https://squareops.com/) Your DevOps Partner for Accelerating cloud journey.
7+
<br>
8+
9+
This example will be very useful for users who are new to a module and want to quickly learn how to use it. By reviewing the examples, users can gain a better understanding of how the module works, what features it supports, and how to customize it to their specific needs.
10+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
11+
## Requirements
12+
13+
| Name | Version |
14+
|------|---------|
15+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
16+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.63 |
17+
18+
## Providers
19+
20+
No providers.
21+
22+
## Modules
23+
24+
| Name | Source | Version |
25+
|------|--------|---------|
26+
| <a name="module_redis"></a> [redis](#module\_redis) | squareops/elasticache-redis/aws | n/a |
27+
28+
## Resources
29+
30+
No resources.
31+
32+
## Inputs
33+
34+
No inputs.
35+
36+
## Outputs
37+
38+
| Name | Description |
39+
|------|-------------|
40+
| <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) |
41+
| <a name="output_elastic_cache_redis_endpoint"></a> [elastic\_cache\_redis\_endpoint](#output\_elastic\_cache\_redis\_endpoint) | Elasticache-redis cluster primary endpoint address |
42+
| <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 |
43+
| <a name="output_id_of_redis_cluster"></a> [id\_of\_redis\_cluster](#output\_id\_of\_redis\_cluster) | ID of the elasticache-redis cluster |
44+
| <a name="output_port_no"></a> [port\_no](#output\_port\_no) | Port number of Redis |
45+
| <a name="output_primary_endpoint_address"></a> [primary\_endpoint\_address](#output\_primary\_endpoint\_address) | Primary endpoint address of redis |
46+
| <a name="output_redis_subnet_group_name"></a> [redis\_subnet\_group\_name](#output\_redis\_subnet\_group\_name) | Subnet group name of the elasticache-redis cluster |
47+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
locals {
2+
name = "redis"
3+
region = "us-east-2"
4+
family = "redis6.x"
5+
node_type = "cache.t3.small"
6+
vpc_cidr = "10.0.0.0/16"
7+
environment = "prod"
8+
allowed_security_groups = ["sg-02c3f55874f6e0c64"]
9+
redis_engine_version = "6.0"
10+
additional_tags = {
11+
Owner = "Organization_Name"
12+
Expires = "Never"
13+
Department = "Engineering"
14+
}
15+
current_identity = data.aws_caller_identity.current.arn
16+
availability_zones = slice(data.aws_availability_zones.primary.names, 0, 3)
17+
cluster_mode_enabled = true
18+
}
19+
20+
data "aws_availability_zones" "primary" {}
21+
data "aws_caller_identity" "current" {}
22+
data "aws_region" "current" {}
23+
24+
module "kms" {
25+
source = "terraform-aws-modules/kms/aws"
26+
27+
deletion_window_in_days = 7
28+
description = "Complete key example showing various configurations available"
29+
enable_key_rotation = false
30+
is_enabled = true
31+
key_usage = "ENCRYPT_DECRYPT"
32+
multi_region = false
33+
34+
# Policy
35+
enable_default_policy = true
36+
key_owners = [local.current_identity]
37+
key_administrators = [local.current_identity]
38+
key_users = [local.current_identity]
39+
key_service_users = [local.current_identity]
40+
key_statements = [
41+
{
42+
sid = "Allow use of the key"
43+
actions = [
44+
"kms:Encrypt*",
45+
"kms:Decrypt*",
46+
"kms:ReEncrypt*",
47+
"kms:GenerateDataKey*",
48+
"kms:Describe*"
49+
]
50+
resources = ["*"]
51+
52+
principals = [
53+
{
54+
type = "Service"
55+
identifiers = [
56+
"elasticache.amazonaws.com"
57+
]
58+
}
59+
]
60+
},
61+
{
62+
sid = "Enable IAM User Permissions"
63+
actions = ["kms:*"]
64+
resources = ["*"]
65+
66+
principals = [
67+
{
68+
type = "AWS"
69+
identifiers = [
70+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:root",
71+
data.aws_caller_identity.current.arn,
72+
]
73+
}
74+
]
75+
}
76+
]
77+
78+
# Aliases
79+
aliases = ["${local.name}"]
80+
81+
tags = local.additional_tags
82+
}
83+
84+
module "vpc" {
85+
source = "squareops/vpc/aws"
86+
version = "3.3.1"
87+
name = local.name
88+
vpc_cidr = local.vpc_cidr
89+
environment = local.environment
90+
availability_zones = local.availability_zones
91+
public_subnet_enabled = true
92+
auto_assign_public_ip = true
93+
intra_subnet_enabled = false
94+
private_subnet_enabled = true
95+
one_nat_gateway_per_az = false
96+
database_subnet_enabled = true
97+
}
98+
99+
module "redis" {
100+
source = "squareops/elasticache-redis/aws"
101+
name = local.name
102+
family = local.family
103+
node_type = local.node_type
104+
environment = local.environment
105+
engine_version = local.redis_engine_version
106+
cluster_mode_enabled = local.cluster_mode_enabled
107+
cluster_mode_num_node_groups = 1
108+
cluster_mode_replicas_per_node_group = 2
109+
vpc_id = module.vpc.vpc_id
110+
subnets = module.vpc.database_subnets
111+
kms_key_arn = module.kms.key_arn
112+
multi_az_enabled = true
113+
availability_zones = local.availability_zones
114+
snapshot_window = "07:00-08:00"
115+
maintenance_window = "sun:09:00-sun:10:00"
116+
allowed_security_groups = local.allowed_security_groups
117+
cloudwatch_metric_alarms_enabled = false
118+
alarm_cpu_threshold_percent = 70
119+
alarm_memory_threshold_bytes = "10000000" # in bytes
120+
slack_username = ""
121+
slack_channel = ""
122+
slack_webhook_url = ""
123+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
output "primary_endpoint_address" {
2+
description = "Primary endpoint address of redis"
3+
value = module.redis.elastic_cache_redis_primary_endpoint_address
4+
}
5+
6+
output "redis_subnet_group_name" {
7+
description = "Subnet group name of the elasticache-redis cluster"
8+
value = module.redis.elastic_cache_redis_subnet_group_name
9+
10+
}
11+
12+
output "id_of_redis_cluster" {
13+
description = "ID of the elasticache-redis cluster"
14+
value = module.redis.elastic_cache_redis_cluster_id
15+
}
16+
17+
output "port_no" {
18+
description = "Port number of Redis"
19+
value = module.redis.elastic_cache_redis_port
20+
}
21+
22+
output "elastic_cache_redis_reader_endpoint" {
23+
description = "Elasticache-redis cluster primary endpoint address"
24+
value = module.redis.reader_endpoint_address
25+
}
26+
27+
output "elastic_cache_redis_security_group" {
28+
description = "The security group ID of the cluster"
29+
value = module.redis.elastic_cache_redis_security_group
30+
}
31+
32+
output "auth_token_password" {
33+
description = "Elasticache-redis auth token password(this password may be old, because Terraform doesn't track it after initial creation)"
34+
value = module.redis.auth_token_password
35+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "aws" {
2+
region = local.region
3+
default_tags {
4+
tags = local.additional_tags
5+
}
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 0.13"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = ">= 3.63"
7+
}
8+
}
9+
}

examples/complete/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@ This example will be very useful for users who are new to a module and want to q
1717

1818
## Providers
1919

20-
No providers.
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.63 |
2123

2224
## Modules
2325

2426
| Name | Source | Version |
2527
|------|--------|---------|
28+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | n/a |
2629
| <a name="module_redis"></a> [redis](#module\_redis) | squareops/elasticache-redis/aws | n/a |
30+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | squareops/vpc/aws | 3.3.1 |
2731

2832
## Resources
2933

30-
No resources.
34+
| Name | Type |
35+
|------|------|
36+
| [aws_availability_zones.primary](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
37+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
38+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
3139

3240
## Inputs
3341

@@ -38,7 +46,7 @@ No inputs.
3846
| Name | Description |
3947
|------|-------------|
4048
| <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) |
41-
| <a name="output_elastic_cache_redis_endpoint"></a> [elastic\_cache\_redis\_endpoint](#output\_elastic\_cache\_redis\_endpoint) | Elasticache-redis cluster primary endpoint address |
49+
| <a name="output_elastic_cache_redis_reader_endpoint"></a> [elastic\_cache\_redis\_reader\_endpoint](#output\_elastic\_cache\_redis\_reader\_endpoint) | Elasticache-redis cluster primary endpoint address |
4250
| <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 |
4351
| <a name="output_id_of_redis_cluster"></a> [id\_of\_redis\_cluster](#output\_id\_of\_redis\_cluster) | ID of the elasticache-redis cluster |
4452
| <a name="output_port_no"></a> [port\_no](#output\_port\_no) | Port number of Redis |

0 commit comments

Comments
 (0)