forked from ulamlabs/terraform-aws-rabbitmq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iam.tf
103 lines (92 loc) · 2.43 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
data "aws_iam_policy_document" "policy_doc" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "policy_permissions_doc" {
statement {
effect = "Allow"
actions = [
"autoscaling:DescribeAutoScalingInstances",
"ec2:DescribeInstances"
]
resources = [
"*"
]
}
statement {
effect = "Allow"
actions = [
"ecr:GetAuthorizationToken",
"ecr:ListImages",
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:DescribeImages",
"ecr:DescribeRepositories",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy"
]
resources = [
"*"
]
}
statement {
effect = "Allow"
actions = [
"ssm:GetParameter"
]
resources = [
aws_ssm_parameter.datadog_api_key.arn,
aws_ssm_parameter.datadog_user_password.arn,
aws_ssm_parameter.rabbit_admin_password.arn,
aws_ssm_parameter.rabbit_password.arn,
aws_ssm_parameter.secret_cookie.arn,
]
}
statement {
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
var.kms_key_arn
]
}
dynamic "statement" {
for_each = var.enable_password_rotation ? [true] : []
content {
effect = "Allow"
actions = [
"ssm:GetParameter"
]
resources = [
aws_ssm_parameter.secondary_rabbit_password[0].arn,
aws_ssm_parameter.secondary_rabbit_admin_password[0].arn,
aws_ssm_parameter.secondary_datadog_user_password[0].arn,
]
}
}
}
resource "aws_iam_role_policy" "iam_policy" {
name = "${var.name}-${data.aws_region.current.name}"
role = aws_iam_role.iam_role.id
policy = data.aws_iam_policy_document.policy_permissions_doc.json
}
resource "aws_iam_instance_profile" "iam_profile" {
name_prefix = "${var.name}-${data.aws_region.current.name}-"
role = aws_iam_role.iam_role.name
}
resource "aws_iam_role" "iam_role" {
name = "${var.name}-${data.aws_region.current.name}"
assume_role_policy = data.aws_iam_policy_document.policy_doc.json
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "inspector2_managed_cis_policy" {
count = var.inspector2_cis_scanning_enabled ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonInspector2ManagedCisPolicy"
role = aws_iam_role.iam_role.name
}