-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathiam.tf
47 lines (41 loc) · 1.08 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
resource "aws_iam_role" "cluster" {
name_prefix = "${var.name}"
description = "Kubernetes cluster master and worker nodes"
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_instance_profile" "cluster" {
name_prefix = "${var.name}"
role = "${aws_iam_role.cluster.name}"
}
data "template_file" "role_policy" {
template = "${file("${path.module}/policies/iam.json")}"
vars {
s3_arn = "${aws_s3_bucket.cluster.arn}"
}
}
resource "aws_iam_role_policy" "main" {
name = "${var.name}-main"
role = "${aws_iam_role.cluster.id}"
policy = "${data.template_file.role_policy.rendered}"
}
resource "aws_iam_role_policy" "additional" {
count = "${var.additional_iam_policy == "" ? 0 : 1}"
name = "${var.name}-additional"
role = "${aws_iam_role.cluster.id}"
policy = "${var.additional_iam_policy}"
}