Cn Terraform Terraform Aws Ecs Fargate Save

AWS ECS Fargate Terraform Module

Project README

AWS ECS Fargate Terraform Module

This Terraform module deploys an AWS ECS Fargate service.

Usage

Check valid versions on:

Install pre commit hooks.

Please run this command right after cloning the repository.

    pre-commit install

For that you may need to install the folowwing tools:

In order to run all checks at any point run the following command:

    pre-commit run --all-files

Requirements

Name Version
terraform >= 0.13
aws >= 4

Providers

No providers.

Modules

Name Source Version
ecs-cluster cn-terraform/ecs-cluster/aws 1.0.10
ecs-fargate-service cn-terraform/ecs-fargate-service/aws 2.0.35
td cn-terraform/ecs-fargate-task-definition/aws 1.0.30

Resources

No resources.

Inputs

Name Description Type Default Required
additional_certificates_arn_for_https_listeners (Optional) List of SSL server certificate ARNs for HTTPS listener. Use it if you need to set additional certificates besides default_certificate_arn list(any) [] no
assign_public_ip (Optional) Assign a public IP address to the ENI (Fargate launch type only). If true service will be associated with public subnets. Default false. bool false no
block_s3_bucket_public_access (Optional) If true, public access to the S3 bucket will be blocked. bool true no
command The command that is passed to the container list(string) [] no
container_cpu (Optional) The number of cpu units to reserve for the container. This is optional for tasks using Fargate launch type and the total amount of container_cpu of all containers in a task will need to be lower than the task-level cpu value number 1024 no
container_definition Container definition overrides which allows for extra keys or overriding existing keys. map(any) {} no
container_depends_on The dependencies defined for container startup and shutdown. A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY
list(object({
containerName = string
condition = string
}))
[] no
container_image The image used to start the container. Images in the Docker Hub registry available by default string n/a yes
container_memory (Optional) The amount of memory (in MiB) to allow the container to use. This is a hard limit, if the container attempts to exceed the container_memory, the container is killed. This field is optional for Fargate launch type and the total amount of container_memory of all containers in a task will need to be lower than the task memory value number 4096 no
container_memory_reservation (Optional) The amount of memory (in MiB) to reserve for the container. If container needs to exceed this threshold, it can do so up to the set container_memory hard limit number 2048 no
container_name The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, _ allowed) string n/a yes
custom_lb_arn ARN of the Load Balancer to use in the ECS service. If provided, this module will not create a load balancer and will use the one provided in this variable string null no
default_certificate_arn (Optional) The ARN of the default SSL server certificate. Required if var.https_ports is set. string null no
deployment_maximum_percent (Optional) The upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. number 200 no
deployment_minimum_healthy_percent (Optional) The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. number 100 no
deployment_controller (Optional) Deployment controller. list(any) [] no
desired_count (Optional) The number of instances of the task definition to place and keep running. Defaults to 0. number 1 no
disable_networking When this parameter is true, networking is disabled within the container. bool null no
dns_search_domains Container DNS search domains. A list of DNS search domains that are presented to the container list(string) [] no
dns_servers Container DNS servers. This is a list of strings specifying the IP addresses of the DNS servers list(string) [] no
docker_labels The configuration options to send to the docker_labels map(string) null no
docker_security_options A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems. list(string) [] no
ecs_service_placement_constraints (Optional) rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10. This is a list of maps, where each map should contain "type" and "expression" list(any) [] no
ecs_service_security_groups (Optional) The security groups associated with the task or service. If you do not specify a security group, the default security group for the VPC is used. list(any) [] no
ecs_task_execution_role_custom_policies (Optional) Custom policies to attach to the ECS task execution role. For example for reading secrets from AWS Systems Manager Parameter Store or Secrets Manager list(string) [] no
enable_autoscaling (Optional) If true, autoscaling alarms will be created. bool true no
enable_ecs_managed_tags (Optional) Specifies whether to enable Amazon ECS managed tags for the tasks within the service. bool false no
enable_execute_command (Optional) Specifies whether to enable Amazon ECS Exec for the tasks within the service. bool false no
enable_module (Optional) Boolean variable to enable or disable the whole module. Defaults to true. bool true no
enable_s3_bucket_server_side_encryption (Optional) If true, server side encryption will be applied. bool true no
enable_s3_logs (Optional) If true, all resources to send LB logs to S3 will be created bool true no
entrypoint The entry point that is passed to the container list(string) [] no
environment The environment variables to pass to the container. This is a list of maps. map_environment overrides environment
list(object({
name = string
value = string
}))
[] no
environment_files One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps
list(object({
value = string
type = string
}))
[] no
ephemeral_storage_size The number of GBs to provision for ephemeral storage on Fargate tasks. Must be greater than or equal to 21 and less than or equal to 200 number 0 no
essential Determines whether all other containers in a task are stopped, if this container fails or stops for any reason. Due to how Terraform type casts booleans in json it is required to double quote this value bool true no
extra_hosts A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps
list(object({
ipAddress = string
hostname = string
}))
[] no
firelens_configuration The FireLens configuration for the container. This is used to specify and configure a log router for container logs. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html
object({
type = string
options = map(string)
})
null no
health_check_grace_period_seconds (Optional) Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 2147483647. Only valid for services configured to use load balancers. number 0 no
healthcheck (Optional) A map containing command (string), timeout, interval (duration in seconds), retries (1-10, number of times to retry before marking container unhealthy), and startPeriod (0-300, optional grace period to wait, in seconds, before failed healthchecks count toward retries)
object({
command = list(string)
retries = number
timeout = number
interval = number
startPeriod = number
})
null no
hostname The hostname to use for your container. string null no
interactive When this parameter is true, this allows you to deploy containerized applications that require stdin or a tty to be allocated. bool null no
lb_deregistration_delay (Optional) The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused. The range is 0-3600 seconds. The default value is 300 seconds. number 300 no
lb_drop_invalid_header_fields (Optional) Indicates whether HTTP headers with header fields that are not valid are removed by the load balancer (true) or routed to targets (false). The default is false. Elastic Load Balancing requires that message header names contain only alphanumeric characters and hyphens. bool false no
lb_enable_cross_zone_load_balancing (Optional) If true, cross-zone load balancing of the load balancer will be enabled. Defaults to false. bool false no
lb_enable_deletion_protection (Optional) If true, deletion of the load balancer will be disabled via the AWS API. This will prevent Terraform from deleting the load balancer. Defaults to false. bool false no
lb_enable_http2 (Optional) Indicates whether HTTP/2 is enabled in the load balancer. Defaults to true. bool true no
lb_http_ingress_cidr_blocks List of CIDR blocks to allowed to access the Load Balancer through HTTP list(string)
[
"0.0.0.0/0"
]
no
lb_http_ingress_prefix_list_ids List of prefix list IDs blocks to allowed to access the Load Balancer through HTTP list(string) [] no
lb_http_ports Map containing objects with two fields, listener_port and the target_group_port to redirect HTTP requests map(any)
{
"default_http": {
"listener_port": 80,
"target_group_port": 80
}
}
no
lb_https_ingress_cidr_blocks List of CIDR blocks to allowed to access the Load Balancer through HTTPS list(string)
[
"0.0.0.0/0"
]
no
lb_https_ingress_prefix_list_ids List of prefix list IDs blocks to allowed to access the Load Balancer through HTTPS list(string) [] no
lb_https_ports Map containing objects with two fields, listener_port and the target_group_port to redirect HTTPS requests map(any)
{
"default_http": {
"listener_port": 443,
"target_group_port": 443
}
}
no
lb_idle_timeout (Optional) The time in seconds that the connection is allowed to be idle. Default: 60. number 60 no
lb_internal (Optional) If true, the LB will be internal. bool false no
lb_ip_address_type (Optional) The type of IP addresses used by the subnets for your load balancer. The possible values are ipv4 and dualstack. Defaults to ipv4 string "ipv4" no
lb_load_balancing_algorithm_type (Optional) Determines how the load balancer selects targets when routing requests. The value is round_robin or least_outstanding_requests. The default is round_robin. string "round_robin" no
lb_security_groups (Optional) A list of security group IDs to assign to the LB. list(string) [] no
lb_slow_start (Optional) The amount time for targets to warm up before the load balancer sends them a full share of requests. The range is 30-900 seconds or 0 to disable. The default value is 0 seconds. number 0 no
lb_stickiness (Optional) A Stickiness block. Provide three fields. type, the type of sticky sessions. The only current possible value is lb_cookie. cookie_duration, the time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds). The default value is 1 day (86400 seconds). enabled, boolean to enable / disable stickiness. Default is true.
object({
type = string
cookie_duration = string
enabled = bool
})
{
"cookie_duration": 86400,
"enabled": true,
"type": "lb_cookie"
}
no
lb_target_group_health_check_enabled (Optional) Indicates whether health checks are enabled. Defaults to true. bool true no
lb_target_group_health_check_healthy_threshold (Optional) The number of consecutive health checks successes required before considering an unhealthy target healthy. Defaults to 3. number 3 no
lb_target_group_health_check_interval (Optional) The approximate amount of time, in seconds, between health checks of an individual target. Minimum value 5 seconds, Maximum value 300 seconds. Default 30 seconds. number 30 no
lb_target_group_health_check_matcher The HTTP codes to use when checking for a successful response from a target. You can specify multiple values (for example, "200,202") or a range of values (for example, "200-299"). Default is 200. string "200" no
lb_target_group_health_check_path The destination for the health check request. string "/" no
lb_target_group_health_check_timeout (Optional) The amount of time, in seconds, during which no response means a failed health check. The range is 2 to 120 seconds, and the default is 5 seconds. number 5 no
lb_target_group_health_check_unhealthy_threshold (Optional) The number of consecutive health check failures required before considering the target unhealthy. Defaults to 3. number 3 no
lb_waf_web_acl_arn ARN of a WAFV2 to associate with the ALB string "" no
links List of container names this container can communicate with without port mappings list(string) [] no
linux_parameters Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html
object({
capabilities = object({
add = list(string)
drop = list(string)
})
devices = list(object({
containerPath = string
hostPath = string
permissions = list(string)
}))
initProcessEnabled = bool
maxSwap = number
sharedMemorySize = number
swappiness = number
tmpfs = list(object({
containerPath = string
mountOptions = list(string)
size = number
}))
})
null no
log_configuration Log configuration options to send to a custom log driver for the container. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html any null no
map_environment The environment variables to pass to the container. This is a map of string: {key: value}. map_environment overrides environment map(string) null no
mount_points Container mount points. This is a list of maps, where each map should contain a containerPath and sourceVolume. The readOnly key is optional. list(any) [] no
name_prefix Name prefix for resources on AWS any n/a yes
ordered_placement_strategy (Optional) Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of ordered_placement_strategy blocks is 5. This is a list of maps where each map should contain "id" and "field" list(any) [] no
permissions_boundary (Optional) The ARN of the policy that is used to set the permissions boundary for the ecs_task_execution_role role. string null no
placement_constraints_task_definition (Optional) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10. This is a list of maps, where each map should contain "type" and "expression" list(any) [] no
platform_version (Optional) The platform version on which to run your service. Defaults to 1.4.0. More information about Fargate platform versions can be found in the AWS ECS User Guide. string "1.4.0" no
port_mappings The port mappings to configure for the container. This is a list of maps. Each map should contain "containerPort", "hostPort", and "protocol", where "protocol" is one of "tcp" or "udp". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort
list(object({
containerPort = number
hostPort = number
protocol = string
}))
[
{
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
]
no
private_subnets_ids The private subnets associated with the task or service. list(any) n/a yes
privileged When this variable is true, the container is given elevated privileges on the host container instance (similar to the root user). This parameter is not supported for Windows containers or tasks using the Fargate launch type. bool null no
propagate_tags (Optional) Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION. Default to SERVICE string "SERVICE" no
proxy_configuration (Optional) The proxy configuration details for the App Mesh proxy. This is a list of maps, where each map should contain "container_name", "properties" and "type" list(any) [] no
pseudo_terminal When this parameter is true, a TTY is allocated. bool null no
public_subnets_ids The public subnets associated with the task or service. list(any) n/a yes
readonly_root_filesystem Determines whether a container is given read-only access to its root filesystem. Due to how Terraform type casts booleans in json it is required to double quote this value bool false no
repository_credentials Container repository credentials; required when using a private repo. This map currently supports a single key; "credentialsParameter", which should be the ARN of a Secrets Manager's secret holding the credentials map(string) null no
s3_bucket_server_side_encryption_key (Optional) The AWS KMS master key ID used for the SSE-KMS encryption. This can only be used when you set the value of sse_algorithm as aws:kms. The default aws/s3 AWS KMS master key is used if this element is absent while the sse_algorithm is aws:kms. string null no
s3_bucket_server_side_encryption_sse_algorithm (Optional) The server-side encryption algorithm to use. Valid values are AES256 and aws:kms string "AES256" no
secrets The secrets to pass to the container. This is a list of maps
list(object({
name = string
valueFrom = string
}))
[] no
service_registries (Optional) The service discovery registries for the service. The maximum number of service_registries blocks is 1. This is a map that should contain the following fields "registry_arn", "port", "container_port" and "container_name" map(any) {} no
ssl_policy (Optional) The name of the SSL Policy for the listener. . Required if var.https_ports is set. string null no
start_timeout Time duration (in seconds) to wait before giving up on resolving dependencies for a container number null no
stop_timeout Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own number null no
system_controls A list of namespaced kernel parameters to set in the container, mapping to the --sysctl option to docker run. This is a list of maps: { namespace = "", value = ""} list(map(string)) [] no
tags Resource tags map(string) {} no
ulimits Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit"
list(object({
name = string
hardLimit = number
softLimit = number
}))
[] no
user The user to run as inside the container. Can be any of these formats: user, user:group, uid, uid:gid, user:gid, uid:group. The default (null) will use the container's configured USER directive or root if not set. string null no
volumes (Optional) A set of volume blocks that containers in your task may use
list(object({
host_path = string
name = string
docker_volume_configuration = list(object({
autoprovision = bool
driver = string
driver_opts = map(string)
labels = map(string)
scope = string
}))
efs_volume_configuration = list(object({
file_system_id = string
root_directory = string
transit_encryption = string
transit_encryption_port = string
authorization_config = list(object({
access_point_id = string
iam = string
}))
}))
}))
[] no
volumes_from A list of VolumesFrom maps which contain "sourceContainer" (name of the container that has the volumes to mount) and "readOnly" (whether the container can write to the volume)
list(object({
sourceContainer = string
readOnly = bool
}))
[] no
vpc_id ID of the VPC any n/a yes
working_directory The working directory to run commands inside the container string null no

Outputs

Name Description
aws_ecs_cluster_cluster_arn The Amazon Resource Name (ARN) that identifies the cluster
aws_ecs_cluster_cluster_id The Amazon ID that identifies the cluster
aws_ecs_cluster_cluster_name The name of the cluster
aws_ecs_service_service_cluster The Amazon Resource Name (ARN) of cluster which the service runs on.
aws_ecs_service_service_desired_count The number of instances of the task definition
aws_ecs_service_service_id The Amazon Resource Name (ARN) that identifies the service.
aws_ecs_service_service_name The name of the service.
aws_ecs_task_definition_td_arn Full ARN of the Task Definition (including both family and revision).
aws_ecs_task_definition_td_family The family of the Task Definition.
aws_ecs_task_definition_td_revision The revision of the task in a particular family.
aws_iam_role_ecs_task_execution_role_arn The Amazon Resource Name (ARN) specifying the role.
aws_iam_role_ecs_task_execution_role_create_date The creation date of the IAM role.
aws_iam_role_ecs_task_execution_role_description The description of the role.
aws_iam_role_ecs_task_execution_role_id The ID of the role.
aws_iam_role_ecs_task_execution_role_name The name of the role.
aws_iam_role_ecs_task_execution_role_unique_id The stable and unique string identifying the role.
aws_lb_lb_arn The ARN of the load balancer (matches id).
aws_lb_lb_arn_suffix The ARN suffix for use with CloudWatch Metrics.
aws_lb_lb_dns_name The DNS name of the load balancer.
aws_lb_lb_id The ARN of the load balancer (matches arn).
aws_lb_lb_zone_id The canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record).
aws_security_group_lb_access_sg_arn The ARN of the security group
aws_security_group_lb_access_sg_description The description of the security group
aws_security_group_lb_access_sg_egress The egress rules.
aws_security_group_lb_access_sg_id The ID of the security group
aws_security_group_lb_access_sg_ingress The ingress rules.
aws_security_group_lb_access_sg_name The name of the security group
aws_security_group_lb_access_sg_owner_id The owner ID.
aws_security_group_lb_access_sg_vpc_id The VPC ID.
container_name Name of the container
ecs_tasks_sg_arn ${var.name_prefix} ECS Tasks Security Group - The ARN of the security group
ecs_tasks_sg_description ${var.name_prefix} ECS Tasks Security Group - The description of the security group
ecs_tasks_sg_id ${var.name_prefix} ECS Tasks Security Group - The ID of the security group
ecs_tasks_sg_name ${var.name_prefix} ECS Tasks Security Group - The name of the security group
lb_http_listeners_arns List of HTTP Listeners ARNs
lb_http_listeners_ids List of HTTP Listeners IDs
lb_http_tgs_arns List of HTTP Target Groups ARNs
lb_http_tgs_ids List of HTTP Target Groups IDs
lb_http_tgs_names List of HTTP Target Groups Names
lb_https_listeners_arns List of HTTPS Listeners ARNs
lb_https_listeners_ids List of HTTPS Listeners IDs
lb_https_tgs_arns List of HTTPS Target Groups ARNs
lb_https_tgs_ids List of HTTPS Target Groups IDs
lb_https_tgs_names List of HTTPS Target Groups Names
Open Source Agenda is not affiliated with "Cn Terraform Terraform Aws Ecs Fargate" Project. README Source: cn-terraform/terraform-aws-ecs-fargate

Open Source Agenda Badge

Open Source Agenda Rating