Skip to content

Commit

Permalink
Add task definition support
Browse files Browse the repository at this point in the history
  • Loading branch information
mwkaufman committed Jun 8, 2020
1 parent c0c6175 commit 5983a8b
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
<a href="https://www.rearc.io/data/">
<img src="https://www.rearc.io/wp-content/uploads/2018/11/Logo.png" alt="Rearc Logo" title="Rearc Logo" height="52" />
</a>

# terraform-aws-ecs-task
Terraform module to provide ECS task definitions and optionally other related resources such as IAM roles, security groups, an ECS service, and a load balancer to run a variety of workloads on ECS.

Terraform module to provide an ECS task definition and optionally an ECS service and a load balancer to run a variety of workloads on ECS.

## Introduction

The module will create:

* ECS task definition
* ECS service (TBD)
* AutoScaling target, policies, and CloudWatch alarms (TBD)
* Required security groups (TBD)
* Application load balancer (TBD)
* Route53 A record (TBD)

## Usage

By default, this will create a task definition which can be run using the ECS [RunTask API](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html).
```hcl
module "ecs_task" {
source = "git::https://github.com/rearc/terraform-aws-ecs-task.git"
aws_account_id = "123456789012"
region = "us-east-1"
name = "express_api"
image = "bitnami/express"
}
```
11 changes: 11 additions & 0 deletions examples/express/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
provider "aws" {
region = "us-east-1"
}

module "ecs_task" {
source = "../.."
aws_account_id = "123456789012"
region = "us-east-1"
name = "express_api"
image = "bitnami/express"
}
27 changes: 27 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
locals {
image = var.image_tag == "latest" ? var.image : "${var.image}:${var.image_tag}"
stack = var.stack != "" ? var.stack : var.environment
}

resource "aws_ecs_task_definition" "task_definition" {
family = "${local.stack}_${var.name}"
network_mode = "awsvpc"
execution_role_arn = "arn:aws:iam::${var.aws_account_id}:role/ecsTaskExecutionRole"
container_definitions = <<JSON
[
{
"cpu": 512,
"essential": true,
"memory": 1024,
"memoryReservation": 512,
"name": ""${local.stack}_${var.name}",
"image": "${local.image}",
"portMappings": [
{
"containerPort": 3000
}
]
}
]
JSON
}
61 changes: 61 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
variable "aws_account_id" {
type = string
description = "AWS Account ID"
}

variable "region" {
type = string
description = "AWS Region, e.g. us-east-1"
}

variable "name" {
type = string
description = "Name of the task to define for ECS"
}

variable "image" {
type = string
description = "Name of image to run in ECS task"
}

variable "environment" {
type = string
description = "Infrastructure environment, e.g. staging or production"
default = "staging"
}

variable "stack" {
type = string
description = "Name to differentiate applications deployed in the same infrastructure environment"
default = ""
}

variable "image_tag" {
type = string
description = "Image tag to run in ECS task"
default = "latest"
}

variable "task_role_arn" {
type = string
description = "IAM role to run ECS task with"
default = ""
}

variable "ecs_cluster_name" {
type = string
description = "Elastic Container Service cluster name to deploy services to"
default = ""
}

variable "subnets" {
type = list(string)
description = "VPC subnets to run ECS task in"
default = []
}

variable "security_groups" {
type = list(string)
description = "VPC security groups to run ECS task in"
default = []
}

0 comments on commit 5983a8b

Please sign in to comment.