generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
124 lines (100 loc) · 3.97 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
/* # SNS
*
* A wrapper on the SNS module that enfores a customer managed KMS key. You can either supply
* your own KMS ARN as `kms_master_key_id` or let the module create their own key. If you choose
* to let the module create a KMS key it will also include an IAM policy that allows access from the
* root user of the account. You can also supply service like `s3.amazonaws.com` or `sns.amazonaws.com`
* in the `kms_event_sources` list, as well as IAM roles in the `kms_iam_sources` list who will then have
* `kms:Decrypt*` and `kms:GenerateDataKey*` permissions on the key.
*/
data "aws_caller_identity" "current" {}
resource "aws_sns_topic" "this" {
name = var.name
name_prefix = var.name_prefix
display_name = var.display_name
policy = var.policy
delivery_policy = var.delivery_policy
application_success_feedback_role_arn = var.application_success_feedback_role_arn
application_success_feedback_sample_rate = var.application_success_feedback_sample_rate
application_failure_feedback_role_arn = var.application_failure_feedback_role_arn
http_success_feedback_role_arn = var.http_success_feedback_role_arn
http_success_feedback_sample_rate = var.http_success_feedback_sample_rate
http_failure_feedback_role_arn = var.http_failure_feedback_role_arn
kms_master_key_id = var.kms_master_key_id == null ? aws_kms_key.sns_key[0].arn : var.kms_master_key_id
fifo_topic = var.fifo_topic
content_based_deduplication = var.content_based_deduplication
lambda_success_feedback_role_arn = var.lambda_success_feedback_role_arn
lambda_success_feedback_sample_rate = var.lambda_success_feedback_sample_rate
lambda_failure_feedback_role_arn = var.lambda_failure_feedback_role_arn
sqs_success_feedback_role_arn = var.sqs_success_feedback_role_arn
sqs_success_feedback_sample_rate = var.sqs_success_feedback_sample_rate
sqs_failure_feedback_role_arn = var.sqs_failure_feedback_role_arn
firehose_success_feedback_role_arn = var.firehose_success_feedback_role_arn
firehose_success_feedback_sample_rate = var.firehose_success_feedback_sample_rate
firehose_failure_feedback_role_arn = var.firehose_failure_feedback_role_arn
tags = merge(local.common_tags, var.tags)
}
data "aws_iam_policy_document" "kms_policies" {
statement {
effect = "Allow"
actions = [
"kms:*"
]
resources = [
"*"
]
principals {
type = "AWS"
identifiers = [data.aws_caller_identity.current.account_id]
}
}
dynamic "statement" {
for_each = length(var.kms_event_sources) > 0 ? [true] : []
content {
effect = "Allow"
principals {
type = "Service"
identifiers = var.kms_event_sources
}
actions = [
"kms:Decrypt*",
"kms:GenerateDataKey*",
]
resources = [
"*"
]
condition {
test = "StringLike"
variable = "AWS:SourceArn"
values = [data.aws_caller_identity.current.account_id]
}
}
}
dynamic "statement" {
for_each = length(var.kms_iam_sources) > 0 ? [true] : []
content {
effect = "Allow"
principals {
type = "AWS"
identifiers = var.kms_iam_sources
}
actions = [
"kms:Decrypt*",
"kms:GenerateDataKey*",
]
resources = [
"*"
]
condition {
test = "StringLike"
variable = "AWS:SourceArn"
values = [data.aws_caller_identity.current.account_id]
}
}
}
}
resource "aws_kms_key" "sns_key" {
count = var.kms_master_key_id == null ? 1 : 0
description = "SNS Key for ${var.name}"
policy = data.aws_iam_policy_document.kms_policies.json
}