-
Notifications
You must be signed in to change notification settings - Fork 2
/
iam_role.tf
58 lines (47 loc) · 1.25 KB
/
iam_role.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
data "aws_iam_policy_document" "access" {
statement {
sid = "AllowS3"
effect = "Allow"
actions = [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket",
]
resources = [
"${local.bucket_arn}",
"${local.bucket_arn}/*",
]
}
}
data "aws_iam_policy_document" "trust" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_policy" "access" {
count = var.create_agent_role ? 1 : 0
name = var.agent_role_name
policy = data.aws_iam_policy_document.access.json
}
locals {
agent_role_arn = var.create_agent_role ? module.agent[0].iam_role_arn : data.aws_iam_role.agent[0].arn
}
data "aws_iam_role" "agent" {
count = var.create_agent_role ? 0 : 1
name = var.agent_role_name
}
module "agent" {
count = var.create_agent_role ? 1 : 0
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
version = ">= 5.1.0"
create_role = true
role_name = var.agent_role_name
create_custom_role_trust_policy = true
custom_role_trust_policy = data.aws_iam_policy_document.trust.json
custom_role_policy_arns = [aws_iam_policy.access[0].arn, ]
}