-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.tf
85 lines (78 loc) · 3.36 KB
/
redis.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Resources for Gitlab Redis setup */
locals {
gitlab_redis_sg_name = "${local.environment_prefix}-gitlab-redis"
gitlab_redis_subnet_group_name = "${local.environment_prefix}-gitlab-redis"
gitlab_redis_cluster_id = "${local.environment_prefix}-gitlab-redis"
}
resource "aws_security_group" "gitlab_redis" {
name = local.gitlab_redis_sg_name
vpc_id = data.aws_vpc.vpc.id
description = "Security group for Gitlab Redis"
ingress = [
{
from_port = var.gitlab_redis_port
protocol = "tcp"
to_port = var.gitlab_redis_port
cidr_blocks = []
ipv6_cidr_blocks = []
prefix_list_ids = []
security_groups = [aws_security_group.gitlab.id]
self = false
description = "allow TCP access from Gitlab instance"
}
]
tags = merge({
Name = local.gitlab_redis_sg_name
}, local.default_tags, var.additional_tags)
}
resource "aws_elasticache_parameter_group" "gitlab_redis" {
count = var.gitlab_redis_create_parameter_group == true ? 1 : 0
family = var.gitlab_redis_parameter_group.family
name = var.gitlab_redis_parameter_group.name
tags = merge({
Name = "${local.environment_prefix}-${var.gitlab_redis_parameter_group.name}"
}, local.default_tags, var.additional_tags)
lifecycle {
precondition {
condition = var.gitlab_redis_parameter_group.name != null && var.gitlab_redis_parameter_group.family != null
error_message = "Provide name and family in gitlab_redis_parameter_group for Parameter Group creation"
}
}
}
resource "aws_elasticache_subnet_group" "gitlab_redis" {
count = var.gitlab_redis_create_subnet_group == true ? 1 : 0
name = local.gitlab_redis_subnet_group_name
subnet_ids = var.gitlab_redis_subnet_ids
tags = merge({
Name = local.gitlab_redis_subnet_group_name
}, local.default_tags, var.additional_tags)
lifecycle {
precondition {
condition = var.gitlab_redis_create_subnet_group && length(var.gitlab_redis_subnet_ids) != 0
error_message = "Subnet Group creation needs subnet-ids. Add subnet-ids to gitlab_redis_subnet_ids"
}
}
}
resource "aws_elasticache_cluster" "gitlab_redis" {
cluster_id = local.gitlab_redis_cluster_id
engine = "redis"
node_type = var.gitlab_redis_node_type
num_cache_nodes = var.gitlab_redis_num_cache_nodes
parameter_group_name = var.gitlab_redis_create_parameter_group == true ? aws_elasticache_parameter_group.gitlab_redis[0].name : var.gitlab_redis_parameter_group_name
engine_version = var.gitlab_redis_engine_version
port = var.gitlab_redis_port
security_group_ids = [aws_security_group.gitlab_redis.id]
subnet_group_name = var.gitlab_redis_create_subnet_group == true ? aws_elasticache_subnet_group.gitlab_redis[0].name : var.gitlab_redis_subnet_group_name
tags = merge({
Name = local.gitlab_redis_cluster_id
}, local.default_tags, var.additional_tags)
lifecycle {
precondition {
condition = anytrue([
(var.gitlab_redis_create_parameter_group == false && var.gitlab_redis_parameter_group_name != null),
(var.gitlab_redis_create_parameter_group)
])
error_message = "Parameter Group creation for Gitlab Redis is set to ${var.gitlab_redis_create_parameter_group}. Provide a pre-existing Parameter Group name."
}
}
}