generated from nhs-england-tools/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
86 lines (72 loc) · 2.12 KB
/
iam.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
resource "aws_iam_role" "iam_for_lambda" {
name = "${var.prefix}-msteams-iam-for-lambda"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
tags = {
Name = "${var.prefix}-msteams-iam-for-lambda"
}
}
data "aws_iam_policy_document" "assume_role" {
statement {
sid = "LambdaAssumePolicy"
effect = "Allow"
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
data "aws_iam_policy_document" "function_logging_policy_document" {
statement {
sid = "AllowCloudWatchLogging"
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:GetLogEvents",
"logs:PutLogEvents"
]
resources = ["${aws_cloudwatch_log_group.function_log_group.arn}:*", ]
}
statement {
sid = "AllowXRayLogging"
effect = "Allow"
actions = ["xray:PutTraceSegments", "xray:PutTelemetryRecords"]
resources = ["*"]
}
}
resource "aws_iam_policy" "function_logging_policy" {
name = "${var.prefix}-msteams-function-logging-policy"
description = "A logging function document"
policy = data.aws_iam_policy_document.function_logging_policy_document.json
tags = {
Name = "${var.prefix}-msteams-function-logging-policy"
}
}
resource "aws_iam_role_policy_attachment" "function_ssm_policy_attachment" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = aws_iam_policy.function_logging_policy.arn
}
data "aws_iam_policy_document" "ssm_policy" {
statement {
actions = [
"ssm:getparameter",
"ssm:getparameters",
]
resources = [
local.ssm_budget_webhook_arn,
local.ssm_cloudwatch_webhook_arn
]
}
}
resource "aws_iam_policy" "ssm_policy" {
name = "${var.prefix}-msteams-ssm-policy"
description = "A ssm policy document"
policy = data.aws_iam_policy_document.ssm_policy.json
tags = {
Name = "${var.prefix}-msteams-ssm-policy"
}
}
resource "aws_iam_role_policy_attachment" "ssm_policy_attachment" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = aws_iam_policy.ssm_policy.arn
}