Skip to content

NamelessHH/tf_ecs_service

 
 

Repository files navigation

tf-ecs-service

a terraform module that manages an ECS service Note: You must have a working ECS cluster to use this module, it does not create the cluster for you.

Getting Started

Non-load balanced service

module "service" {
    source                = "git::git@github.com:charles-d-burton/tf_ecs_service?ref={version}"
    desired_count         = 1
    enable_log_forwarding = true
    filter_pattern        = ""
    logs_function_arn = "{arn_of_log_function}"
    logs_function_name = "{name_of_logging_function}"
    log_group_path = "/ecs/services/"
    region                = "${var.region}"
    service_name          = "my-service-${var.env}"
    container_definition = "${data.template_file.container_definition.rendered}"
    cluster_name = "${var.cluster_name}"
}

Load-balanced service

module "service" {
    source  = "git::git@github.com:charles-d-burton/tf_ecs_service?ref={version}"
    desired_count = 2
    enable_log_forwarding = true
    logs_function_arn = "{arn_of_log_function}"
    logs_function_name = "{name_of_logging_function}"
    log_group_path = "/ecs/services/"
    use_load_balancer = true
    alb_arn = "{arn_of_loadbalancer}"
    listner_port = 8080
    region = "${var.region}"
    container_definition = "${data.template_file.container_definition.rendered}"
    cluster_name = "${var.cluster_name}"
    enable_autoscaling = true
}

Variables

variable type description default
cluster_name string the name of the ecs cluster to attach services to
container_definition string json container definition array
region string aws region
service_name string name of ECS service
desired_count string baseline container count
task_policy_arn string arn of additional task policy
add_task_policy bool set to enable additional task policy false
enable_autoscaling bool set to enable application scaling false
scale_out_adjustment int number of containers to add for scaling 2
scale_in_adjustement int negative number of containers to remove -2
scale_in_cooldown int time window for autoscaling in 60
scale_out_cooldown int time window for autoscaling out 60
max_containers int maximum number of containers to scale to 20
use_load_balancer bool whether or not to enable load balancing false
alb_arn string arn of ALB to attach to
nlb_arn string arn of NLB to attach to
listener_port int port to assign to listener on LB
log_group_path string path for cloudwatch logging
enable_log_forwarding bool enable log forwarding to lambda false
log_forwarding_arn string arn of function to attach to log stream
log_forwarding_name string name of lambda function to forward logs
filter_pattern string log forwarding subscription filter pattern ""
max_log_retention int maximum time to keep logs in days 365
health_check_interval int time between health checks 30
health_check_path string path to health check "/"
health_check_port string port to container health check traffic_port
health_check_protocol string protocol for health check HTTP
health_check_timeout int seconds before health check timeout 5
health_check_healthy_threshold int number of checks for healthy status 5
health_check_unhealthy_threshold int number of failures for unhealthy status 2
health_check_matcher int http status code to match health check 200

Outputs

name type description
task_role_arn string arn of iam role used by ECS task
task_role_name string name of iam role used by ECS task
task_log_group_arn string arn of created log group

License

Apache V2

About

Terraform to create an ECS Service deployed in a cluster

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 100.0%