Git Product home page Git Product logo

terraform-module-fargate-deploy's Introduction

Terraform module to deploy an APP into ECS Fargate cluster.

This module:

  • Create tasks.
  • Create service.
  • Zero downtime deploy.
  • Create monitoring using CloudWatch.
  • Receive an json with containers definitions.

Usage

module "app-deploy" {
  source                 = "[email protected]:gomex/terraform-module-fargate-deploy.git?ref=v0.1"
  containers_definitions = data.template_file.containers_definitions_json.rendered
  environment            = "development"
  subdomain_name         = "app"
  app_name               = "app"
  hosted_zone_id         = "Z09847195EBZJRXWQDI"
  app_port               = "80"
  cloudwatch_group_name  = "development-app"
}

################   DATA   ################ 

data "template_file" "containers_definitions_json" {
  template = file("./containers_definitions.json")

  vars = {
    APP_VERSION = var.APP_VERSION
    APP_IMAGE   = var.APP_IMAGE
    ENVIRONMENT = "development"
    AWS_REGION  = var.aws_region
  }
}

################   VARIABLES   ################ 
variable "APP_VERSION" {
}

variable "APP_IMAGE" {
  default = "app"
}

variable "aws_region" {
  default = "us-east-1"
}

Container Definition Sample

Create a folder called templates and a file called containers_definitions.json with the content bellow:

[
  {
    "cpu": 1024,
    "image": "670631891947.dkr.ecr.us-east-1.amazonaws.com/my_app:${APP_VERSION}",
    "memory": 1024,
    "name": "myawesomeapp",
    "networkMode": "awsvpc",
    "portMappings": [
      {
        "containerPort": 3000,
        "hostPort": 3000
      }
    ],
    "environment": [
      {
        "name": "AWESOME_ENV_VAR",
        "value": "${AWESOME_ENV_VAR}"
      }
    ],
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-group": "awesomeapp-gp",
        "awslogs-region": "us-east-1",
        "awslogs-stream-prefix": "myawesomeapp-${APP_VERSION}"
      }
    }
  }
]
  • The name of one container created on containers_definitions.json should be the same as app_name passed to module.
  • You can configure almost everything as variable, and you probably should do this.

Multiple Container Definition Sample

[
  {
    "cpu": 1024,
    "image": "670631891947.dkr.ecr.us-east-1.amazonaws.com/my_app:${APP_VERSION}",
    "memory": 1024,
    "name": "myawesomeapp",
    "networkMode": "awsvpc",
    "portMappings": [
      {
        "containerPort": 3000,
        "hostPort": 3000
      }
    ]
  },
  {
    "cpu": 1024,
    "image": "670631891947.dkr.ecr.us-east-1.amazonaws.com/my_worker:${APP_VERSION}",
    "memory": 1024,
    "name": "myawesomeworker",
    "networkMode": "awsvpc",
    "portMappings": [
      {
        "containerPort": 3000,
        "hostPort": 3000
      }
    ]
  }
]

Inputs

Name Description Type Default Required
app_count Number of tasks that will be deployed for this app. string "1" no
app_name How your app will be called. string n/a yes
app_port The PORT that will be used to communication between load balancer and container. string "3000" no
aws_region The AWS region to create things in. string "us-east-1" no
cloudwatch_group_name CloudWatch group name where to send the logs. string "sample-group-name" no
containers_definitions A JSON with all container definitions that should be run on the task. For more http://bit.do/eKzfH string n/a yes
environment The enviroment name where that app will be deployed. string "development" no
fargate_cpu The maximum of CPU that the task can use. string "1024" no
fargate_memory The maximum of memory that the task can use. string "1024" no
fargate_version The fargate version used to deploy inside ECS cluster. string "1.3.0" no
subdomain_name The subdomain that will be create for the app. string n/a yes

Wiki

Want to know more?

terraform-module-fargate-deploy's People

Contributors

gomex avatar

Watchers

 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.