generated from rhythmictech/terraform-terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
iam.tf
62 lines (51 loc) · 1.37 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
data "aws_iam_policy_document" "assume" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "this" {
statement {
actions = ["ec2:AttachVolume"]
sid = "AllowEBSAttach"
resources = [
"arn:aws:ec2:*:*:instance/*",
"arn:aws:ec2:*:*:volume/*"
]
condition {
test = "StringLike"
values = [var.volume_key]
variable = "ec2:ResourceTag/VolumeKey"
}
}
}
resource "aws_iam_policy" "this" {
name_prefix = var.name
description = "IAM policy for bitbucket servers"
path = "/"
policy = data.aws_iam_policy_document.this.json
}
resource "aws_iam_role" "this" {
name_prefix = var.name
assume_role_policy = data.aws_iam_policy_document.assume.json
tags = var.tags
lifecycle {
create_before_destroy = true
}
}
resource "aws_iam_role_policy_attachment" "this" {
role = aws_iam_role.this.name
policy_arn = aws_iam_policy.this.arn
}
resource "aws_iam_role_policy_attachment" "additional" {
count = length(var.asg_additional_iam_policies)
role = aws_iam_role.this.name
policy_arn = var.asg_additional_iam_policies[count.index]
}
resource "aws_iam_instance_profile" "this" {
name_prefix = var.name
role = aws_iam_role.this.name
}