/
elasticache_cluster_node_detail.sp
567 lines (495 loc) · 14.3 KB
/
elasticache_cluster_node_detail.sp
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
dashboard "elasticache_cluster_node_detail" {
title = "AWS ElastiCache Cluster Node Detail"
documentation = file("./dashboards/elasticache/docs/elasticache_cluster_node_detail.md")
tags = merge(local.elasticache_common_tags, {
type = "Detail"
})
input "elasticache_cluster_node_arn" {
title = "Select a Node:"
query = query.elasticache_cluster_node_input
width = 4
}
container {
card {
query = query.elasticache_cluster_node_status
width = 2
args = [self.input.elasticache_cluster_node_arn.value]
}
card {
query = query.elasticache_cluster_node_node_type
width = 2
args = [self.input.elasticache_cluster_node_arn.value]
}
card {
query = query.elasticache_cluster_node_automatic_backup
width = 2
args = [self.input.elasticache_cluster_node_arn.value]
}
card {
query = query.elasticache_cluster_node_encryption_transit
width = 2
args = [self.input.elasticache_cluster_node_arn.value]
}
card {
query = query.elasticache_cluster_node_encryption_rest
width = 2
args = [self.input.elasticache_cluster_node_arn.value]
}
card {
query = query.elasticache_cluster_node_auth_token
width = 2
args = [self.input.elasticache_cluster_node_arn.value]
}
}
with "elasticache_node_groups_for_elasticache_cluster_node" {
query = query.elasticache_node_groups_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "elasticache_parameter_groups_for_elasticache_cluster_node" {
query = query.elasticache_parameter_groups_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "elasticache_clusters_for_elasticache_cluster_node" {
query = query.elasticache_clusters_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "elasticache_subnet_groups_for_elasticache_cluster_node" {
query = query.elasticache_subnet_groups_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "kms_keys_for_elasticache_cluster_node" {
query = query.kms_keys_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "sns_topics_for_elasticache_cluster_node" {
query = query.sns_topics_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "vpc_security_groups_for_elasticache_cluster_node" {
query = query.vpc_security_groups_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "vpc_subnets_for_elasticache_cluster_node" {
query = query.vpc_subnets_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
with "vpc_vpcs_for_elasticache_cluster_node" {
query = query.vpc_vpcs_for_elasticache_cluster_node
args = [self.input.elasticache_cluster_node_arn.value]
}
container {
graph {
title = "Relationships"
type = "graph"
direction = "TD"
node {
base = node.elasticache_cluster
args = {
elasticache_cluster_arns = with.elasticache_clusters_for_elasticache_cluster_node.rows[*].elasticache_cluster_arn
}
}
node {
base = node.elasticache_cluster_node
args = {
elasticache_cluster_node_arns = [self.input.elasticache_cluster_node_arn.value]
}
}
node {
base = node.elasticache_parameter_group
args = {
elsticache_parameter_group_arns = with.elasticache_parameter_groups_for_elasticache_cluster_node.rows[*].elasticache_parameter_group_arn
}
}
node {
base = node.elasticache_node_group
args = {
elasticache_node_group_ids = with.elasticache_node_groups_for_elasticache_cluster_node.rows[*].elasticache_node_group_id
}
}
node {
base = node.elasticache_subnet_group
args = {
elasticache_subnet_group_arns = with.elasticache_subnet_groups_for_elasticache_cluster_node.rows[*].elasticache_subnet_group_arn
}
}
node {
base = node.kms_key
args = {
kms_key_arns = with.kms_keys_for_elasticache_cluster_node.rows[*].kms_key_arn
}
}
node {
base = node.sns_topic
args = {
sns_topic_arns = with.sns_topics_for_elasticache_cluster_node.rows[*].sns_topic_arn
}
}
node {
base = node.vpc_security_group
args = {
vpc_security_group_ids = with.vpc_security_groups_for_elasticache_cluster_node.rows[*].vpc_security_group_id
}
}
node {
base = node.vpc_subnet
args = {
vpc_subnet_ids = with.vpc_subnets_for_elasticache_cluster_node.rows[*].vpc_subnet_id
}
}
node {
base = node.vpc_vpc
args = {
vpc_vpc_ids = with.vpc_vpcs_for_elasticache_cluster_node.rows[*].vpc_vpc_id
}
}
edge {
base = edge.elasticache_cluster_node_to_elasticache_parameter_group
args = {
elsticache_parameter_group_arns = with.elasticache_parameter_groups_for_elasticache_cluster_node.rows[*].elasticache_parameter_group_arn
}
}
edge {
base = edge.elasticache_cluster_node_to_kms_key
args = {
kms_key_arns = with.kms_keys_for_elasticache_cluster_node.rows[*].kms_key_arn
}
}
edge {
base = edge.elasticache_cluster_node_to_sns_topic
args = {
elasticache_cluster_node_arns = [self.input.elasticache_cluster_node_arn.value]
}
}
edge {
base = edge.elasticache_cluster_node_to_vpc_security_group
args = {
vpc_security_group_ids = with.vpc_security_groups_for_elasticache_cluster_node.rows[*].vpc_security_group_id
}
}
edge {
base = edge.elasticache_cluster_to_elasticache_node_group
args = {
elasticache_cluster_arns = with.elasticache_clusters_for_elasticache_cluster_node.rows[*].elasticache_cluster_arn
}
}
edge {
base = edge.elasticache_node_group_to_elasticache_cluster_node
args = {
elasticache_cluster_arns = with.elasticache_clusters_for_elasticache_cluster_node.rows[*].elasticache_cluster_arn
}
}
edge {
base = edge.elasticache_subnet_group_to_vpc_subnet
args = {
vpc_subnet_ids = with.vpc_subnets_for_elasticache_cluster_node.rows[*].vpc_subnet_id
}
}
edge {
base = edge.vpc_security_group_to_elasticache_subnet_group
args = {
elasticache_cluster_node_arns = [self.input.elasticache_cluster_node_arn.value]
}
}
edge {
base = edge.vpc_subnet_to_vpc_vpc
args = {
vpc_subnet_ids = with.vpc_subnets_for_elasticache_cluster_node.rows[*].vpc_subnet_id
}
}
}
}
container {
container {
width = 6
table {
title = "Overview"
type = "line"
width = 6
query = query.elasticache_cluster_node_overview
args = [self.input.elasticache_cluster_node_arn.value]
}
table {
title = "Tags"
width = 6
query = query.elasticache_cluster_node_tags
args = [self.input.elasticache_cluster_node_arn.value]
}
}
container {
width = 6
table {
title = "Notification Configuration"
query = query.elasticache_cluster_node_notification_configuration
args = [self.input.elasticache_cluster_node_arn.value]
}
}
}
}
# Input queries
query "elasticache_cluster_node_input" {
sql = <<-EOQ
select
title as label,
arn as value,
json_build_object(
'account_id', account_id,
'region', region
) as tags
from
aws_elasticache_cluster
order by
title;
EOQ
}
# With queries
query "elasticache_parameter_groups_for_elasticache_cluster_node" {
sql = <<-EOQ
select
g.arn as elasticache_parameter_group_arn
from
aws_elasticache_cluster as c,
aws_elasticache_parameter_group as g
where
c.cache_parameter_group ->> 'CacheParameterGroupName' = g.cache_parameter_group_name
and c.region = g.region
and c.account_id = g.account_id
and c.arn = $1;
EOQ
}
query "elasticache_clusters_for_elasticache_cluster_node" {
sql = <<-EOQ
select
g.arn as elasticache_cluster_arn
from
aws_elasticache_cluster as c,
aws_elasticache_replication_group as g
where
c.replication_group_id = g.replication_group_id
and c.arn = $1;
EOQ
}
query "elasticache_node_groups_for_elasticache_cluster_node" {
sql = <<-EOQ
select
rg.title || '-' || (ng ->> 'NodeGroupId') as elasticache_node_group_id
from
aws_elasticache_cluster as c,
aws_elasticache_replication_group rg,
jsonb_array_elements(node_groups) ng,
jsonb_array_elements(ng -> 'NodeGroupMembers') ngm
where
c.cache_cluster_id = ngm ->> 'CacheClusterId'
and c.arn = $1;
EOQ
}
query "elasticache_subnet_groups_for_elasticache_cluster_node" {
sql = <<-EOQ
select
g.arn as elasticache_subnet_group_arn
from
aws_elasticache_cluster as c,
aws_elasticache_subnet_group as g
where
g.cache_subnet_group_name = c.cache_subnet_group_name
and g.region = c.region
and c.arn = $1;
EOQ
}
query "kms_keys_for_elasticache_cluster_node" {
sql = <<-EOQ
select
kms_key_id as kms_key_arn
from
aws_elasticache_cluster as c,
aws_elasticache_replication_group as g
where
c.arn = $1
and c.replication_group_id = g.replication_group_id
and kms_key_id is not null;
EOQ
}
query "sns_topics_for_elasticache_cluster_node" {
sql = <<-EOQ
select
notification_configuration ->> 'TopicArn' as sns_topic_arn
from
aws_elasticache_cluster
where
arn = $1
and notification_configuration ->> 'TopicArn' is not null;
EOQ
}
query "vpc_security_groups_for_elasticache_cluster_node" {
sql = <<-EOQ
select
group_id as vpc_security_group_id
from
aws_vpc_security_group
where
group_id in
(
select
sg ->> 'SecurityGroupId'
from
aws_elasticache_cluster,
jsonb_array_elements(security_groups) as sg
where
arn = $1
);
EOQ
}
query "vpc_subnets_for_elasticache_cluster_node" {
sql = <<-EOQ
select
subnet ->> 'SubnetIdentifier' as vpc_subnet_id
from
aws_elasticache_cluster as c,
aws_elasticache_subnet_group as g,
jsonb_array_elements(subnets) as subnet
where
g.cache_subnet_group_name = c.cache_subnet_group_name
and g.region = c.region
and c.arn = $1
EOQ
}
query "vpc_vpcs_for_elasticache_cluster_node" {
sql = <<-EOQ
select
vpc_id as vpc_vpc_id
from
aws_vpc
where
vpc_id in
(
select
vpc_id
from
aws_elasticache_cluster as c,
aws_elasticache_subnet_group as g
where
g.cache_subnet_group_name = c.cache_subnet_group_name
and g.region = c.region
and c.arn = $1
);
EOQ
}
# Card queries
query "elasticache_cluster_node_status" {
sql = <<-EOQ
select
'Status' as label,
initcap(cache_cluster_status) as value
from
aws_elasticache_cluster
where
arn = $1;
EOQ
}
query "elasticache_cluster_node_node_type" {
sql = <<-EOQ
select
'Node Type' as label,
cache_node_type as value
from
aws_elasticache_cluster
where
arn = $1;
EOQ
}
query "elasticache_cluster_node_automatic_backup" {
sql = <<-EOQ
select
'Automatic Backup' as label,
case when snapshot_retention_limit is null then 'Disabled' else 'Enabled' end as value,
case when snapshot_retention_limit is null then 'alert' else 'ok' end as type
from
aws_elasticache_cluster
where
arn = $1;
EOQ
}
query "elasticache_cluster_node_encryption_transit" {
sql = <<-EOQ
select
'Encryption in Transit' as label,
case when transit_encryption_enabled then 'Enabled' else 'Disabled' end as value,
case when transit_encryption_enabled then 'ok' else 'alert' end as type
from
aws_elasticache_cluster
where
arn = $1;
EOQ
}
query "elasticache_cluster_node_encryption_rest" {
sql = <<-EOQ
select
'Encryption at Rest' as label,
case when at_rest_encryption_enabled then 'Enabled' else 'Disabled' end as value,
case when at_rest_encryption_enabled then 'ok' else 'alert' end as type
from
aws_elasticache_cluster
where
arn = $1;
EOQ
}
query "elasticache_cluster_node_auth_token" {
sql = <<-EOQ
select
'Auth Token' as label,
case when auth_token_enabled then 'Enabled' else 'Disabled' end as value,
case when auth_token_enabled then 'ok' else 'alert' end as type
from
aws_elasticache_cluster
where
arn = $1;
EOQ
}
# Other detail page queries
query "elasticache_cluster_node_overview" {
sql = <<-EOQ
select
title as "Title",
auth_token_enabled as "Auth Token Enabled",
auto_minor_version_upgrade as "Auto Minor Version Upgrade",
cache_cluster_create_time as "Create Time",
cache_subnet_group_name as "Subnet Group Name",
engine as "Engine",
engine_version as "Engine Version",
preferred_availability_zone as "Preferred Availability Zone",
region as "Region",
account_id as "Account ID",
arn as "ARN"
from
aws_elasticache_cluster
where
arn = $1;
EOQ
}
query "elasticache_cluster_node_tags" {
sql = <<-EOQ
select
tag ->> 'Key' as "Key",
tag ->> 'Value' as "Value"
from
aws_elasticache_cluster,
jsonb_array_elements(tags_src) as tag
where
arn = $1
order by
tag ->> 'Key';
EOQ
}
query "elasticache_cluster_node_notification_configuration" {
sql = <<-EOQ
select
t.title as "Topic Title",
notification_configuration ->> 'TopicStatus' as "Topic Status"
from
aws_elasticache_cluster as c
left join
aws_sns_topic as t
on notification_configuration ->> 'TopicArn' = topic_arn
where
c.arn = $1;
EOQ
}