Skip to content

Terraform module to provision an AWS ECS Fargate Cluster with an ALB.

License

Notifications You must be signed in to change notification settings

geekcell/terraform-aws-ecs-fargate-alb

Repository files navigation

Geek Cell GmbH

Inputs

Name Description Type Default Required
container_image Image to create task definition with. string "public.ecr.aws/docker/library/nginx:1.23-alpine" no
container_name Name of container to create task definition with. string "nginx" no
container_port Port to create task definition with. number 80 no
container_protocol Protocol to create task definition with. string "tcp" no
deployment_maximum_percent Maximum deployment percent. Usually double minimum to allow rolling deployment. number 200 no
deployment_minimum_healthy_percent Minimum deployment percent. Usually set to 100 to ensure at least one task. number 100 no
desired_count Number of desired Fargate tasks. number 1 no
enable_deletion_protection Enable delete protection on ALB. bool true no
enable_execute_command Allow execution commands on containers. bool true no
enable_http_to_https_redirect Enable port 80 redirect to 443. bool false no
enable_security_group Enable default security group. bool true no
enable_security_group_default_http_https_rule Enable default security group rules for port 80 & 443. bool true no
name Name to use for components. string n/a yes
tags Tags to add to the created resources. map(any) {} no
task_additional_execute_role_policies Additional policy ARNs to attach to the execution role. list(string) [] no
task_additional_task_role_policies Additional policy ARNs to attach to the task role. list(string) [] no
task_cpu Number of CPU units used by the task. number 1024 no
task_cpu_architecture CPU architecture required by the task. string "X86_64" no
task_definition_name Name of the task definition. Defaults to the base name. string null no
task_ephemeral_storage_size_in_gib The amount of ephemeral storage (in GiB) to allocate to the task. number 20 no
task_inference_accelerators List of Elastic Inference accelerators associated with the task.
list(object({
name = string
type = string
}))
[] no
task_memory Amount (in MiB) of memory used by the task. number 2048 no
task_operating_system_family OS family required by the task. string "LINUX" no
task_proxy_configuration Configuration details for an App Mesh proxy.
object({
container_name = string
properties = map(any)
type = optional(string, "APPMESH")
})
null no
task_volumes A list of volume definitions.
list(object({
name = string
host_path = string

docker_volume_configuration = optional(object({
autoprovision = bool
driver = string
driver_opts = map(any)
labels = map(any)
scope = string
}))

efs_volume_configuration = optional(object({
file_system_id = string
root_directory = optional(string)
transit_encryption = optional(string)
transit_encryption_port = optional(number)

authorization_config = optional(object({
access_point_id = string
iam = optional(string)
}))
}))
}))
[] no
vpc_id Id of VPC. string n/a yes
vpc_private_subnets Private subnets from VPC. list(string) n/a yes
vpc_public_subnets Public subnets from VPC. list(string) n/a yes

Outputs

Name Description
alb_dns_name Public address of ALB.
cluster_name Name of the ECS cluster.
ecr_repository_name Name of the ECR repository.
execution_role_arn ARN of the execution role.
execution_role_name Name of the execution role.
security_group_id Security group assigned to the service.
service_name Name of the ECS service.
task_role_arn ARN of the task role.
task_role_name Name of the task role.

Providers

Name Version
aws >= 4.36

Resources

  • resource.aws_cloudwatch_log_group.main (main.tf#179)
  • resource.aws_ecs_service.main (main.tf#144)
  • resource.aws_lb_listener.main (main.tf#43)
  • resource.aws_lb_target_group.main (main.tf#16)

Examples

Complete

module "basic-example" {
  source = "../../"

  name = var.name

  vpc_id              = var.vpc_id
  vpc_private_subnets = var.vpc_private_subnets
  vpc_public_subnets  = var.vpc_public_subnets

  container_port  = var.container_port
  container_name  = var.container_name
  container_image = var.container_image
}