@@ -73,6 +73,7 @@ data "aws_iam_policy_document" "default" {
73
73
}
74
74
75
75
locals {
76
+ enabled = module. this . enabled
76
77
skip_index_re = var. skip_index_re == null ? " ^\\ .kibana*" : var. skip_index_re
77
78
}
78
79
@@ -105,7 +106,7 @@ locals {
105
106
# Resources
106
107
# --------------------------------------------------------------
107
108
resource "aws_lambda_function" "default" {
108
- count = var . enabled ? 1 : 0
109
+ count = local . enabled ? 1 : 0
109
110
filename = module. artifact . file
110
111
function_name = local. function_name
111
112
description = local. function_name
@@ -134,15 +135,15 @@ resource "aws_lambda_function" "default" {
134
135
}
135
136
136
137
resource "aws_security_group" "default" {
137
- count = var . enabled ? 1 : 0
138
+ count = local . enabled ? 1 : 0
138
139
name = local. function_name
139
140
description = local. function_name
140
141
vpc_id = var. vpc_id
141
142
tags = module. label . tags
142
143
}
143
144
144
145
resource "aws_security_group_rule" "udp_dns_egress_from_lambda" {
145
- count = var . enabled ? 1 : 0
146
+ count = local . enabled ? 1 : 0
146
147
description = " Allow outbound UDP traffic from Lambda Elasticsearch cleanup to DNS"
147
148
type = " egress"
148
149
from_port = 53
@@ -153,7 +154,7 @@ resource "aws_security_group_rule" "udp_dns_egress_from_lambda" {
153
154
}
154
155
155
156
resource "aws_security_group_rule" "tcp_dns_egress_from_lambda" {
156
- count = var . enabled ? 1 : 0
157
+ count = local . enabled ? 1 : 0
157
158
description = " Allow outbound TCP traffic from Lambda Elasticsearch cleanup to DNS"
158
159
type = " egress"
159
160
from_port = 53
@@ -164,7 +165,7 @@ resource "aws_security_group_rule" "tcp_dns_egress_from_lambda" {
164
165
}
165
166
166
167
resource "aws_security_group_rule" "egress_from_lambda_to_es_cluster" {
167
- count = var . enabled ? 1 : 0
168
+ count = local . enabled ? 1 : 0
168
169
description = " Allow outbound traffic from Lambda Elasticsearch cleanup SG to Elasticsearch SG"
169
170
type = " egress"
170
171
from_port = 443
@@ -175,7 +176,7 @@ resource "aws_security_group_rule" "egress_from_lambda_to_es_cluster" {
175
176
}
176
177
177
178
resource "aws_security_group_rule" "ingress_to_es_cluster_from_lambda" {
178
- count = var . enabled ? 1 : 0
179
+ count = local . enabled ? 1 : 0
179
180
description = " Allow inbound traffic to Elasticsearch domain from Lambda Elasticsearch cleanup SG"
180
181
type = " ingress"
181
182
from_port = 443
@@ -186,34 +187,34 @@ resource "aws_security_group_rule" "ingress_to_es_cluster_from_lambda" {
186
187
}
187
188
188
189
resource "aws_iam_role" "default" {
189
- count = var . enabled ? 1 : 0
190
+ count = local . enabled ? 1 : 0
190
191
name = local. function_name
191
192
assume_role_policy = data. aws_iam_policy_document . assume_role . json
192
193
tags = module. label . tags
193
194
}
194
195
195
196
resource "aws_iam_role_policy" "default" {
196
- count = var . enabled ? 1 : 0
197
+ count = local . enabled ? 1 : 0
197
198
name = local. function_name
198
199
role = join (" " , aws_iam_role. default . * . name )
199
200
policy = data. aws_iam_policy_document . default . json
200
201
}
201
202
202
203
resource "aws_iam_role_policy_attachment" "default" {
203
- count = var . enabled ? 1 : 0
204
+ count = local . enabled ? 1 : 0
204
205
role = join (" " , aws_iam_role. default . * . name )
205
206
policy_arn = " arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
206
207
}
207
208
208
209
resource "aws_cloudwatch_event_rule" "default" {
209
- count = var . enabled ? 1 : 0
210
+ count = local . enabled ? 1 : 0
210
211
name = local. function_name
211
212
description = local. function_name
212
213
schedule_expression = var. schedule
213
214
}
214
215
215
216
resource "aws_lambda_permission" "default" {
216
- count = var . enabled ? 1 : 0
217
+ count = local . enabled ? 1 : 0
217
218
statement_id = " AllowExecutionFromCloudWatch"
218
219
action = " lambda:InvokeFunction"
219
220
function_name = join (" " , aws_lambda_function. default . * . arn )
@@ -222,7 +223,7 @@ resource "aws_lambda_permission" "default" {
222
223
}
223
224
224
225
resource "aws_cloudwatch_event_target" "default" {
225
- count = var . enabled ? 1 : 0
226
+ count = local . enabled ? 1 : 0
226
227
target_id = local. function_name
227
228
rule = join (" " , aws_cloudwatch_event_rule. default . * . name )
228
229
arn = join (" " , aws_lambda_function. default . * . arn )
0 commit comments