generated from clowdhaus/terraform-aws-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.tf
132 lines (100 loc) · 4.54 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
locals {
create_acl_name = coalesce(var.acl_name, var.name)
acl_name = var.create && var.create_acl ? aws_memorydb_acl.this[0].id : var.acl_name
create_parameter_group_name = coalesce(var.parameter_group_name, var.name)
parameter_group_name = var.create && var.create_parameter_group ? aws_memorydb_parameter_group.this[0].id : var.parameter_group_name
create_subnet_group_name = coalesce(var.subnet_group_name, var.name)
subnet_group_name = var.create && var.create_subnet_group ? aws_memorydb_subnet_group.this[0].id : var.subnet_group_name
}
################################################################################
# Cluster
################################################################################
resource "aws_memorydb_cluster" "this" {
count = var.create ? 1 : 0
name = var.use_name_prefix ? null : var.name
name_prefix = var.use_name_prefix ? "${var.name}-" : null
description = var.description
engine = var.engine
engine_version = var.engine_version
auto_minor_version_upgrade = var.auto_minor_version_upgrade
port = var.port
node_type = var.node_type
num_shards = var.num_shards
num_replicas_per_shard = var.num_replicas_per_shard
parameter_group_name = local.parameter_group_name
data_tiering = var.data_tiering
acl_name = local.acl_name
kms_key_arn = var.kms_key_arn
tls_enabled = var.tls_enabled
security_group_ids = var.security_group_ids
subnet_group_name = local.subnet_group_name
maintenance_window = var.maintenance_window
sns_topic_arn = var.sns_topic_arn
snapshot_name = var.snapshot_name
snapshot_arns = var.snapshot_arns
snapshot_retention_limit = var.snapshot_retention_limit
snapshot_window = var.snapshot_window
final_snapshot_name = var.final_snapshot_name
tags = var.tags
}
################################################################################
# User(s)
################################################################################
resource "aws_memorydb_user" "this" {
for_each = { for k, v in var.users : k => v if var.create && var.create_users }
user_name = each.value.user_name
access_string = each.value.access_string
authentication_mode {
type = try(each.value.type, "password")
passwords = try(each.value.passwords, null)
}
tags = merge(var.tags, lookup(each.value, "tags", {}))
}
################################################################################
# ACL
################################################################################
resource "aws_memorydb_acl" "this" {
count = var.create && var.create_acl ? 1 : 0
name = var.acl_use_name_prefix ? null : local.create_acl_name
name_prefix = var.acl_use_name_prefix ? "${local.create_acl_name}-" : null
user_names = distinct(concat([for u in aws_memorydb_user.this : u.id], var.acl_user_names))
lifecycle {
create_before_destroy = true
}
tags = merge(var.tags, var.acl_tags)
}
################################################################################
# Parameter Group
################################################################################
resource "aws_memorydb_parameter_group" "this" {
count = var.create && var.create_parameter_group ? 1 : 0
name = var.parameter_group_use_name_prefix ? null : local.create_parameter_group_name
name_prefix = var.parameter_group_use_name_prefix ? "${local.create_parameter_group_name}-" : null
description = var.parameter_group_description
family = var.parameter_group_family
dynamic "parameter" {
for_each = var.parameter_group_parameters
content {
name = parameter.value.name
value = parameter.value.value
}
}
lifecycle {
create_before_destroy = true
}
tags = merge(var.tags, var.parameter_group_tags)
}
################################################################################
# Subnet Group
################################################################################
resource "aws_memorydb_subnet_group" "this" {
count = var.create && var.create_subnet_group ? 1 : 0
name = var.subnet_group_use_name_prefix ? null : local.create_subnet_group_name
name_prefix = var.subnet_group_use_name_prefix ? "${local.create_subnet_group_name}-" : null
description = var.subnet_group_description
subnet_ids = var.subnet_ids
lifecycle {
create_before_destroy = true
}
tags = merge(var.tags, var.subnet_group_tags)
}