Skip to content

bryan-rhm/terraform-aws-ecs-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform AWS ECS Service Module

This terraform module provisions an ECS service.

Usage

Example on how to provision an AWS ECS Service with FARGATE SPOT containers.

module "ecs_service" {
  source                     = "bryan-rhm/ecs-service/aws"
  version                    = "..." # select your prefered version
  name                       = "service-name"
  cluster_arn                = module.ecs_cluster.output.arn
  task_definition_arn        = module.ecs_task_definition.output.arn
  desired_count              = 2
  propagate_tags             = "TASK_DEFINITION"
  launch_type                = "FARGATE"
  deployment_maximum_percent = 200
  deployment_minimum_percent = 100

  network_config = {
    subnets         = module.vpc.output.private_subnet_ids
    security_groups = ["sg-id-1234"]
  }

  capacity_provider_strategy = [{
    base   = 2
    name   = "FARGATE_SPOT"
    weight = 1
  }]

  load_balancer = {
    target_group_arn = module.alb_target_group.output.arn
    container_name   = "container-name"
    container_port   = 8080
  }
}

Requirements

Name Version
terraform >= 1.0.4
aws >= 3.43.0

Providers

Name Version
aws 3.70.0

Modules

No modules.

Resources

Name Type
aws_ecs_service.this resource

Inputs

Name Description Type Default Required
capacity_provider_strategy (Optional) Capacity provider strategies to use for the service. Can be one or more. These can be updated without destroying and recreating the service only if force_new_deployment = true and not changing from 0 capacity_provider_strategy blocks to greater than 0, or vice versa.
list(object({
base = number
name = string
weight = number
}))
[] no
cluster_arn ARN of the ECS cluster on which to run the service. If a cluster is not specified, the default cluster is assumed. string null no
deployment_maximum_percent (Optional) Upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. Not valid when using the DAEMON scheduling strategy. number 200 no
deployment_minimum_percent (Optional) Lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. number 100 no
desired_count Number of instances of the task definition to place and keep running. number 0 no
enable_execute_command (Optional) Specifies whether to enable Amazon ECS Exec for the tasks within the service. bool true no
health_check_grace_period Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 2147483647. Only valid for services configured to use load balancers. number 10 no
launch_type Launch type on which to run your service. The valid values are EC2, FARGATE, and EXTERNAL. string "FARGATE" no
load_balancer Details of the load balancer to be associated to the service.
object({
target_group_arn = string
container_name = string
container_port = number
})
null no
name Name to give to the ECS Service. string n/a yes
network_config Network configuration for the service.
object({
subnets = list(string)
security_groups = list(string)
assign_public_ip = optional(bool)
})
null no
propagate_tags Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION. string "TASK_DEFINITION" no
service_registry The details of the service discovery registry to associate with this service.
object({
arn = string
port = optional(number)
container_port = optional(number)
container_name = optional(string)
})
null no
tags A map of tags to assign to the target group. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level. map(any) null no
task_definition_arn Family and revision (family:revision) or full ARN of the task definition to be run in the service. Required unless using the EXTERNAL deployment controller. If a revision is not specified, the latest ACTIVE revision is used. string null no

Outputs

Name Description
output ECS service attributes