Skip to content

Latest commit

 

History

History
157 lines (124 loc) · 6.42 KB

README.md

File metadata and controls

157 lines (124 loc) · 6.42 KB

Terraform ECS Module

terraform-aws-ecs

Simple Terraform module to deploy an ECS task using AWS Fargate including addons (Load Balancer, ECR, CI credentials)

Example usage

Bootstrapped setup

module "ecr" {
  source  = "tbobm/ecs/aws"
  # version = "" use latest version

  container = {
    image = "particuleio/helloworld"
  }

  networking = {
    vpc_id = "vpc-xxxxxxxx"
    subnet_ids = ["subnet-xxxxxxxx"]
  }
}

Restricted setup

Simply setup an ECS Cluster and Service based on container.image.

module "ecr" {
  source  = "tbobm/ecs/aws"
  # version = "" use latest version

  container = {
    image = "particuleio/helloworld"
  }

  networking = {
    vpc_id = "vpc-xxxxxxxx"
    subnet_ids = ["subnet-xxxxxxxx"]
  }
  addons = {
    iam = {
      enable = false
    }
    ecr = {
      enable = false
    }
    loadbalancer = {
      enable = false
    }
  }
}

Use an external ECS Task definition

module "ecr" {
  source  = "tbobm/ecs/aws"
  # version = "" use latest version

  ecs_values = {
    ecs_task_arn = "arn:aws:ecs:<region>:<aws_account_id>:task-definition/<task_family>:1"
  }
  networking = {
    vpc_id = "vpc-xxxxxxxx"
    subnet_ids = ["subnet-xxxxxxxx"]
  }
}

Doc generation

Code formatting and documentation for variables and outputs is generated using pre-commit-terraform hooks which uses terraform-docs.

Follow these instructions to install pre-commit locally.

And install terraform-docs with go get github.com/segmentio/terraform-docs or brew install terraform-docs.

Contributing

Report issues/questions/feature requests on in the issues section.

Requirements

Name Version
aws ~> 3.0

Providers

Name Version
aws ~> 3.0

Modules

No modules.

Resources

Name Type
aws_ecr_repository.this resource
aws_ecr_repository_policy.this resource
aws_ecs_cluster.this resource
aws_ecs_service.this resource
aws_ecs_task_definition.this resource
aws_iam_access_key.publisher resource
aws_iam_role.this resource
aws_iam_role_policy.this resource
aws_iam_user.publisher resource
aws_iam_user_policy.publisher resource
aws_lb.this resource
aws_lb_listener.this resource
aws_lb_target_group.this resource

Inputs

Name Description Type Default Required
addons Configuration of each addon that can be toggles on and off any {} no
aws_region AWS region string "eu-west-3" no
container Container configuration to deploy any {} no
ecr_values AWS ECR configuration any {} no
ecs_values AWS ECS configuration any {} no
lb_values AWS Load Balancer configuration any {} no
networking AWS networking configuration (subnet_ids, vpc_id)
object({
vpc_id = string
subnet_ids = list(string)
})
n/a yes

Outputs

Name Description
addons The Addons configuration
app_url The public ALB DNS
aws_region The AWS region used
container_name Container name for the ECS task
ecr_repository_name The ECR repository name
ecr_url The ECR repository URL
ecs_cluster The ECS cluster name
ecs_service The ECS service name
loadbalancer The AWS Load Balancer resources (loadbalancer, target_group and lb_listener)
publisher_access_key AWS_ACCESS_KEY to publish to ECR
publisher_secret_key AWS_SECRET_ACCESS_KEY to upload to the ECR