forked from aliaskov/aws-costs-to-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam_roles.tf
71 lines (63 loc) · 1.86 KB
/
iam_roles.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
# IAM roles to allow Lambda functions to access different AWS resources.
# Fetch our own account id and region. Used in our IAM policy templates.
data "aws_caller_identity" "current" {}
# Role for our 'get_aws_costs' lambda to assume.
# This is used by lambdas that manage instance lifecycles.
resource "aws_iam_role" "lambda_get_aws_costs" {
name = "lambda_get_aws_costs"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
}
EOF
}
# Here we ingest the template and create the role policies
# Template for our 'stop_and_terminate_instances' lambda IAM policy
data "template_file" "iam_lambda_get_aws_costs_policy" {
template = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"budgets:ViewBudget",
"aws-portal:*Usage",
"organizations:DescribeOrganization",
"aws-portal:*PaymentMethods",
"aws-portal:*",
"cur:*",
"aws-portal:*Billing",
"ce:*",
"logs:CreateLogGroup",
"logs:PutLogEvents",
"budgets:ModifyBudget"
],
"Resource": "*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "organizations:DescribeAccount",
"Resource": "arn:aws:organizations::*:account/o-*/*"
}
]
}
EOF
}
resource "aws_iam_role_policy" "lambda_get_aws_costs" {
name = "lambda_get_aws_costs"
policy = "${data.template_file.iam_lambda_get_aws_costs_policy.rendered}"
role = "${aws_iam_role.lambda_get_aws_costs.id}"
}