Skip to content

Terraform module which creates ECS Scheduled Task resources on AWS.

License

Notifications You must be signed in to change notification settings

penngineering/terraform-aws-ecs-scheduled-task

 
 

Repository files navigation

terraform-aws-ecs-scheduled-task

Terraform Actions Status Markdown Actions Status YAML Actions Status JSON Actions Status GitHub tag License

Terraform module which creates ECS Scheduled Task resources on AWS.

Description

Provision ECS Task Definitions and CloudWatch Events.

This module provides recommended settings:

  • Fargate launch type
  • Disable assign public ip address

Usage

Minimal

module "ecs_scheduled_task" {
  source                = "git::https://github.com/tmknom/terraform-aws-ecs-scheduled-task.git?ref=tags/2.0.0"
  name                  = "example"
  schedule_expression   = "rate(3 minutes)"
  container_definitions = var.container_definitions
  cluster_arn           = var.cluster_arn
  subnets               = var.subnets
}

Complete

module "ecs_scheduled_task" {
  source                = "git::https://github.com/tmknom/terraform-aws-ecs-scheduled-task.git?ref=tags/2.0.0"
  name                  = "example"
  schedule_expression   = "rate(3 minutes)"
  container_definitions = var.container_definitions
  cluster_arn           = var.cluster_arn
  subnets               = var.subnets

  is_enabled               = true
  task_count               = 1
  platform_version         = "LATEST"
  assign_public_ip         = true
  security_groups          = []
  cpu                      = 256
  memory                   = 512
  requires_compatibilities = ["FARGATE"]
  iam_path                 = "/service_role/"
  description              = "This is example"
  enabled                  = true

  create_ecs_events_role = false
  ecs_events_role_arn    = var.ecs_events_role_arn

  create_ecs_task_execution_role = false
  ecs_task_execution_role_arn    = var.ecs_events_role_arn

  create_ecs_task_role = false
  ecs_task_role_arn    = var.ecs_task_role_arn

  tags = {
    Environment = "prod"
  }
}

Examples

Requirements

Name Version
terraform >= 0.12

Providers

Name Version
aws n/a

Inputs

Name Description Type Default Required
cluster_arn ARN of an ECS cluster. string n/a yes
container_definitions A list of valid container definitions provided as a single valid JSON document. string n/a yes
name The name of ecs task definition. string n/a yes
schedule_expression The scheduling expression.For example, cron(0 20 * * ? *) or rate(5 minutes). string n/a yes
subnets The subnets associated with the task or service. list(string) n/a yes
assign_public_ip Assign a public IP address to the ENI (Fargate launch type only). string false no
cpu The number of cpu units used by the task. string "256" no
create_ecs_events_role Specify true to indicate that CloudWatch Events IAM Role creation. string true no
create_ecs_task_execution_role Specify true to indicate that ECS Task Execution IAM Role creation. string true no
description The description of the all resources. string "Managed by Terraform" no
ecs_events_role_arn The ARN of the CloudWatch Events IAM Role. string "" no
ecs_task_execution_role_arn The ARN of the ECS Task Execution IAM Role. string "" no
enabled Set to false to prevent the module from creating anything. bool true no
iam_path Path in which to create the IAM Role and the IAM Policy. string "/" no
is_enabled Whether the rule should be enabled. string true no
memory The amount (in MiB) of memory used by the task. string "512" no
platform_version Specifies the platform version for the task. string "1.4.0" no
requires_compatibilities A set of launch types required by the task. The valid values are EC2 and FARGATE. list(string)
[
"FARGATE"
]
no
security_groups The security groups associated with the task or service. list(string) [] no
tags A mapping of tags to assign to all resources. map(string) {} no
task_count The number of tasks to create based on the TaskDefinition. string 1 no

Outputs

Name Description
cloudwatch_event_rule_arn The Amazon Resource Name (ARN) of the rule.
ecs_events_policy_arn The ARN assigned by AWS to this CloudWatch Events IAM Policy.
ecs_events_policy_description The description of the CloudWatch Events IAM Policy.
ecs_events_policy_document The policy document of the CloudWatch Events IAM Policy.
ecs_events_policy_id The CloudWatch Events IAM Policy's ID.
ecs_events_policy_name The name of the CloudWatch Events IAM Policy.
ecs_events_policy_path The path of the CloudWatch Events IAM Policy.
ecs_events_role_arn The Amazon Resource Name (ARN) specifying the CloudWatch Events IAM Role.
ecs_events_role_create_date The creation date of the IAM Role.
ecs_events_role_description The description of the CloudWatch Events IAM Role.
ecs_events_role_name The name of the CloudWatch Events IAM Role.
ecs_events_role_unique_id The stable and unique string identifying the CloudWatch Events IAM Role.
ecs_task_definition_arn Full ARN of the Task Definition (including both family and revision).
ecs_task_definition_family The family of the Task Definition.
ecs_task_definition_revision The revision of the task in a particular family.
ecs_task_execution_policy_arn The ARN assigned by AWS to this ECS Task Execution IAM Policy.
ecs_task_execution_policy_description The description of the ECS Task Execution IAM Policy.
ecs_task_execution_policy_document The policy document of the ECS Task Execution IAM Policy.
ecs_task_execution_policy_id The ECS Task Execution IAM Policy's ID.
ecs_task_execution_policy_name The name of the ECS Task Execution IAM Policy.
ecs_task_execution_policy_path The path of the ECS Task Execution IAM Policy.
ecs_task_execution_role_arn The Amazon Resource Name (ARN) specifying the ECS Task Execution IAM Role.
ecs_task_execution_role_create_date The creation date of the ECS Task Execution IAM Role.
ecs_task_execution_role_description The description of the ECS Task Execution IAM Role.
ecs_task_execution_role_name The name of the ECS Task Execution IAM Role.
ecs_task_execution_role_unique_id The stable and unique string identifying the ECS Task Execution IAM Role.

Development

Development Requirements

Configure environment variables

export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=ap-northeast-1

Installation

git clone [email protected]:tmknom/terraform-aws-ecs-scheduled-task.git
cd terraform-aws-ecs-scheduled-task
make install

Makefile targets

apply-complete                 Run terraform apply examples/complete
apply-minimal                  Run terraform apply examples/minimal
bump-version                   Bump version (Required argument 'VERSION')
check-format                   Check format code
clean                          Clean .terraform
destroy-complete               Run terraform destroy examples/complete
destroy-minimal                Run terraform destroy examples/minimal
diff                           Word diff
docs                           Generate docs
format                         Format code
help                           Show help
install                        Install requirements
lint                           Lint code
plan-complete                  Run terraform plan examples/complete
plan-minimal                   Run terraform plan examples/minimal
release                        Release GitHub and Terraform Module Registry
upgrade                        Upgrade makefile

Releasing new versions

Bump VERSION file, and run make release.

Terraform Module Registry

License

Apache 2 Licensed. See LICENSE for full details.

About

Terraform module which creates ECS Scheduled Task resources on AWS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 94.5%
  • Makefile 5.5%