forked from DNXLabs/terraform-aws-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot.tf
52 lines (42 loc) · 1.39 KB
/
chatbot.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
# Note that the same configuration name cannot appear more than once, even in different slack
# workspaces.
resource "aws_cloudformation_stack" "tf_chatbot" {
for_each = var.enabled ? local.slack_targets : {}
name = "terraform-chatbot-${each.key}"
parameters = {
ConfigurationNameParam = each.key
IamRoleArnArnParam = aws_iam_role.chatbot.*.arn[0]
SnsTopicArnsParam = join(",", flatten([var.alarm_sns_topic_arns]))
SlackChannelIdParam = each.value.channel
SlackWorkspaceIdParam = each.value.workspace
LoggingLevelParam = var.logging_level
}
template_body = file("${path.module}/cf-chatbot.yml")
}
#--------------
resource "aws_iam_role" "chatbot" {
count = var.enabled ? 1 : 0
name = "${var.org_name}-${var.workspace_name}-chatbot-role"
assume_role_policy = data.aws_iam_policy_document.assume_role_chatbot.*.json[0]
tags = var.tags
}
#--------------
resource "aws_iam_role_policy_attachment" "chatbot_policy" {
count = var.enabled ? 1 : 0
role = aws_iam_role.chatbot.*.name[0]
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
data "aws_iam_policy_document" "assume_role_chatbot" {
count = var.enabled ? 1 : 0
statement {
principals {
type = "Service"
identifiers = [
"chatbot.amazonaws.com"
]
}
actions = [
"sts:AssumeRole",
]
}
}