-
Notifications
You must be signed in to change notification settings - Fork 6
/
iam.tf
61 lines (52 loc) · 1.86 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
data "aws_iam_policy_document" "ec2_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["ec2.amazonaws.com"]
type = "Service"
}
effect = "Allow"
}
}
resource "aws_iam_role" "ec2_role" {
name = "${var.service_name}-${var.env}-ec2-role"
assume_role_policy = data.aws_iam_policy_document.ec2_role.json
}
resource "aws_iam_instance_profile" "ec2_iam_instance_profile" {
name = "${var.service_name}-${var.env}-iam-instance-profile"
role = aws_iam_role.ec2_role.name
}
resource "aws_iam_role_policy_attachment" "policy_attachment_1" {
role = aws_iam_role.ec2_role.name
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier"
}
resource "aws_iam_role_policy_attachment" "policy_attachment_2" {
role = aws_iam_role.ec2_role.name
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier"
}
resource "aws_iam_role_policy_attachment" "policy_attachment_3" {
role = aws_iam_role.ec2_role.name
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker"
}
data "aws_iam_policy_document" "service_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["elasticbeanstalk.amazonaws.com"]
type = "Service"
}
effect = "Allow"
}
}
resource "aws_iam_role" "service_role" {
name = "${var.service_name}-${var.env}-service-role"
assume_role_policy = data.aws_iam_policy_document.service_role.json
}
resource "aws_iam_role_policy_attachment" "policy_attachment_4" {
role = aws_iam_role.service_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth"
}
resource "aws_iam_role_policy_attachment" "service" {
role = aws_iam_role.service_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkService"
}