forked from monzo/etcd3-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
44 lines (39 loc) · 1.16 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
resource "aws_key_pair" "default" {
count = var.key_pair_public_key == "" ? 0 : 1
key_name = var.role
public_key = var.key_pair_public_key
}
resource "aws_iam_policy" "default" {
name = "${var.role}.${data.aws_region.current.name}.i.${var.environment}.${var.dns}"
path = "/"
description = "Allow data volume management for instances"
policy = module.attached-ebs.iam_role_policy_document
}
resource "aws_iam_role" "default" {
name = "${count.index}.${var.role}.${data.aws_region.current.name}.i.${var.environment}.${var.dns}"
count = var.cluster_size
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_instance_profile" "default" {
count = var.cluster_size
name = aws_iam_role.default[count.index].name
role = aws_iam_role.default[count.index].name
}
resource "aws_iam_role_policy_attachment" "default" {
count = var.cluster_size
role = aws_iam_role.default[count.index].name
policy_arn = aws_iam_policy.default.arn
}