-
Notifications
You must be signed in to change notification settings - Fork 5
/
loader.tf
88 lines (79 loc) · 2.13 KB
/
loader.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
resource "aws_lambda_function" "loader" {
s3_bucket = local.lambda_buckets[var.aws_region]
s3_key = "LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.8.3.zip"
function_name = "controlshift-redshift-loader"
role = aws_iam_role.loader_lambda_role.arn
handler = "index.handler"
runtime = "nodejs16.x"
timeout = 900
vpc_config {
subnet_ids = var.lambda_loader_subnet_ids
security_group_ids = var.lambda_loader_security_group_ids
}
environment {
variables = {
"DEBUG" = "true"
"CONTROLSHIFT_AWS_REGION" = var.controlshift_aws_region
}
}
}
resource "aws_lambda_event_source_mapping" "process_task" {
event_source_arn = aws_sqs_queue.receiver_queue.arn
function_name = aws_lambda_function.loader.arn
batch_size = 1
depends_on = [aws_iam_role_policy.lambda_loads_tables]
}
resource "aws_sns_topic" "success_sns_topic" {
depends_on = [aws_lambda_function.loader]
name = var.success_topic_name
policy = data.aws_iam_policy_document.success_sns_notification_policy.json
}
data "aws_iam_policy_document" "success_sns_notification_policy" {
statement {
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"SNS:Publish",
]
resources = [
"arn:aws:sns:*:*:${var.success_topic_name}"
]
condition {
test = "ArnLike"
variable = "aws:SourceArn"
values = [
aws_lambda_function.loader.arn,
]
}
}
}
resource "aws_sns_topic" "failure_sns_topic" {
depends_on = [aws_lambda_function.loader]
name = var.failure_topic_name
policy = data.aws_iam_policy_document.failure_sns_notification_policy.json
}
data "aws_iam_policy_document" "failure_sns_notification_policy" {
statement {
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"SNS:Publish",
]
resources = [
"arn:aws:sns:*:*:${var.failure_topic_name}"
]
condition {
test = "ArnLike"
variable = "aws:SourceArn"
values = [
aws_lambda_function.loader.arn,
]
}
}
}