AWS Elastic Container Services (ECS) Terraform Module
Terraform module to provision ECS Resources
on AWS.
This module contains ECS Service and ECS Task Definition as sub-modules under modules
folder.
In order to create an ECS Service , you need to create ECS Cluster and ECS Task Definition first as describe below.
Usage
Simple setup
Create a simple ECS cluster:
module "ecs" {
source = "app.terraform.io/ncodelibrary/ecs/aws"
version = "0.1.6"
identifier = "example"
container_insights = "disabled"
tags = {
Cost_Center = "XYZ"
}
}
Create a simple ECS Task Definition:
module ecs_task_definition {
source = "app.terraform.io/ncodelibrary/ecs/aws//modules/ecs-task-definition"
version = "0.1.6"
identifier = "example"
container_image = "nginx"
port_mappings = [
{
containerPort = 80
hostPort = 0
protocol = "tcp"
}
]
}
Create a simple ECS Service:
module ecs_service {
source = "app.terraform.io/ncodelibrary/ecs/aws//modules/ecs-service"
version = "0.1.6"
cluster = module.ecs.output.cluster.id
identifier = "example"
container_port = 80
vpc_id = "vpc-xxxxxxxxxxx"
task_definition = "arn:aws:ecs:us-west-2:xxxxxxx:task-definition/TaskDefinitionFamily:1"
listener_arn = "arn:aws:elasticloadbalancing:us-west-1:xxxxxxxx:listener/app/my-load-balancer/xxxx"
tags = {
Cost_Center = "XYZ"
}
}
Important Note: Please make sure identifier in ecs_task_definition
and ecs_service
are same.
For more details on a working example, please visit examples/simple
Advanced Setup
If you want to create a ElasticSearch Domain with an advanced configuration like Multi-AZ, you can use the module like this:
Create an ECS Cluster:
module "ecs" {
source = "app.terraform.io/ncodelibrary/ecs/aws"
version = "0.1.6"
identifier = "example"
container_insights = "disabled"
tags = {
Cost_Center = "XYZ"
}
}
Create a Task Definition
module ecs_task_definition {
source = "app.terraform.io/ncodelibrary/ecs/aws//modules/ecs-task-definition"
version = "0.1.6"
identifier = "example"
container_image = "nginx"
port_mappings = [
{
containerPort = 80
hostPort = 0
protocol = "tcp"
}
]
tags = {
Cost_Center = "XYZ"
}
execution_role_arn = "arn:aws:iam::xxxxxx"
task_role_arn = ""
container_memory = 256
container_memory_reservation = 128
container_cpu = 10
essential = true
environment = [
{
"name" : "ENVIRONMENT",
"value" : "PROD"
}
]
log_configuration = {
"logDriver" : "awslogs",
"options" : {
"awslogs-group" : var.identifier,
"awslogs-region" : "us-east-1",
"awslogs-stream-prefix" : "ecs"
}
}
}
Create an ECS Service
module ecs_service {
source = "app.terraform.io/ncodelibrary/ecs/aws//modules/ecs-service"
version = "0.1.6"
cluster = module.ecs.output.cluster.id
identifier = var.identifier
health_check_path = "/"
path_pattern = ["/*"]
scheduling_strategy = "REPLICA"
deployment_maximum_percent = 100
deployment_minimum_healthy_percent = 0
container_port = 80
vpc_id = "vpc-xxxxxxxxxx"
task_definition = "arn:aws:ecs:us-west-2:xxxxxxx:task-definition/TaskDefinitionFamily:1"
listener_arn = "arn:aws:elasticloadbalancing:us-west-1:xx:listener/app/my-load-balancer/xxxx"
desired_count = 1
tags = {
Cost_Center = "XYZ"
}
}
For more options refer to a working example at examples/advanced
Examples
Here are some working examples of using this module:
Requirements
Name | Version |
---|---|
terraform | >= 0.12 |
Providers
Name | Version |
---|---|
aws | n/a |
Modules
No Modules.
Resources
Name |
---|
aws_ecs_cluster |
Inputs
Name | Description | Type | Default | Required |
---|---|---|---|---|
append_workspace | Appends the terraform workspace at the end of resource names, |
bool |
true |
no |
capacity_providers | Capacity providers for ECS cluster | list(string) |
[] |
no |
container_insights | Enable container insights for the ecs cluster | string |
"enabled" |
no |
identifier | The name for the cluster | string |
n/a | yes |
tags | Tags to be applied to the resource | map(any) |
{} |
no |
Outputs
Name | Description |
---|---|
output | n/a |
Contributing
If you want to contribute to this repository check all the guidelines specified here before submitting a new PR.