Skip to content

launchbynttdata/tf-aws-module_primitive-ecs_service

Repository files navigation

tf-aws-module_primitive-ecs_service

This module provides a primitive Terraform module for creating an Amazon ECS service with support for various configurations including load balancers, service discovery, and more.

Features

  • Supports Fargate and EC2 launch types
  • Configurable network settings with subnets and security groups
  • Load balancer integration
  • Service Connect for service-to-service communication
  • Service discovery registries
  • Capacity provider strategies
  • Deployment configurations with circuit breakers and alarms
  • Volume configurations for EBS attachments
  • ECS Exec support
  • Comprehensive tagging and managed tags

Usage

module "ecs_service" {
  source = "path/to/module"

  name            = "my-ecs-service"
  cluster         = aws_ecs_cluster.example.arn
  task_definition = aws_ecs_task_definition.example.arn

  desired_count = 2
  launch_type   = "FARGATE"

  network_configuration = {
    subnets          = [aws_subnet.example.id]
    security_groups  = [aws_security_group.example.id]
    assign_public_ip = false
  }

  tags = {
    Environment = "dev"
  }
}

Resources Created

  • 1 ECS Service
  • 1 Service Discovery Service (data source, if Service Connect lookup is configured)

Requirements

Name Version
terraform >= 1.0
aws ~> 5.0

Modules

No modules.

Resources

Name Type
aws_ecs_service.this resource
aws_service_discovery_service.service_connect data source

Inputs

Name Description Type Default Required
name Name for the ECS service string n/a yes
tags A map of tags to add to the ECS service map(string) {} no
cluster ARN of the ECS cluster where this service will be placed string n/a yes
task_definition The family and revision (family:revision) or full ARN of the task definition to run in your service string n/a yes
desired_count The number of instances of the task definition to place and keep running number 1 no
launch_type The launch type on which to run your service. Valid values: EC2, FARGATE, EXTERNAL string "FARGATE" no
platform_version The platform version on which to run your service. Only applicable for launch_type set to FARGATE string "LATEST" no
iam_role The ARN of an IAM role that allows your Amazon ECS service to make calls to other AWS services string null no
enable_execute_command Whether to enable Amazon ECS Exec for the tasks in the service bool false no
enable_ecs_managed_tags Whether to enable Amazon ECS managed tags for the tasks in the service bool false no
propagate_tags Whether to propagate the tags from the task definition or the service to the tasks string "SERVICE" no
health_check_grace_period_seconds Health check grace period in seconds for the service when using load balancers number null no
wait_for_steady_state Whether to wait for the service to reach a steady state before continuing bool false no
force_new_deployment Whether to force a new task deployment of the service bool false no
network_configuration Network configuration for the ECS service
object({
subnets = list(string)
security_groups = list(string)
assign_public_ip = optional(bool, false)
})
null no
load_balancer Load balancer configuration for the service
list(object({
target_group_arn = string
container_name = string
container_port = number
}))
[] no
service_connect_configuration Service Connect configuration for the service
object({
enabled = bool
namespace = optional(string)
log_configuration = optional(object({
log_driver = string
options = map(string)
}))
service = optional(object({
client_alias = object({
dns_name = string
port = number
})
discovery_name = string
port_name = string
tls = optional(object({
issuer_cert_authority = object({
aws_pca_authority_arn = string
})
kms_key = optional(string)
role_arn = optional(string)
}))
}))
})
null no
service_registries Service discovery registries for the service
list(object({
registry_arn = string
port = optional(number)
container_name = optional(string)
container_port = optional(number)
}))
[] no
service_connect_registry_arn ARN of the Service Connect service to register in service registries for external discovery string null no
service_connect_registry_port Port value for the Service Connect service registry entry number null no
service_connect_registry_container_name Container name for the Service Connect service registry entry string null no
service_connect_registry_container_port Container port for the Service Connect service registry entry number null no
service_connect_discovery_name Discovery name of the Service Connect service to lookup (should match service.discovery_name in service_connect_configuration) string null no
service_connect_namespace_id Namespace ID for Service Connect service discovery lookup string null no
capacity_provider_strategy Capacity provider strategy to use for the service
list(object({
capacity_provider = string
weight = number
base = optional(number, 0)
}))
[] no
deployment_configuration Deployment configuration for the service
object({
maximum_percent = optional(number, 200)
minimum_healthy_percent = optional(number, 100)
deployment_circuit_breaker = optional(object({
enable = bool
rollback = bool
}))
alarms = optional(object({
alarm_names = list(string)
enable = bool
rollback = bool
}))
deployment_attempts = optional(number, 2)
})
{
"maximum_percent": 200,
"minimum_healthy_percent": 100
}
no
placement_constraints Placement constraints for the service
list(object({
type = string
expression = optional(string)
}))
[] no
ordered_placement_strategy Placement strategy for the service
list(object({
type = string
field = optional(string)
}))
[] no
volume_configuration Configuration for EBS volumes that are attached to tasks
object({
name = string
managed_ebs_volume = object({
role_arn = string
encrypted = optional(bool, true)
file_system_type = optional(string, "ext4")
iops = optional(number)
kms_key_id = optional(string)
size_in_gb = optional(number, 20)
snapshot_id = optional(string)
throughput = optional(number)
volume_type = optional(string, "gp3")
tag_specifications = optional(list(object({
resource_type = string
tags = map(string)
})), [])
})
})
null no

Outputs

Name Description
id The ID of the ECS service
name The name of the ECS service
cluster The cluster the ECS service is associated with
desired_count The desired number of tasks for the ECS service
task_definition The task definition ARN used by the ECS service
launch_type The launch type of the ECS service
platform_version The platform version of the ECS service
deployment_configuration The deployment configuration of the ECS service
network_configuration The network configuration of the ECS service
load_balancer_configuration The load balancer configuration of the ECS service
service_connect_configuration The service connect configuration of the ECS service
service_registries The effective service registries configuration of the ECS service (includes Service Connect registry if configured)
service_connect_service_arn ARN of the Service Connect service discovered via data source (if lookup is configured)
service_connect_service_discovery_name Discovery name of the Service Connect service (from configuration)
capacity_provider_strategy The capacity provider strategy of the ECS service
placement_constraints The placement constraints of the ECS service
placement_strategy The placement strategy of the ECS service
volume_configuration The volume configuration of the ECS service
enable_execute_command Whether ECS Exec is enabled for the service
enable_ecs_managed_tags Whether ECS managed tags are enabled for the service
propagate_tags How tags are propagated to tasks
tags A map of tags assigned to the ECS service
tags_all A map of tags assigned to the resource, including provider default_tags
service_details Comprehensive details about the ECS service for integration purposes
service_configuration Summary of the ECS service configuration

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5