-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathiam.tf
75 lines (63 loc) · 1.92 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
data "aws_iam_policy_document" "resource_role" {
statement {
sid = "EC2AssumeRole"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals = {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
module "resource_role_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.1"
namespace = var.namespace
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
}
resource "aws_iam_role" "resource_role" {
name = module.resource_role_label.id
assume_role_policy = data.aws_iam_policy_document.resource_role.json
}
resource "aws_iam_role_policy_attachment" "resource_role" {
role = aws_iam_role.resource_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforDataPipelineRole"
}
resource "aws_iam_instance_profile" "resource_role" {
name = module.resource_role_label.id
role = aws_iam_role.resource_role.name
}
data "aws_iam_policy_document" "role" {
statement {
sid = "AssumeRole"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals = {
type = "Service"
identifiers = [
"elasticmapreduce.amazonaws.com",
"datapipeline.amazonaws.com",
]
}
}
}
module "role_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.1"
namespace = var.namespace
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = ["${compact(concat(var.attributes, list("role")))}"]
tags = var.tags
}
resource "aws_iam_role" "role" {
name = module.role_label.id
assume_role_policy = data.aws_iam_policy_document.role.json
}
resource "aws_iam_role_policy_attachment" "role" {
role = aws_iam_role.role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSDataPipelineRole"
}