Skip to content

geekcell/terraform-aws-ecs-fargate-eventbridge

Repository files navigation

Geek Cell GmbH

Code Quality

License GitHub release (latest tag) Release Validate Lint

Terraform AWS ECS Fargate EventBridge

This module creates an AWS EventBridge (formerly known as CloudWatch Events) rule and target to run a task on an ECS Fargate cluster. This is useful for running tasks periodically, like cleanup CRON jobs.

Inputs

Name Description Type Default Required
assign_public_ip Assign a public IP address to the ENI. bool false no
container_overrides The container overrides for the ECS task. list(any) [] no
ecs_cluster_arn The ARN of the ECS cluster to run the task in. string n/a yes
ecs_target_group The name of the ECS task group for the task. string null no
enable_ecs_managed_tags Specifies whether to enable Amazon ECS managed tags for the task. bool false no
enable_execute_command Whether to enable the execute command functionality for the ECS task. bool false no
platform_version Platform version on which to run your ECS task. string "1.4.0" no
propagate_tags Specifies whether to propagate the tags from the task definition the ECS tasks. string null no
rule_description Description of the rule. string null no
rule_is_enabled Whether the rule is enabled. bool true no
rule_name Name of the rule. string n/a yes
rule_role_arn The ARN of the IAM role associated with the rule. string null no
rule_schedule_expression The scheduling expression. For example, cron(0 20 * * ? *) or rate(5 minutes). string n/a yes
security_group_ids Security groups associated with the ECS task. If you do not specify a security group, the default security group for the VPC is used. list(string) [] no
subnet_ids Subnets associated with the ECS task. list(string) n/a yes
tags Tags to add to the created resources. map(any) {} no
target_name Name of the target. string n/a yes
target_policy_name The name of the policy to create. string null no
target_policy_name_prefix Whether to use the target_policy_name as a prefix or not. bool false no
target_role_name The name of the EventBridge target role. string null no
target_role_name_prefix Whether to prefix the EventBridge target role name. bool false no
task_count The number of tasks to create based on the task definition. number 1 no
task_definition_arn The ARN of the task definition to use. string n/a yes
task_execution_role_arn The ARN of the IAM role to use as execution role for the ECS task. string null no
task_role_arn The ARN of the IAM role to use as task role for the ECS task. string null no
use_rule_name_prefix Use the rule_name attribute as prefix for the rule name. bool false no

Outputs

No outputs.

Providers

Name Version
aws >= 4.36

Resources

  • resource.aws_cloudwatch_event_rule.main (main.tf#7)
  • resource.aws_cloudwatch_event_target.main (main.tf#20)

Examples

Complete

module "example" {
  source = "../../"

  rule_name                = "run-cleanup-script-on-midnight"
  rule_schedule_expression = "cron(0 0 * * ? *)"

  target_name = "ecs-fargate-taskdef"

  ecs_cluster_arn     = "arn:aws:ecs:us-east-1:123456789012:cluster/ecs-cluster"
  task_definition_arn = "arn:aws:ecs:us-east-1:123456789012:task-definition/ecs-task"

  security_group_ids = ["sg-12345678"]
  subnet_ids = [
    "subnet-12345678",
    "subnet-87654321",
  ]
}