Skip to content

kk-rishang/terraform-aws-fargate

 
 

Repository files navigation

aws ecs fargate terraform module

Usage

For examples and refrences click here.

# quick usage look

# things to be created
# ecs service (memory scaling) >> TargetGroup >> Alb HTTPS rule >> Route53 >> app.example.com

module "fargate" {
  source  = "Rishang/fargate/aws"
  version = "1.4.0"

  EnvironmentName = "test"

  # ecs fargate
  cluster             = aws_ecs_cluster.app.name
  service             = "whoami"
  container_port      = 80
  task_definition_arn = module.fargate_task_definition.arn
  min_count           = 3
  
  fargate_spot        = true
  
  # default to true, only set force_spot to false
  # if you want to use mixed on-demand and spot instances 
  force_spot        = false

  # networking
  assign_public_ip = true
  vpc_id           = "vpc-demos7"
  subnets          = ["subnet-a2b3","subnet-c9da","subnet-0b23"]
  security_groups  = ["sg-f34d92"]

  # load balancer (optional)
  point_to_lb        = true
  listener_arn_https = aws_lb_listener.https.arn
  subdomain          = "app.example.com"

  # route53 (optional)
  point_to_r53 = true

  # autoscale (optional)
  memory_scale_target = 60
  # cpu_scale_target  = 60

  # service discovery (optional)
  enable_discovery = true
  namespace_id     = aws_service_discovery_private_dns_namespace.service.id

  tags = {
    Name         = "whoami"
    Version      = "latest"
    cluster_name = local.cluster_name
  }
}

Providers

Name Version
aws 4.8.0

Outputs

Name Description
cluster_name ecs fargate application cluster name.
discovery_arn application service discovery name. (if provided)
discovery_id application service discovery name. (if provided)
discovery_name application service discovery name. (if provided)
domain_id application route53 endpoint id. (if provided)
domain_name application service domain name. (if provided)
domain_type application route53 endpoint domain type eg. [A, CNAME]. (if provided)
id ecs fargate application service id.
name ecs fargate application service name.

available tfvar inputs

# null are required inputs,
# others are optional default values

EnvironmentName                    = null
assign_public_ip                   = false
cluster                            = null
container_name                     = ""
container_port                     = -1
cpu_scale_target                   = -1
deployment_maximum_percent         = 200
deployment_minimum_healthy_percent = 100
enable_discovery                   = false
enable_ecs_managed_tags            = false
fargate_spot                       = false
force_new_deployment               = false
force_spot                         = true
health_check_interval              = 20
health_check_matcher               = "200,202"
health_check_path                  = "/"
lb_scale_target                    = -1
listener_arn_https                 = ""
memory_scale_target                = -1
min_count                          = 1
namespace_id                       = ""
path_pattern                       = ["/", "/*"]
point_to_lb                        = false
point_to_r53                       = false
scale_in_cooldown                  = 250
scale_max_capacity                 = 20
scale_out_cooldown                 = 250
security_groups                    = []
service                            = null
subdomain                          = ""
subnets                            = null
tags                               = {}
task_definition_arn                = null
vpc_id                             = ""

Inputs

Name Description Type Default Required
EnvironmentName The name of the infra environment to deploy to eg. dev, prod, test string n/a yes
cluster The name of the cluster that hosts the service any n/a yes
service Fargate service name any n/a yes
subnets List of subnets for ecs service list(string) n/a yes
task_definition_arn The ARN of the task definition to use for the ECS service string n/a yes
assign_public_ip Auto assign public ip for ecs containers bool false no
container_name Required if service name is different than main application container_name of task defination string "" no
container_port container application port number -1 no
cpu_scale_target Treshold cpu target value for autoscaling ecs service number -1 no
deployment_maximum_percent Deployment max healthy percent of container count number 200 no
deployment_minimum_healthy_percent Deployment min healthy percent of container count number 100 no
enable_discovery Enable service discovery, requires namespace_id and container_name bool false no
enable_ecs_managed_tags Specifies whether to enable Amazon ECS managed tags for the service. bool false no
fargate_spot Whether to use fargate spot instances or not. bool false no
force_new_deployment Enable to force a new task deployment of the service bool false no
force_spot Set only fargate spot as Capacity provider. bool true no
health_check_interval target group health check interval time in sec number 20 no
health_check_matcher Service health check response matcher string "200,202" no
health_check_path Health check path for ecs running containers string "/" no
lb_scale_target Treshold target requests traffic value from alb, for autoscaling ecs service number -1 no
listener_arn_https HTTPS listner arn for Application Load Balencer (required if 'point_to_lb' is true) string "" no
memory_scale_target Treshold memory target value for autoscaling ecs service number -1 no
min_count Min count of containers number 1 no
namespace_id Namespace id (private) for service discovery, Note: discovery endpoint's subdomain will be same as service name string "" no
path_pattern List of paths for alb to route traffic at ecs target group list(string)
[
"/",
"/*"
]
no
point_to_lb Enable to point to ALB (load balancer) bool false no
point_to_r53 Enable to point to R53 bool false no
scale_in_cooldown The amount of time, in sec, after a scale in activity completes before another scale in activity can start. number 250 no
scale_max_capacity Max count of containers number 20 no
scale_out_cooldown The amount of time, in sec, after a scale out activity completes before another scale in activity can start. number 250 no
security_groups Extra security groups to attach to ecs service list(string) [] no
subdomain Subdomain name you want to give eg: test.example.com (required if 'point_to_r53' is true) string "" no
tags Tags to apply to the resources map(any) {} no
vpc_id aws vpc id string "" no

README.md created by: terraform-docs

Packages

No packages published

Languages

  • HCL 92.8%
  • Makefile 7.2%