Skip to content

Commit f68a930

Browse files
committed
fix the code login and tested.
1 parent c30e4fd commit f68a930

File tree

6 files changed

+89
-32
lines changed

6 files changed

+89
-32
lines changed

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ No modules.
2222

2323
| Name | Type |
2424
|------|------|
25-
| [aws_elasticache_cluster.replica](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster) | resource |
26-
| [aws_elasticache_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster) | resource |
25+
| [aws_cloudwatch_metric_alarm.cache_cpu](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
26+
| [aws_cloudwatch_metric_alarm.cache_memory](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
2727
| [aws_elasticache_parameter_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_parameter_group) | resource |
2828
| [aws_elasticache_replication_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group) | resource |
2929
| [aws_elasticache_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
@@ -36,31 +36,48 @@ No modules.
3636
| <a name="input_alarm_cpu_threshold_percent"></a> [alarm\_cpu\_threshold\_percent](#input\_alarm\_cpu\_threshold\_percent) | CPU threshold alarm level | `number` | `75` | no |
3737
| <a name="input_alarm_memory_threshold_bytes"></a> [alarm\_memory\_threshold\_bytes](#input\_alarm\_memory\_threshold\_bytes) | Alarm memory threshold bytes | `number` | `10000000` | no |
3838
| <a name="input_apply_immediately"></a> [apply\_immediately](#input\_apply\_immediately) | Specifies whether any database modifications are applied immediately, or during the next maintenance window | `bool` | `true` | no |
39+
| <a name="input_auth_token"></a> [auth\_token](#input\_auth\_token) | Password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true` | `string` | `null` | no |
3940
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | Cluster ID | `string` | `null` | no |
41+
| <a name="input_cluster_mode_enabled"></a> [cluster\_mode\_enabled](#input\_cluster\_mode\_enabled) | Set to false to diable cluster module | `bool` | `false` | no |
4042
| <a name="input_cluster_size"></a> [cluster\_size](#input\_cluster\_size) | Cluster size | `number` | `1` | no |
4143
| <a name="input_create_elasticache_subnet_group"></a> [create\_elasticache\_subnet\_group](#input\_create\_elasticache\_subnet\_group) | Create Elasticache Subnet Group | `bool` | `false` | no |
4244
| <a name="input_elasticache_parameter_group_family"></a> [elasticache\_parameter\_group\_family](#input\_elasticache\_parameter\_group\_family) | ElastiCache parameter group family | `string` | `"memcached1.6"` | no |
4345
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `true` | no |
4446
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | Memcached engine version. For more info, see https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/supported-engine-versions.html | `string` | `"1.6.6"` | no |
4547
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Elastic cache instance type | `string` | `"cache.t2.micro"` | no |
48+
| <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` | `null` | no |
4649
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | Maintenance window | `string` | `"wed:03:00-wed:04:00"` | no |
4750
| <a name="input_name"></a> [name](#input\_name) | Name of the application | `string` | `"value"` | no |
4851
| <a name="input_notification_topic_arn"></a> [notification\_topic\_arn](#input\_notification\_topic\_arn) | ARN of an SNS topic to send ElastiCache notifications | `string` | `""` | no |
52+
| <a name="input_num_node_groups"></a> [num\_node\_groups](#input\_num\_node\_groups) | Number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications. Required unless `global_replication_group_id` is set | `number` | `2` | no |
4953
| <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. | `list(string)` | `[]` | no |
5054
| <a name="input_parameter_group_name"></a> [parameter\_group\_name](#input\_parameter\_group\_name) | Excisting Parameter Group name | `string` | `""` | no |
5155
| <a name="input_parameters"></a> [parameters](#input\_parameters) | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
52-
| <a name="input_port"></a> [port](#input\_port) | Memcached port | `number` | `11211` | no |
56+
| <a name="input_port"></a> [port](#input\_port) | Redis port | `number` | `6379` | no |
5357
| <a name="input_preferred_cache_cluster_azs"></a> [preferred\_cache\_cluster\_azs](#input\_preferred\_cache\_cluster\_azs) | List of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is considered. The first item in the list will be the primary node. Ignored when updating | `list(string)` | <pre>[<br> "ap-southeast-1a",<br> "ap-southeast-1b"<br>]</pre> | no |
54-
| <a name="input_replication_enabled"></a> [replication\_enabled](#input\_replication\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `false` | no |
58+
| <a name="input_replicas_per_node_group"></a> [replicas\_per\_node\_group](#input\_replicas\_per\_node\_group) | Number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will trigger an online resizing operation before other settings modifications. | `number` | `1` | no |
59+
| <a name="input_replication_enabled"></a> [replication\_enabled](#input\_replication\_enabled) | Set to false to diable replication in redis cluster | `bool` | `false` | no |
5560
| <a name="input_replication_group_id"></a> [replication\_group\_id](#input\_replication\_group\_id) | ElastiCache replication\_group\_id | `string` | `""` | no |
5661
| <a name="input_security_groups"></a> [security\_groups](#input\_security\_groups) | List of Security Group IDs to place the cluster into | `list(string)` | `[]` | no |
57-
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | 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 snapshot\_retention\_limit is set to zero (0), backups are turned off. Please note that setting a snapshot\_retention\_limit is not supported on cache.t1.micro cache nodes | `number` | `0` | no |
62+
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | 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 snapshot\_retention\_limit is set to zero (0), backups are turned off. Please note that setting a snapshot\_retention\_limit is not supported on cache.t1.micro cache nodes | `number` | `5` | no |
5863
| <a name="input_subnet_group_name"></a> [subnet\_group\_name](#input\_subnet\_group\_name) | Subnet group name for the ElastiCache instance | `string` | `""` | no |
5964
| <a name="input_subnets"></a> [subnets](#input\_subnets) | AWS subnet ids | `list(string)` | `[]` | no |
6065
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (\_e.g.\_ map("BusinessUnit","ABC") | `map(string)` | `{}` | no |
61-
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID | `string` | n/a | yes |
6266

6367
## Outputs
6468

65-
No outputs.
69+
| Name | Description |
70+
|------|-------------|
71+
| <a name="output_arn"></a> [arn](#output\_arn) | Elasticache Replication Group ARN |
72+
| <a name="output_cluster_enabled"></a> [cluster\_enabled](#output\_cluster\_enabled) | Indicates if cluster mode is enabled. |
73+
| <a name="output_configuration_endpoint_address"></a> [configuration\_endpoint\_address](#output\_configuration\_endpoint\_address) | Address of the replication group configuration endpoint when cluster mode is enabled. |
74+
| <a name="output_endpoint"></a> [endpoint](#output\_endpoint) | Redis primary or configuration endpoint, whichever is appropriate for the given cluster mode |
75+
| <a name="output_engine_version_actual"></a> [engine\_version\_actual](#output\_engine\_version\_actual) | Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine. |
76+
| <a name="output_id"></a> [id](#output\_id) | ID of the ElastiCache Replication Group. |
77+
| <a name="output_member_clusters"></a> [member\_clusters](#output\_member\_clusters) | Redis cluster members |
78+
| <a name="output_parameter_group_arn"></a> [parameter\_group\_arn](#output\_parameter\_group\_arn) | The AWS ARN associated with the parameter group. |
79+
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | The ElastiCache parameter group name. |
80+
| <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 |
81+
| <a name="output_subnet_group_name"></a> [subnet\_group\_name](#output\_subnet\_group\_name) | The Name of the ElastiCache Subnet Group. |
82+
| <a name="output_subnet_group_subnet_ids"></a> [subnet\_group\_subnet\_ids](#output\_subnet\_group\_subnet\_ids) | The Subnet IDs of the ElastiCache Subnet Group. |
6683
<!-- END_TF_DOCS -->

alarms.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
2525
ok_actions = var.ok_actions
2626

2727
depends_on = [
28-
aws_elasticache_cluster.this
28+
aws_elasticache_replication_group.this
2929
]
3030
}
3131

@@ -56,6 +56,6 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
5656
ok_actions = var.ok_actions
5757

5858
depends_on = [
59-
aws_elasticache_cluster.this
59+
aws_elasticache_replication_group.this
6060
]
6161
}

examples/main.tf

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
data "aws_caller_identity" "current" {}
22

33
locals {
4-
vpc_id = "vpc-0454bbcd698f2a399"
4+
vpc_id = "vpc-0123456789"
55

66
db_subnets = [
77
"10.0.2.0/24",
@@ -13,31 +13,27 @@ module "redis" {
1313
source = "../"
1414

1515
enabled = true
16-
shards_enabled = false
1716
cluster_mode_enabled = false
1817
create_elasticache_subnet_group = false
1918
replication_enabled = true
2019

2120
subnets = local.db_subnets
2221

23-
name = "redis-replic-test-cluster-module"
22+
name = "redis-test-cluster-module"
2423
port = 6379
2524

2625
instance_type = "cache.t2.small"
2726
engine_version = "5.0.6"
28-
security_groups = ["sg-03e6a972953f703ea"]
27+
security_groups = ["sg-0123456789"]
2928

3029
subnet_group_name = "default"
3130
elasticache_parameter_group_family = "redis5.0"
3231

3332
cluster_size = 1
3433

35-
# alarm_actions = ["arn:aws:sns:us-east-1:012345:test"]
36-
# sns_name = "test-sns-memcached-cluster"
37-
3834
apply_immediately = true
3935

4036
tags = {
41-
description = "redis-replic-test-cluster-module"
37+
description = "redis-test-cluster-module"
4238
}
4339
}

main.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ resource "aws_elasticache_subnet_group" "this" {
2525
subnet_ids = var.subnets
2626
}
2727

28-
29-
resource "aws_elasticache_cluster" "this" {
30-
count = var.enabled && var.shards_enabled ? 1 : 0
31-
32-
cluster_id = local.cluster_id
33-
replication_group_id = aws_elasticache_replication_group.this[0].id
34-
35-
}
36-
3728
resource "aws_elasticache_replication_group" "this" {
3829
count = var.enabled ? 1 : 0
3930

outputs.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
output "endpoint" {
2+
description = "Redis primary or configuration endpoint, whichever is appropriate for the given cluster mode"
3+
value = aws_elasticache_replication_group.this[0].primary_endpoint_address
4+
}
5+
6+
output "reader_endpoint_address" {
7+
description = "The address of the endpoint for the reader node in the replication group, if the cluster mode is disabled"
8+
value = aws_elasticache_replication_group.this[0].reader_endpoint_address
9+
}
10+
11+
output "member_clusters" {
12+
description = "Redis cluster members"
13+
value = aws_elasticache_replication_group.this[0].member_clusters
14+
}
15+
16+
output "arn" {
17+
description = "Elasticache Replication Group ARN"
18+
value = aws_elasticache_replication_group.this[0].arn
19+
}
20+
21+
output "cluster_enabled" {
22+
description = "Indicates if cluster mode is enabled."
23+
value = aws_elasticache_replication_group.this[0].cluster_enabled
24+
}
25+
26+
output "id" {
27+
description = "ID of the ElastiCache Replication Group."
28+
value = aws_elasticache_replication_group.this[0].id
29+
}
30+
31+
output "configuration_endpoint_address" {
32+
description = "Address of the replication group configuration endpoint when cluster mode is enabled."
33+
value = aws_elasticache_replication_group.this[0].configuration_endpoint_address
34+
}
35+
36+
output "engine_version_actual" {
37+
description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine."
38+
value = aws_elasticache_replication_group.this[0].engine_version_actual
39+
}
40+
41+
output "subnet_group_name" {
42+
description = "The Name of the ElastiCache Subnet Group."
43+
value = aws_elasticache_subnet_group.this[0].name
44+
}
45+
46+
output "subnet_group_subnet_ids" {
47+
description = "The Subnet IDs of the ElastiCache Subnet Group."
48+
value = aws_elasticache_subnet_group.this[0].subnet_ids
49+
}
50+
51+
output "parameter_group_arn" {
52+
description = "The AWS ARN associated with the parameter group."
53+
value = aws_elasticache_parameter_group.this[0].arn
54+
}
55+
56+
output "parameter_group_id" {
57+
description = "The ElastiCache parameter group name."
58+
value = aws_elasticache_parameter_group.this[0].id
59+
}

variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ variable "cluster_mode_enabled" {
1616
default = false
1717
}
1818

19-
variable "shards_enabled" {
20-
description = "Set to false to diable shards in redis cluster"
21-
type = bool
22-
default = false
23-
}
24-
2519
variable "name" {
2620
description = "Name of the application"
2721
type = string

0 commit comments

Comments
 (0)