Coder Social home page Coder Social logo

jch254 / terraform-ecs-autoscale-alb Goto Github PK

View Code? Open in Web Editor NEW
63.0 8.0 19.0 58 KB

ECS cluster with instance and service autoscaling configured and running behind an ALB with path based routing set up

License: MIT License

Shell 4.86% HCL 89.95% JavaScript 4.68% Dockerfile 0.51%
terraform ecs-cluster bitbucket-pipelines docker alb aws ecs autoscaling

terraform-ecs-autoscale-alb's Introduction

Terraform-ecs-autoscale-alb

Amazon EC2 Container Service (ECS) is a highly scalable, fast, container management service that makes it easy to run, stop, and manage Docker containers on a cluster of EC2 instances (called container instances).

The idea behind ECS is to create a cluster (a group of container instances managed by ECS), define what Docker containers we want to run (with configuration for each container) and ECS will take care of deploying those containers across the cluster, rolling out new versions and integrating with other AWS infrastructure/services.

A task definition is required to run a Docker container on an ECS cluster. A task definition specifies various parameters such as which Docker image(s) to use and the repository in which the image is stored, how much CPU and memory to use for the container, which environment variables should be passed to the container when it starts, which logging driver to use (awslogs, syslog etc.).


This repo contains Terraform configuration for an ECS cluster running three services (alpha, beta and charlie) with instance and service autoscaling configured at 80% CPU and memory (min and max autoscaling limits can be configured). The three services are sitting behind an Application Load Balancer (ALB) with path based routing set up.

As far as I could tell the ALB doesn't currently support URL Rewriting so I've had to manually perform this at the application level.

The code for the demo API is in the /demo-api directory and is built and hosted on Docker Hub.

Dockerhub badge

Base-infra components:

  • VPC
  • Public and private subnets
  • Internet Gateway
  • NAT Gateways
  • ALB in public subnet with Route53 record
  • ECS cluster
  • ECS container instances in private subnet with autoscaling configured (running Datadog agent and NGINX serving a default index.html for ALB default action on boot)
  • Bastion instance in public subnet (in ASG with a fixed size of one). This only allows SSH access for a specific IP address.

Service components

  • ECS service with autoscaling configured
  • ALB listener and target group

Deploying via Bitbucket Pipelines

Deployment to AWS is automated via Bitbucket Pipelines.

Before running pipeline for the first time you must:

  1. Enable Bitbucket Pipelines for repository
  2. Create an S3 bucket named 'your-terraform-remote-state' for Terraform remote state via console or CLI
  3. Create a Bitbucket Pipelines IAM user with the required permissions
  4. Set up the following account-level Bitbucket Pipelines environment variables in Bitbucket UI:
    • AWS_ACCESS_KEY_ID = PIPELINES_USER_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY = PIPELINES_USER_SECRET_ACCESS_KEY
  5. Set up the following repository-level Bitbucket Pipelines environment variables in Bitbucket UI:
    • TF_VAR_ssh_allowed_ip = YOUR_IP
    • TF_VAR_acm_arn = YOUR_ACM_CERT_ARN
    • TF_VAR_route53_zone_id = YOUR_R53_ZONE_ID
    • TF_VAR_datadog_api_key = YOUR_DATADOG_API_KEY
    • TF_VAR_key_pair_name = YOUR_KEY_PAIR_NAME
    • TF_VAR_bastion_key_pair_name = YOUR_KEY_PAIR_NAME
  6. Edit configuration in the .tfvars file in /base-infra, /alpha-service, /beta-service and /charlie-service directories with required values.
  7. Update deploy.bash file in /base-infra, /alpha-service, /beta-service and [/charlie-service] (../master/charlie-service/) directories with your remote state bucket name.
  8. Uncomment steps in /bitbucket-pipelines.yml and commit to repository to trigger the pipeline

Refer to deploy.bash files for manual deployment steps.

  • TODO: Add comments throughout infra code

terraform-ecs-autoscale-alb's People

Contributors

jch254 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-ecs-autoscale-alb's Issues

Add license to repository

Hi! Thanks for contributing this terraform setup โ€“ it's really helped me get up to speed with ECS and terraform.

I would like to use the ECS cluster/instance code here, but I can't see a license on the repo or code. Without a license the default copyright laws apply, which means no-one can (or probably "should") use the code.

I have an affinity towards MIT, but there's a whole host of options: https://help.github.com/articles/licensing-a-repository/.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.