Terraform module to create an ECS Service for a web app (task), and an ALB target group to route requests.
This project is part of our comprehensive "SweetOps" approach towards DevOps.
It's 100% Open Source and licensed under the APACHE2.
We literally have hundreds of terraform modules that are Open Source and well-maintained. Check them out!
For a complete example, see examples/complete
module "label" {
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=master"
namespace = "eg"
stage = "staging"
name = "app"
}
module "container_definition" {
source = "git::https://github.com/cloudposse/terraform-aws-ecs-container-definition.git?ref=master"
container_name = "app"
container_image = "cloudposse/geodesic:latest"
environment = [
{
name = "string_var"
value = "I am a string"
},
{
name = "true_boolean_var"
value = true
},
{
name = "false_boolean_var"
value = false
},
{
name = "integer_var"
value = 42
},
]
port_mappings = [
{
containerPort = 8080
hostPort = 80
protocol = "tcp"
},
{
containerPort = 8081
hostPort = 443
protocol = "udp"
},
]
}
module "alb_service_task" {
source = "git::https://github.com/cloudposse/terraform-aws-ecs-alb-service-task.git?ref=master"
namespace = "eg"
stage = "staging"
name = "app"
alb_target_group_arn = "xxxxxxx"
container_definition_json = "${module.container_definition.json}"
container_name = "${module.label.id}"
ecs_cluster_arn = "xxxxxxx"
launch_type = "FARGATE"
vpc_id = "xxxxxxx"
security_group_ids = ["xxxxx", "yyyyy"]
private_subnet_ids = ["xxxxx", "yyyyy", "zzzzz"]
}
The container_image
in the container_definition
module is the Docker image used to start a container.
This string is passed directly to the Docker daemon. Images in the Docker Hub registry are available by default.
Other repositories are specified with either repository-url/image:tag
or repository-url/image@digest
.
Up to 255 letters (uppercase and lowercase), numbers, hyphens, underscores, colons, periods, forward slashes, and number signs are allowed.
This parameter maps to Image in the Create a container section of the Docker Remote API and the IMAGE parameter of docker run
.
When a new task starts, the Amazon ECS container agent pulls the latest version of the specified image and tag for the container to use. However, subsequent updates to a repository image are not propagated to already running tasks.
Images in Amazon ECR repositories can be specified by either using the full registry/repository:tag
or registry/repository@digest
.
For example, 012345678910.dkr.ecr.<region-name>.amazonaws.com/<repository-name>:latest
or 012345678910.dkr.ecr.<region-name>.amazonaws.com/<repository-name>@sha256:94afd1f2e64d908bc90dbca0035a5b567EXAMPLE
.
Images in official repositories on Docker Hub use a single name (for example, ubuntu
or mongo
).
Images in other repositories on Docker Hub are qualified with an organization name (for example, amazon/amazon-ecs-agent
).
Images in other online repositories are qualified further by a domain name (for example, quay.io/assemblyline/ubuntu
).
For more info, see Container Definition.
Available targets:
help Help screen
help/all Display help for all targets
help/short This help short screen
Name | Description | Type | Default | Required |
---|---|---|---|---|
alb_target_group_arn | The ALB target group ARN for the ECS service | string | - | yes |
attributes | Additional attributes (e.g. 1 ) |
list | <list> |
no |
container_definition_json | The JSON of the task container definition | string | - | yes |
container_name | The name of the container in task definition to associate with the load balancer | string | - | yes |
container_port | The port on the container to associate with the load balancer | string | 80 |
no |
delimiter | Delimiter to be used between name , namespace , stage , etc. |
string | - |
no |
deployment_maximum_percent | The upper limit of the number of tasks (as a percentage of desired_count ) that can be running in a service during a deployment |
string | 200 |
no |
deployment_minimum_healthy_percent | The lower limit (as a percentage of desired_count ) of the number of tasks that must remain running and healthy in a service during a deployment |
string | 100 |
no |
desired_count | The number of instances of the task definition to place and keep running | string | 1 |
no |
ecs_cluster_arn | The ARN of the ECS cluster where service will be provisioned | string | - | yes |
launch_type | The launch type on which to run your service. Valid values are EC2 and FARGATE | string | FARGATE |
no |
name | Solution name, e.g. 'app' or 'cluster' | string | - | yes |
namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | - | yes |
network_mode | The network mode to use for the task. This is required to be awsvpc for FARGATE launch_type |
string | awsvpc |
no |
private_subnet_ids | Private subnet IDs | list | - | yes |
security_group_ids | Security group IDs to allow in Service network_configuration | list | - | yes |
stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | - | yes |
tags | Additional tags (e.g. map('BusinessUnit ,XYZ ) |
map | <map> |
no |
task_cpu | The number of CPU units used by the task. If using Fargate launch type task_cpu must match supported memory values (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_size) |
string | 256 |
no |
task_memory | The amount of memory (in MiB) used by the task. If using Fargate launch type task_memory must match supported cpu value (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_size) |
string | 512 |
no |
vpc_id | The VPC ID where resources are created | string | - | yes |
Name | Description |
---|---|
service_name | ECS Service name |
service_role_arn | ECS Service role ARN |
service_security_group_id | Security Group ID of the ECS task |
task_role_arn | ECS Task role ARN |
task_role_name | ECS Task role name |
Like this project? Please give it a ★ on our GitHub! (it helps us a lot)
Are you using this project or any of our other projects? Consider leaving a testimonial. =)
Check out these related projects.
- terraform-aws-alb - Terraform module to provision a standard ALB for HTTP/HTTP traffic
- terraform-aws-alb-ingress - Terraform module to provision an HTTP style ingress rule based on hostname and path for an ALB
- terraform-aws-codebuild - Terraform Module to easily leverage AWS CodeBuild for Continuous Integration
- terraform-aws-ecr - Terraform Module to manage Docker Container Registries on AWS ECR
- terraform-aws-ecs-web-app - Terraform module that implements a web app on ECS and supporting AWS resources
- terraform-aws-ecs-codepipeline - Terraform Module for CI/CD with AWS Code Pipeline and Code Build for ECS
- terraform-aws-ecs-cloudwatch-sns-alarms - Terraform module to create CloudWatch Alarms on ECS Service level metrics
- terraform-aws-ecs-container-definition - Terraform module to generate well-formed JSON documents that are passed to the aws_ecs_task_definition Terraform resource
- terraform-aws-lb-s3-bucket - Terraform module to provision an S3 bucket with built in IAM policy to allow AWS Load Balancers to ship access logs.
Got a question?
File a GitHub issue, send us an email or join our Slack Community.
Work directly with our team of DevOps experts via email, slack, and video conferencing.
We provide commercial support for all of our Open Source projects. As a Dedicated Support customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer.
- Questions. We'll use a Shared Slack channel between your team and ours.
- Troubleshooting. We'll help you triage why things aren't working.
- Code Reviews. We'll review your Pull Requests and provide constructive feedback.
- Bug Fixes. We'll rapidly work to fix any bugs in our projects.
- Build New Terraform Modules. We'll develop original modules to provision infrastructure.
- Cloud Architecture. We'll assist with your cloud strategy and design.
- Implementation. We'll provide hands-on support to implement our reference architectures.
Are you interested in custom Terraform module development? Submit your inquiry using our form today and we'll get back to you ASAP.
Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.
Signup for our newsletter that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
Please use the issue tracker to report any bugs or file feature requests.
If you are interested in being a contributor and want to get involved in developing this project or help out with our other projects, we would love to hear from you! Shoot us an email.
In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull Request so that we can review your changes
NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!
Copyright © 2017-2019 Cloud Posse, LLC
See LICENSE for full details.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
All other trademarks referenced herein are the property of their respective owners.
This project is maintained and funded by Cloud Posse, LLC. Like it? Please let us know by leaving a testimonial!
We're a DevOps Professional Services company based in Los Angeles, CA. We ❤️ Open Source Software.
We offer paid support on all of our projects.
Check out our other projects, follow us on twitter, apply for a job, or hire us to help with your cloud strategy and implementation.
Erik Osterman |
Igor Rodionov |
Andriy Knysh |
Sarkis Varozian |
---|