Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Module for creating ECS cluster (Linux/Windows) solely for EC2 launch type • This repository is defined and managed in Terraform

License

Notifications You must be signed in to change notification settings

ministryofjustice/modernisation-platform-terraform-ecs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modernisation Platform ECS Cluster Module

repo standards badge

Usage

module "ecs" {

  source = "github.com/ministryofjustice/modernisation-platform-terraform-ecs/ecs"

  subnet_set_name          = local.subnet_set_name
  vpc_id                   = local.vpc_id
  app_name                 = local.application_name
  container_instance_type  = local.app_data.accounts[local.environment].container_instance_type
  environment              = local.environment
  ami_image_id             = local.app_data.accounts[local.environment].ami_image_id
  instance_type            = local.app_data.accounts[local.environment].instance_type
  user_data                = base64encode(data.template_file.launch-template.rendered)
  key_name                 = local.app_data.accounts[local.environment].key_name
  task_definition          = data.template_file.task_definition.rendered
  ec2_desired_capacity     = local.app_data.accounts[local.environment].ec2_desired_capacity
  ec2_max_size             = local.app_data.accounts[local.environment].ec2_max_size
  ec2_min_size             = local.app_data.accounts[local.environment].ec2_min_size
  container_cpu            = local.app_data.accounts[local.environment].container_cpu
  container_memory         = local.app_data.accounts[local.environment].container_memory
  task_definition_volume   = local.app_data.accounts[local.environment].task_definition_volume
  network_mode             = local.app_data.accounts[local.environment].network_mode
  server_port              = local.app_data.accounts[local.environment].server_port
  app_count                = local.app_data.accounts[local.environment].app_count
  public_cidrs             = [data.aws_subnet.public_az_a.cidr_block, data.aws_subnet.public_az_b.cidr_block, data.aws_subnet.public_az_c.cidr_block]
  tags_common              = local.tags

  depends_on               = [aws_ecr_repository.ecr_repo, aws_lb_listener.listener]
}

Requirements

Name Version
terraform >= 1.0.1
aws ~> 4.0

Providers

Name Version
aws ~> 4.0

Modules

No modules.

Resources

Name Type
aws_appautoscaling_policy.scaling_policy_down resource
aws_appautoscaling_policy.scaling_policy_up resource
aws_appautoscaling_target.scaling_target resource
aws_autoscaling_group.cluster-scaling-group resource
aws_cloudwatch_log_group.cloudwatch_group resource
aws_cloudwatch_log_stream.cloudwatch_stream resource
aws_ecs_capacity_provider.capacity_provider resource
aws_ecs_cluster.ecs_cluster resource
aws_ecs_cluster_capacity_providers.ecs_cluster resource
aws_ecs_service.ecs_service resource
aws_ecs_task_definition.linux_ecs_task_definition resource
aws_ecs_task_definition.windows_ecs_task_definition resource
aws_iam_instance_profile.ec2_instance_profile resource
aws_iam_policy.ec2_instance_policy resource
aws_iam_policy.ecs_task_execution_s3_policy resource
aws_iam_role.ec2_instance_role resource
aws_iam_role.ecs_task_execution_role resource
aws_iam_role_policy_attachment.attach_ec2_policy resource
aws_iam_role_policy_attachment.ecs_task_execution_role resource
aws_iam_role_policy_attachment.ecs_task_s3_access resource
aws_iam_role_policy_attachment.ecs_task_secrets_manager resource
aws_launch_template.ec2-launch-template resource
aws_security_group.cluster_ec2 resource
aws_ecs_task_definition.task_definition data source
aws_iam_policy_document.ecs_task_execution_role data source
aws_lb_target_group.target_group data source
aws_subnets.shared-private data source

Inputs

Name Description Type Default Required
ami_image_id EC2 AMI image to run in the ECS cluster string n/a yes
app_count Number of docker containers to run string n/a yes
app_name Name of the application string n/a yes
appscaling_max_capacity Maximum capacity of the application scaling target number 3 no
appscaling_min_capacity Minimum capacity of the application scaling target number 1 no
container_cpu Container instance CPU units to provision (1 vCPU = 1024 CPU units) string n/a yes
container_instance_type Container OS being used (windows or linux) string n/a yes
container_memory Container instance memory to provision (in MiB) string n/a yes
ec2_desired_capacity Number of EC2s in the cluster string n/a yes
ec2_egress_rules Security group egress rules for the cluster EC2s
map(object({
description = string
from_port = number
to_port = number
protocol = string
security_groups = list(string)
cidr_blocks = list(string)
}))
n/a yes
ec2_ingress_rules Security group ingress rules for the cluster EC2s
map(object({
description = string
from_port = number
to_port = number
protocol = string
security_groups = list(string)
cidr_blocks = list(string)
}))
n/a yes
ec2_max_size Max Number of EC2s in the cluster string n/a yes
ec2_min_size Min Number of EC2s in the cluster string n/a yes
instance_type EC2 instance type to run in the ECS cluster string n/a yes
key_name Key to access EC2s in ECS cluster string n/a yes
lb_tg_name Load balancer target group name used by ECS service string n/a yes
network_mode The network mode used for the containers in the task. If OS used is Windows network_mode must equal none. string n/a yes
server_port The port the containers will be listening on string n/a yes
subnet_set_name The name of the subnet set associated with the account string n/a yes
tags_common Common tags to be used by all resources map(string) n/a yes
task_definition Task definition to be used by the ECS service string n/a yes
task_definition_volume Name of the volume referenced in the sourceVolume parameter of container definition in the mountPoints section string n/a yes
user_data The configuration used when creating EC2s used for the ECS cluster string n/a yes
vpc_id The ID of the VPC used to create resources string n/a yes

Outputs

Name Description
app_scale_down_policy_arn ARN for app autoscaling - scaling policy down
app_scale_up_policy_arn ARN for app autoscaling - scaling policy up
cluster_ec2_security_group_id Security group id of EC2s used for ECS cluster
current_task_definition Displays task definition information and version being used
ec2_autoscaling_group Autoscaling group information
ecs_service Displays task definition information and version being used
ecs_task_execution_policy Displays task definition policy details
ecs_task_execution_role Displays task definition role details

Looking for issues?

If you're looking to raise an issue with this module, please create a new issue in the Modernisation Platform repository.