Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ resource "aws_cloudwatch_event_target" "default" {
# Contains the Amazon ECS task definition and task count to be used, if the event target is an Amazon ECS task.
# https://docs.aws.amazon.com/AmazonCloudWatchEvents/latest/APIReference/API_EcsParameters.html
ecs_target {
launch_type = "FARGATE"
launch_type = var.launch_type
task_count = var.task_count
task_definition_arn = aws_ecs_task_definition.default[0].arn

# Specifies the platform version for the task. Specify only the numeric portion of the platform version, such as 1.1.0.
# This structure is used only if LaunchType is FARGATE.
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/platform_versions.html
platform_version = var.platform_version
task_definition_arn = var.create_ecs_task_definition ? aws_ecs_task_definition.default[0].arn : var.ecs_task_definition_arn

# This structure specifies the VPC subnets and security groups for the task, and whether a public IP address is to be used.
# This structure is relevant only for ECS tasks that use the awsvpc network mode.
Expand Down Expand Up @@ -115,7 +110,7 @@ locals {

# https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html
resource "aws_ecs_task_definition" "default" {
count = var.enabled ? 1 : 0
count = var.enabled && var.create_ecs_task_definition ? 1 : 0

# A unique name for your task definition.
family = var.name
Expand Down
19 changes: 19 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ variable "subnets" {
variable "container_definitions" {
type = string
description = "A list of valid container definitions provided as a single valid JSON document."
default = null
}

variable "is_enabled" {
Expand Down Expand Up @@ -65,6 +66,12 @@ variable "memory" {
description = "The amount (in MiB) of memory used by the task."
}

variable "launch_type" {
default = "FARGATE"
type = string
description = "Launch type to use for ecs task"
}

variable "requires_compatibilities" {
default = ["FARGATE"]
type = list(string)
Expand Down Expand Up @@ -118,3 +125,15 @@ variable "ecs_task_execution_role_arn" {
type = string
description = "The ARN of the ECS Task Execution IAM Role."
}

variable "create_ecs_task_definition" {
default = true
type = string
description = "Specify true to indicate that Task Definition creation."
}

variable "ecs_task_definition_arn" {
default = ""
type = string
description = "Specify true to indicate that Task Definition creation."
}