-
Notifications
You must be signed in to change notification settings - Fork 25
/
role.tf
53 lines (43 loc) · 1.24 KB
/
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
# The SAML role to use for adding users to the ECR policy
variable "saml_role" {
}
# creates an application role that the container/task runs as
resource "aws_iam_role" "app_role" {
name = "${var.app}-${var.environment}"
assume_role_policy = data.aws_iam_policy_document.app_role_assume_role_policy.json
}
# assigns the app policy
resource "aws_iam_role_policy" "app_policy" {
name = "${var.app}-${var.environment}"
role = aws_iam_role.app_role.id
policy = data.aws_iam_policy_document.app_policy.json
}
# TODO: fill out custom policy
data "aws_iam_policy_document" "app_policy" {
statement {
actions = [
"ecs:DescribeClusters",
]
resources = [
aws_ecs_cluster.app.arn,
]
}
}
data "aws_caller_identity" "current" {
}
# allow role to be assumed by ecs and local saml users (for development)
data "aws_iam_policy_document" "app_role_assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
principals {
type = "AWS"
identifiers = [
"arn:aws:sts::${data.aws_caller_identity.current.account_id}:assumed-role/${var.saml_role}/[email protected]",
]
}
}
}