Terraform module for scheduling Fargate tasks with CloudWatch Event Rules.
module "fargate-scheduled-task" {
source = "baikonur-oss/fargate-scheduled-task/aws"
version = "v2.0.2"
name = "dev-batch-foo"
schedule_expression = "cron(40 1 * * ? *)"
is_enabled = "true"
target_cluster_arn = "dev"
task_definition_arn = aws_ecs_task_definition.ecs_task_definition.arn
task_role_arn = module.iam_ecs_tasks.arn
task_count = "1"
subnet_ids = ["subnet-***1", "subnet-***2"]
security_group_ids = ["sg-***1", "sg-***2"]
}
module "iam_ecs_tasks" {
source = "baikonur-oss/iam-nofile/aws"
version = "2.0.0"
type = "ecs-tasks"
name = "dev-batch"
policy_json = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::example-bucket/*"
]
}
]
}
EOF
}
Use version
parameter to pin to a specific version, or to specify a version constraint when pulling from Terraform Module Registry (source = baikonur-oss/aws-fargate-scheduled-task/aws
).
For more information, refer to Module Versions section of Terraform Modules documentation.
Make sure to use ?ref=
version pinning in module source URI when pulling from GitHub.
Pulling from GitHub is especially useful for development, as you can pin to a specific branch, tag or commit hash.
Example: source = github.com/baikonur-oss/terraform-aws-fargate-scheduled-task?ref=v1.0.0
For more information on module version pinning, see Selecting a Revision section of Terraform Modules documentation.
Name | Description | Type | Default | Required |
---|---|---|---|---|
execution_role_arn | ARN of IAM Role for task execution (see: https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/task_execution_IAM_role.html ) | string | n/a | yes |
iam_ecs_run_task_resource | Field for overriding ecs:RunTask resource identifier in Events IAM role (defaults to task_definition_arn) | string | "" |
no |
is_enabled | Rule enabled flag | string | "true" |
no |
name | CloudWatch Event Rule name | string | n/a | yes |
schedule_expression | CloudWatch schedule expression (see: https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/events/ScheduledEvents.html ) | string | n/a | yes |
security_group_ids | List of security group ids for Fargate task ENI | list(string) | n/a | yes |
subnet_ids | List of subnet ids for Fargate task ENI | list(string) | n/a | yes |
assign_public_ip | Assign public ip for Fargate task ENI | string | "false" |
no |
target_cluster_arn | Target ECS cluster ARN | string | n/a | yes |
task_count | Number of tasks to execute at once | string | "1" |
no |
task_definition_arn | ARN of Task Definition to run | string | n/a | yes |
task_role_arn | ARN of IAM Role for task (see: https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/task-iam-roles.html ) | string | n/a | yes |
platform_version | Platform version | string | "1.4.0" |
no |
Make sure to have following tools installed:
brew install pre-commit terraform terraform-docs
# set up pre-commit hooks by running below command in repository root
pre-commit install