Skip to content

acro5piano/terraform-fargate-example

Repository files navigation

Terraform & Fargate example

A dead simple example to setup AWS Fargate using Fargate CLI + Terraform

Features

  • Use Terraform to setup AWS ECS basic environment
  • Use Fargate CLI to create Fargate services without hassle
  • Zero-downtime deploy thanks to Fargate

Why

We can create all of AWS ECS environment with Terraform. However, it requires a lot of Terraform boilerplates and understanding how Terraform works. Instead of copy & paste HCL from the Terraform document, let's delegate some parts to Fargate CLI.

How to use

Initial Setup

cp aws-credentials.ini.example aws-credentials.ini

# Add your credentials
vim aws-credentials.ini

# Initialize Terraform
make init

Create service

make create

Show information

make info

Deploy service

make deploy

Note: This will build Dockerfile in the current directory. If you have other deploy strategy, edit Makefile.

Delere everything

make destroy

Note: ECS Execution Role will not be deleted.

What will be created?

By Terraform:

  • ECS Cluser
  • EC2 Security Group
  • ECR Repository

By Fargate CLI:

  • ECS Task Definition
  • ECS Service
  • ECS Task
  • ECS Task Execution Role
  • ALB
  • ALB Target Group
  • CloudWatch Log Group