generated from baikonur-oss/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
67 lines (57 loc) · 1.52 KB
/
main.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
# CloudWatch Event on Fargate
locals {
iam_ecs_run_task_resource = var.iam_ecs_run_task_resource != "" ? var.iam_ecs_run_task_resource : var.task_definition_arn
}
resource "aws_cloudwatch_event_rule" "schedule_rule" {
name = var.name
schedule_expression = var.schedule_expression
is_enabled = var.is_enabled
}
resource "aws_cloudwatch_event_target" "fargate_scheduled_task" {
rule = aws_cloudwatch_event_rule.schedule_rule.name
arn = var.target_cluster_arn
role_arn = module.iam.arn
ecs_target {
task_definition_arn = var.task_definition_arn
task_count = var.task_count
launch_type = "FARGATE"
platform_version = var.platform_version
network_configuration {
subnets = var.subnet_ids
security_groups = var.security_group_ids
assign_public_ip = var.assign_public_ip
}
}
}
module "iam" {
source = "baikonur-oss/iam-nofile/aws"
version = "2.0.0"
type = "events"
name = var.name
policy_json = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:RunTask"
],
"Resource": [
"${local.iam_ecs_run_task_resource}"
]
},
{
"Effect": "Allow",
"Action": [
"iam:PassRole"
],
"Resource": [
"${var.task_role_arn}",
"${var.execution_role_arn}"
]
}
]
}
EOF
}