1
1
data "aws_vpc" "vpc" {
2
- id = " ${ var . vpc_id } "
2
+ id = var. vpc_id
3
3
}
4
4
5
5
resource "random_id" "salt" {
6
6
byte_length = 8
7
7
}
8
8
9
9
resource "aws_elasticache_replication_group" "redis" {
10
- replication_group_id = " ${ format (" %.20s" , " ${ var . name } -${ var . env } " )} "
10
+ replication_group_id = format (" %.20s" , " ${ var . name } -${ var . env } " )
11
11
replication_group_description = " Terraform-managed ElastiCache replication group for ${ var . name } -${ var . env } -${ data . aws_vpc . vpc . tags [" Name" ]} "
12
- number_cache_clusters = " ${ var . redis_clusters } "
13
- node_type = " ${ var . redis_node_type } "
14
- automatic_failover_enabled = " ${ var . redis_failover } "
15
- engine_version = " ${ var . redis_version } "
16
- port = " ${ var . redis_port } "
17
- parameter_group_name = " ${ aws_elasticache_parameter_group . redis_parameter_group . id } "
18
- subnet_group_name = " ${ aws_elasticache_subnet_group . redis_subnet_group . id } "
19
- security_group_ids = [" ${ aws_security_group . redis_security_group . id } " ]
20
- apply_immediately = " ${ var . apply_immediately } "
21
- maintenance_window = " ${ var . redis_maintenance_window } "
22
- snapshot_window = " ${ var . redis_snapshot_window } "
23
- snapshot_retention_limit = " ${ var . redis_snapshot_retention_limit } "
24
- tags = " ${ merge (map (" Name" , format (" tf-elasticache-%s-%s" , var. name , lookup (data. aws_vpc . vpc . tags , " Name" , " " ))), var. tags )} "
12
+ number_cache_clusters = var. redis_clusters
13
+ node_type = var. redis_node_type
14
+ automatic_failover_enabled = var. redis_failover
15
+ engine_version = var. redis_version
16
+ port = var. redis_port
17
+ parameter_group_name = aws_elasticache_parameter_group. redis_parameter_group . id
18
+ subnet_group_name = aws_elasticache_subnet_group. redis_subnet_group . id
19
+ security_group_ids = [aws_security_group . redis_security_group . id ]
20
+ apply_immediately = var. apply_immediately
21
+ maintenance_window = var. redis_maintenance_window
22
+ snapshot_window = var. redis_snapshot_window
23
+ snapshot_retention_limit = var. redis_snapshot_retention_limit
24
+ tags = merge (map (" Name" , format (" tf-elasticache-%s-%s" , var. name , lookup (data. aws_vpc . vpc . tags , " Name" , " " ))), var. tags )
25
25
}
26
26
27
27
resource "aws_elasticache_parameter_group" "redis_parameter_group" {
28
- name = " ${ replace (format (" %.255s" , lower (replace (" tf-redis-${ var . name } -${ var . env } -${ data . aws_vpc . vpc . tags [" Name" ]} -${ random_id . salt . hex } " , " _" , " -" ))), " /\\ s/" , " -" )} "
28
+ name = replace (format (" %.255s" , lower (replace (" tf-redis-${ var . name } -${ var . env } -${ data . aws_vpc . vpc . tags [" Name" ]} -${ random_id . salt . hex } " , " _" , " -" ))), " /\\ s/" , " -" )
29
29
30
30
description = " Terraform-managed ElastiCache parameter group for ${ var . name } -${ var . env } -${ data . aws_vpc . vpc . tags [" Name" ]} "
31
31
32
32
# Strip the patch version from redis_version var
33
- family = " redis${ replace (var. redis_version , " /\\ .[\\ d]+$/" , " " )} "
33
+ family = " redis${ replace (var. redis_version , " /\\ .[\\ d]+$/" , " " )} "
34
34
dynamic "parameter" {
35
35
for_each = var. redis_parameters
36
36
content {
37
- name = parameter. value . name
37
+ name = parameter. value . name
38
38
value = parameter. value . value
39
39
}
40
40
}
@@ -45,6 +45,6 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" {
45
45
}
46
46
47
47
resource "aws_elasticache_subnet_group" "redis_subnet_group" {
48
- name = " ${ replace (format (" %.255s" , lower (replace (" tf-redis-${ var . name } -${ var . env } -${ data . aws_vpc . vpc . tags [" Name" ]} " , " _" , " -" ))), " /\\ s/" , " -" )} "
49
- subnet_ids = " ${ var . subnets } "
48
+ name = replace (format (" %.255s" , lower (replace (" tf-redis-${ var . name } -${ var . env } -${ data . aws_vpc . vpc . tags [" Name" ]} " , " _" , " -" ))), " /\\ s/" , " -" )
49
+ subnet_ids = var. subnets
50
50
}
0 commit comments