Skip to content

Commit 2104ff4

Browse files
committed
add support for custom sg and notification_topic_arn
1 parent c3a08a9 commit 2104ff4

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
5151
| auto\_minor\_version\_upgrade | | string | `"true"` | no |
5252
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | string | `"true"` | no |
5353
| description | The description of the all resources. | string | `"Managed by Terraform"` | no |
54-
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.0"` | no |
54+
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.6"` | no |
5555
| family | The family of the ElastiCache parameter group. | string | `"redis5.0"` | no |
5656
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | list(string) | `[]` | no |
5757
| 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 |
5858
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | string | `""` | no |
59+
| notification\_topic\_arn | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic` | string | `""` | no |
5960
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `[]` | no |
6061
| port | The port number on which each of the cache nodes will accept connections. | string | `"6379"` | no |
62+
| security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
6163
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | string | `"30"` | no |
6264
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | string | `""` | no |
63-
| source\_security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
6465
| tags | A mapping of tags to assign to all resources. | map(string) | `{}` | no |
6566
| transit\_encryption\_enabled | Whether to enable encryption in transit. | string | `"true"` | no |
6667

examples/core/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ terraform apply --auto-approve
2323
| auto\_minor\_version\_upgrade | | string | `"true"` | no |
2424
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | string | `"true"` | no |
2525
| description | The description of the all resources. | string | `"Managed by Terraform"` | no |
26-
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.0"` | no |
26+
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.6"` | no |
2727
| family | The family of the ElastiCache parameter group. | string | `"redis5.0"` | no |
2828
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | list(string) | `[]` | no |
2929
| 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 |
3030
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | string | `""` | no |
31+
| notification\_topic\_arn | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic` | string | `""` | no |
3132
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `[]` | no |
3233
| port | The port number on which each of the cache nodes will accept connections. | string | `"6379"` | no |
34+
| security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
3335
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | string | `"30"` | no |
3436
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | string | `""` | no |
35-
| source\_security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
3637
| tags | A mapping of tags to assign to all resources. | map(string) | `{}` | no |
3738
| transit\_encryption\_enabled | Whether to enable encryption in transit. | string | `"true"` | no |
3839

examples/core/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module "vpc" {
3030
module "redis" {
3131
source = "../../"
3232

33-
name_prefix = "core-example-redis"
33+
name_prefix = "core-example"
3434
number_cache_clusters = 2
3535
node_type = "cache.t3.small"
3636

main.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ resource "aws_elasticache_replication_group" "redis" {
33

44
parameter_group_name = aws_elasticache_parameter_group.redis.name
55
subnet_group_name = aws_elasticache_subnet_group.redis.name
6-
security_group_ids = [aws_security_group.redis.id]
6+
security_group_ids = concat(var.security_group_ids, [aws_security_group.redis.id])
77

8-
replication_group_id = var.name_prefix
8+
replication_group_id = "${var.name_prefix}-redis"
99
number_cache_clusters = var.number_cache_clusters
1010
node_type = var.node_type
1111

@@ -27,16 +27,18 @@ resource "aws_elasticache_replication_group" "redis" {
2727

2828
replication_group_description = var.description
2929

30+
notification_topic_arn = var.notification_topic_arn
31+
3032
tags = merge(
3133
{
32-
"Name" = var.name_prefix
34+
"Name" = "${var.name_prefix}-redis"
3335
},
3436
var.tags,
3537
)
3638
}
3739

3840
resource "aws_elasticache_parameter_group" "redis" {
39-
name = var.name_prefix
41+
name = "${var.name_prefix}-redis-pg"
4042
family = var.family
4143
description = var.description
4244

@@ -50,7 +52,7 @@ resource "aws_elasticache_parameter_group" "redis" {
5052
}
5153

5254
resource "aws_elasticache_subnet_group" "redis" {
53-
name = var.name_prefix
55+
name = "${var.name_prefix}-redis-sg"
5456
subnet_ids = var.subnet_ids
5557
description = var.description
5658
}
@@ -61,10 +63,14 @@ resource "aws_security_group" "redis" {
6163

6264
tags = merge(
6365
{
64-
"Name" = "${var.name_prefix}"
66+
"Name" = "${var.name_prefix}-redis"
6567
},
6668
var.tags
6769
)
70+
71+
lifecycle {
72+
create_before_destroy = true
73+
}
6874
}
6975

7076
resource "aws_security_group_rule" "redis_ingress_cidr_blocks" {

variables.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ variable "ingress_cidr_blocks" {
2929
default = []
3030
}
3131

32-
variable "source_security_group_ids" {
32+
variable "security_group_ids" {
3333
type = list(string)
3434
description = "List of Security Groups."
3535
default = []
3636
}
3737

3838
variable "engine_version" {
39-
default = "5.0.0"
39+
default = "5.0.6"
4040
type = string
4141
description = "The version number of the cache engine to be used for the cache clusters in this replication group."
4242
}
@@ -133,4 +133,8 @@ variable "parameter" {
133133
description = "A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another"
134134
}
135135

136-
136+
variable "notification_topic_arn" {
137+
type = string
138+
default = ""
139+
description = "An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic`"
140+
}

0 commit comments

Comments
 (0)