Skip to content

Latest commit

 

History

History
113 lines (96 loc) · 11.1 KB

README.md

File metadata and controls

113 lines (96 loc) · 11.1 KB

AWS ECS Service Terraform Module

Terraform module to deploy an application to AWS ECS with support for EC2 or Fargate launch types, and autoscaling.

Usage

module "service" {
  source = "github.com/amberstarlight/terraform-aws-ecs-service"

  cluster_name = "ecs-cluster"
  service_name = "arch-builders"

  docker_image = "archlinux"
  docker_tag   = "base-devel"
}

Requirements

Name Version
terraform >= 1.0, <= 1.5.5
aws >= 5.0
random ~> 3

Providers

Name Version
aws 5.14.0

Modules

No modules.

Resources

Name Type
aws_appautoscaling_policy.this resource
aws_appautoscaling_target.this resource
aws_cloudwatch_log_group.this resource
aws_ecs_service.this resource
aws_ecs_task_definition.this resource
aws_iam_policy.exec resource
aws_iam_role.execution_role resource
aws_iam_role.task_role resource
aws_iam_role_policy_attachment.execution_role_additional_policies resource
aws_iam_role_policy_attachment.execution_role_policy resource
aws_iam_role_policy_attachment.task_role_additional_policies resource
aws_iam_role_policy_attachment.task_role_policy resource
aws_kms_key.this resource
aws_kms_key_policy.this resource
aws_service_discovery_service.this resource
aws_caller_identity.this data source
aws_cloudwatch_log_group.this data source
aws_ecs_cluster.this data source
aws_iam_policy_document.ecs_tasks_assume_role_policy data source
aws_iam_policy_document.exec data source
aws_region.this data source
aws_service_discovery_dns_namespace.this data source

Inputs

Name Description Type Default Required
assign_public_ip Whether to assign a public IP to this service. Defaults to false. bool false no
autoscaling_metrics A map of autoscaling metrics.
map(object({
metric_type = string
target_value = number
scale_in_cooldown = number
scale_out_cooldown = number
}))
{
"cpu": {
"metric_type": "ECSServiceAverageCPUUtilization",
"scale_in_cooldown": 300,
"scale_out_cooldown": 300,
"target_value": 75
},
"memory": {
"metric_type": "ECSServiceAverageMemoryUtilization",
"scale_in_cooldown": 300,
"scale_out_cooldown": 300,
"target_value": 75
}
}
no
cloudwatch_log_group_name CloudWatch log group to use with the service. string null no
cluster_name Name of the ECS Cluster to deploy the service into. string n/a yes
container_port Port the container should expose. number null no
cpu CPU limits for container. number 256 no
create_log_group Whether to create the CloudWatch log group. Defaults to true. bool true no
deployment_maximum_percent Maximum deployment as a percentage of service_count. Defaults to 200, for zero-downtime deployment. number 200 no
deployment_minimum_healthy_percent Minimum healthy percentage for a deployment. Defaults to 100, for zero-downtime deployment. number 100 no
docker_image Base docker image to use. string n/a yes
docker_tag Tag of the docker image to use. string n/a yes
enable_ecs_exec Whether to enable ECS Exec for the service. bool false no
enable_rollback Whether to enable circuit breaker rollbacks. Defaults to true. bool true no
entrypoint Entrypoint to be passed to the container. list(string) null no
execution_role_policy_arns A list of additional policy ARNs to attach to the service's execution role. list(string) [] no
fargate_version Fargate platform version to use. Defaults to LATEST. string "LATEST" no
healthcheck_grace_period Number of seconds to wait before starting healthchecks on the service. Defaults to 10. number 10 no
max_capacity A maximum capacity for autoscaling. number n/a yes
memory Memory limits for container. number 512 no
min_capacity A minimum capacity for autoscaling. Defaults to 1. number 1 no
network_mode Docker networking mode to use. One of awsvpc, bridge, host, or none. string "awsvpc" no
private_dns_namespace Private DNS namespace name. If provided, enables service discovery. string null no
security_groups A list of security group IDs to asssociate with the service. list(string) null no
service_count Number of replicas of the service to create. Defaults to 1. number 1 no
service_environment_config Service specific environment config list(map(string)) [] no
service_name Name of the service to create. string n/a yes
service_secrets_config Service specific environment secrets list(map(string)) [] no
skip_destroy Whether to retain the task definition revision when the resource is destroyed or replaced. Defaults to false. bool false no
subnet_ids Subnet IDs to place the service into. list(string) null no
tags A map of tags to apply to all resources in this module. map(string) {} no
target_group_arn ARN of the load balancer target group. string null no
task_role_policy_arns A list of additional policy ARNs to attach to the service's task role. list(string) [] no
timeout Timeout time for the ECS service to become stable before producing a Terraform error. string "15m" no
use_autoscaling Whether to use autoscaling for the service. Defaults to false. bool true no
use_fargate Whether to use Fargate to launch tasks. Disable to use EC2-backed ECS. bool true no
wait_for_steady_state Whether to wait for the service to become stable akin to aws ecs wait services-stable. Defaults to true. bool true no

Outputs

Name Description
task_execution_role_arn Task execution role ARN.
task_role_arn Task role ARN.