Giter VIP home page Giter VIP logo

terraform-ecs-ec2-deployment's Introduction

Provisioning VPC, ECS and ALB using Terraform

This is the example of creating a simple infrastructure using Terraform and AWS cloud provider. It consists of:

  • Virtual Private Cloud (VPC) with 3 public subnets in 3 availability zones
  • Elastic Container Service (ECS)
  • Application Load Balancer (ALB)

How to create the infrastructure?

This example implies that you have already AWS account and Terraform CLI installed.

  1. git clone https://github.com/mashun4ek/ecs_terraform_workshop.git
  2. cd ecs_terraform_workshop
  3. terraform init
  4. terraform plan
  5. terraform apply

Note: it can take about 5 minutes to provision all resources.

How to delete the infrastructure?

  1. Terminate instances
  2. Run terraform destroy

Brief Description

Cluster is created using container instances (EC2 launch type, not Fargate!).

In this example, verified module vpc is imported from Terraform Registry, other resources are created in relevant files.

In file ecs.tf we create:

  • cluster of container instances web-cluster
  • capacity provider, which is basically AWS Autoscaling group for EC2 instances. In this example managed scaling is enabled, Amazon ECS manages the scale-in and scale-out actions of the Auto Scaling group used when creating the capacity provider. I set target capacity to 85%, which will result in the Amazon EC2 instances in your Auto Scaling group being utilized for 85% and any instances not running any tasks will be scaled in.
  • task definition with family web-family, volume and container definition is defined in the file container-def.json
  • service web-service, desired count is set to 10, which means there are 10 tasks will be running simultaneously on your cluster. There are two service scheduler strategies available: REPLICA and DAEMON, in this example REPLICA is used. Application load balancer is attached to this service, so the traffic can be distributed between those tasks. Note: The binpack task placement strategy is used, which places tasks on available instances that have the least available amount of the cpu (specified with the field parameter).

In file asg.tf we create:

  • launch configuration
  • key pair
  • security groups for EC2 instances
  • auto-scaling group.

Note: in order to enable ECS managed scaling you need to enable protect from scale in from auto-scaling group.

In file iam.tf we create roles, which will help us to associate EC2 instances to clusters, and other tasks.

In file alb.tf we create Application Load Balancer with target groups, security group and listener.

terraform-ecs-ec2-deployment's People

Contributors

mashun4ek avatar niki521 avatar

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.