diff --git a/main.tf b/main.tf index 285ca8e..b5b6794 100644 --- a/main.tf +++ b/main.tf @@ -48,7 +48,7 @@ resource "aws_iam_role_policy" "scheduled_task_cloudwatch_policy" { resource "aws_ecs_task_definition" "scheduled_task" { family = "${var.name}-${var.environment}-scheduled-task" container_definitions = "${var.container_definitions}" - requires_compatibilities = ["EC2"] + requires_compatibilities = ["${var.launch_type}"] network_mode = "${var.network_mode}" execution_role_arn = "${aws_iam_role.scheduled_task_ecs_execution.arn}" task_role_arn = "${aws_iam_role.scheduled_task_ecs.arn}" @@ -73,5 +73,12 @@ resource "aws_cloudwatch_event_target" "scheduled_task" { ecs_target { task_count = "${var.task_count}" task_definition_arn = "${aws_ecs_task_definition.scheduled_task.arn}" + launch_type = "${var.launch_type}" + + network_configuration { + subnets = ["${var.subnets}"] + security_groups = ["${var.security_groups}"] + assign_public_ip = "${var.assign_public_ip}" + } } } diff --git a/variables.tf b/variables.tf index c6fcf42..c38a101 100644 --- a/variables.tf +++ b/variables.tf @@ -8,12 +8,6 @@ variable "environment" { description = "Environment - appended to ${var.name} for resources" } -variable "network_mode" { - type = "string" - description = "Task network mode" - default = "bridge" -} - variable "container_definitions" { type = "string" description = "Task container defintions" @@ -44,3 +38,29 @@ variable "memory" { type = "string" description = "The amount (in MiB) of memory used by the task" } + +variable "network_mode" { + type = "string" + description = "Task network mode" + default = "bridge" +} + +variable "launch_type" { + description = "Launch type on which your task is running. Valid values are EC2 or FARGATE." + default = "EC2" +} + +variable "subnets" { + description = "List of subnets if network_mode is `awsvpc`" + default = [] +} + +variable "security_groups" { + description = "List of security groups if network_mode is `awsvpc`" + default = [] +} + +variable "assign_public_ip" { + description = "Assign a public IP to the ENI (Fargate launch type only)" + default = false +}