9
9
namespace = join (" -" , [local . project_name , local . environment_name ])
10
10
11
11
tags = {
12
+ " Name" = join (" -" , [local . namespace , local . resource_name ])
13
+
12
14
" walrus.seal.io/project-id" = local.project_id
13
15
" walrus.seal.io/environment-id" = local.environment_id
14
16
" walrus.seal.io/resource-id" = local.resource_id
@@ -95,9 +97,10 @@ resource "random_string" "name_suffix" {
95
97
}
96
98
97
99
locals {
98
- name = join (" -" , [local . resource_name , random_string . name_suffix . result ])
99
- fullname = join (" -" , [local . namespace , local . name ])
100
- password = coalesce (var. password , random_password. password . result )
100
+ name = join (" -" , [local . resource_name , random_string . name_suffix . result ])
101
+ fullname = join (" -" , [local . namespace , local . name ])
102
+ description = " Created by Walrus catalog, and provisioned by Terraform."
103
+ password = coalesce (var. password , random_password. password . result )
101
104
102
105
replication_readonly_replicas = var. replication_readonly_replicas == 0 ? 1 : var. replication_readonly_replicas
103
106
}
@@ -117,59 +120,67 @@ locals {
117
120
# create security group.
118
121
119
122
resource "aws_security_group" "target" {
120
- name = local. fullname
121
- tags = local. tags
123
+ name = local. fullname
124
+ description = local. description
125
+ tags = local. tags
122
126
123
127
vpc_id = data. aws_vpc . selected . id
124
128
}
125
129
126
130
resource "aws_security_group_rule" "target" {
131
+ description = local. description
132
+
127
133
security_group_id = aws_security_group. target . id
128
134
129
135
type = " ingress"
130
136
protocol = " tcp"
131
137
cidr_blocks = [data . aws_vpc . selected . cidr_block ]
132
138
from_port = 6379
133
139
to_port = 6379
134
- description = " Access Redis from VPC"
135
140
}
136
141
137
142
resource "aws_elasticache_subnet_group" "target" {
138
143
name = local. fullname
139
- description = " Elasticache subnet group for ${ local . fullname } "
140
- subnet_ids = data. aws_subnets . selected . ids
144
+ description = local. description
141
145
tags = local. tags
146
+
147
+ subnet_ids = data. aws_subnets . selected . ids
148
+ }
149
+
150
+ locals {
151
+ parameters = merge (
152
+ {
153
+ " cluster-enabled" = " no"
154
+ },
155
+ {
156
+ for c in (var. engine_parameters != null ? var. engine_parameters : []) : c . name => c . value
157
+ if try (c. value != " " , false )
158
+ }
159
+ )
142
160
}
143
161
144
162
resource "aws_elasticache_parameter_group" "target" {
145
163
name = local. fullname
146
- description = " Elasticache parameter group for ${ local . fullname } "
147
- family = local. version_family_mapping [local . version ]
164
+ description = local. description
165
+ tags = local. tags
166
+
167
+ family = local. version_family_mapping [local . version ]
148
168
149
169
dynamic "parameter" {
150
- for_each = concat ([
151
- { name = " cluster-enabled" , value = " no" }
152
- ], var. engine_parameters == null ? [] : var. engine_parameters )
170
+ for_each = local. parameters
153
171
content {
154
- name = parameter. value . name
155
- value = tostring (parameter. value . value )
172
+ name = parameter. key
173
+ value = tostring (parameter. value )
156
174
}
157
175
}
158
-
159
- tags = local. tags
160
-
161
- # Ignore changes to the description since it will try to recreate the resource
162
- lifecycle {
163
- ignore_changes = [
164
- description ,
165
- ]
166
- }
167
176
}
168
177
169
178
resource "aws_elasticache_replication_group" "default" {
170
- replication_group_id = local. fullname
171
- description = " Elasticache replication group for ${ local . fullname } "
172
- tags = local. tags
179
+ description = local. description
180
+ tags = local. tags
181
+
182
+ replication_group_id = local. fullname
183
+
173
184
multi_az_enabled = local. architecture == " replication"
174
185
automatic_failover_enabled = local. architecture == " replication"
175
186
subnet_group_name = aws_elasticache_subnet_group. target . name
@@ -195,10 +206,9 @@ resource "aws_elasticache_replication_group" "default" {
195
206
resource "aws_service_discovery_service" "primary" {
196
207
count = var. infrastructure . domain_suffix != null ? 1 : 0
197
208
198
- name = format (" %s.%s" , (local. architecture == " replication" ? join (" -" , [
199
- local . name , " primary"
200
- ]) : local. name ), local. namespace )
201
- force_destroy = true
209
+ name = format (" %s.%s" , (local. architecture == " replication" ? join (" -" , [local . name , " primary" ]) : local. name ), local. namespace )
210
+ description = local. description
211
+ tags = local. tags
202
212
203
213
dns_config {
204
214
namespace_id = data. aws_service_discovery_dns_namespace . selected [0 ]. id
@@ -208,6 +218,8 @@ resource "aws_service_discovery_service" "primary" {
208
218
type = " CNAME"
209
219
}
210
220
}
221
+
222
+ force_destroy = true
211
223
}
212
224
213
225
resource "aws_service_discovery_instance" "primary" {
@@ -224,8 +236,9 @@ resource "aws_service_discovery_instance" "primary" {
224
236
resource "aws_service_discovery_service" "reader" {
225
237
count = var. infrastructure . domain_suffix != null && local. architecture == " replication" ? 1 : 0
226
238
227
- name = format (" %s.%s" , join (" -" , [local . name , " reader" ]), local. namespace )
228
- force_destroy = true
239
+ name = format (" %s.%s" , join (" -" , [local . name , " reader" ]), local. namespace )
240
+ description = local. description
241
+ tags = local. tags
229
242
230
243
dns_config {
231
244
namespace_id = data. aws_service_discovery_dns_namespace . selected [0 ]. id
@@ -235,6 +248,8 @@ resource "aws_service_discovery_service" "reader" {
235
248
type = " CNAME"
236
249
}
237
250
}
251
+
252
+ force_destroy = true
238
253
}
239
254
240
255
resource "aws_service_discovery_instance" "reader" {
0 commit comments