-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschedule.tf
60 lines (55 loc) · 1.68 KB
/
schedule.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
resource "aws_cloudwatch_event_rule" "event_rule" {
name = var.task_family
schedule_expression = var.schedule_expression
state = var.schedule_state
}
resource "aws_cloudwatch_event_target" "event_target" {
rule = aws_cloudwatch_event_rule.event_rule.name
arn = var.ecs_cluster_arn
role_arn = aws_iam_role.event_target.arn
# FUTURE USE CASE
#input = var.task_container_overrides
ecs_target {
enable_execute_command = var.ecs_execute_command_enabled
launch_type = "FARGATE"
platform_version = var.ecs_platform_version
task_count = var.task_count
task_definition_arn = aws_ecs_task_definition.task.arn
network_configuration {
subnets = var.subnet_ids
security_groups = var.security_group_ids
assign_public_ip = var.assign_public_ip
}
}
}
resource "aws_iam_role" "event_target" {
name = "${var.task_family}-event-target"
assume_role_policy = data.aws_iam_policy_document.principal.json
}
resource "aws_iam_role_policy" "event_target" {
name = "inline1"
role = aws_iam_role.event_target.id
policy = data.aws_iam_policy_document.event_target.json
}
resource "aws_iam_role_policies_exclusive" "event_target" {
role_name = aws_iam_role.event_target.name
policy_names = [aws_iam_role_policy.event_target.name]
}
data "aws_iam_policy_document" "event_target" {
statement {
actions = [
"ecs:RunTask"
]
resources = [
"${aws_ecs_task_definition.task.arn_without_revision}:*"
]
}
statement {
actions = [
"iam:PassRole"
]
resources = [
aws_iam_role.task.arn, aws_iam_role.exec.arn
]
}
}