-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiam.ts
58 lines (51 loc) · 1.57 KB
/
iam.ts
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
import { iam } from "@cdktf/provider-aws"
import { Fn } from "cdktf"
import { Construct } from "constructs"
import { Tfvars } from "./variables"
export class EcsMonitoringIamTaskExecRole extends Construct {
public role: iam.IamRole
constructor(
scope: Construct,
name: string,
vars: Tfvars
) {
super(scope, name)
const nameTagPrefix = `${Fn.lookup(vars.defaultTags, "project", "")}`
const assumeRolePolicyDoc = new iam.DataAwsIamPolicyDocument(this, "monitoring-assume-role-doc", {
version: "2012-10-17",
statement: [
{
effect: "Allow",
actions: ["sts:AssumeRole"],
principals: [{
identifiers: ["ecs-tasks.amazonaws.com"],
type: "Service"
}]
}
]
})
const monitoringPermissionsDoc = new iam.DataAwsIamPolicyDocument(this, "monitoring-permissions", {
version: "2012-10-17",
statement: [
{
effect: "Allow",
actions: [
"ecs:ListClusters",
"ecs:ListContainerInstances",
"ecs:DescribeContainerInstances"
],
resources: ["*"]
}
]
})
this.role = new iam.IamRole(this, "monitoring-task-exec-role", {
namePrefix: `${nameTagPrefix}-te-role`,
description: "Task execution role for monitoring with ECS Task definitions",
assumeRolePolicy: assumeRolePolicyDoc.json
})
new iam.IamPolicy(this, "monitoring-permissions-attachment", {
name: `${nameTagPrefix}-monitoring-policy`,
policy: monitoringPermissionsDoc.json
})
}
}