-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] | ||
} |