Skip to content

Latest commit

 

History

History
387 lines (258 loc) · 19.8 KB

File metadata and controls

387 lines (258 loc) · 19.8 KB

README Header

Cloud Posse

terraform-aws-ecs-alb-service-task Build Status Latest Release Slack Community

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.

Terraform Open Source Modules

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!

Usage

IMPORTANT: The master branch is used in source just as an example. In your code, do not pin to master because there may be breaking changes between releases. Instead pin to the release tag (e.g. ?ref=tags/x.y.z) of one of our latest releases.

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.

Makefile Targets

Available targets:

  help                                Help screen
  help/all                            Display help for all targets
  help/short                          This help short screen

Inputs

Name Description Type Default Required
alb_security_group Security group of the ALB string - yes
alb_target_group_arn The ALB target group ARN for the ECS service string - yes
assign_public_ip Assign a public IP address to the ENI (Fargate launch type only). Valid values are true or false. Default false. string false no
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_controller_type Type of deployment controller. Valid values: CODE_DEPLOY, ECS. string ECS 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
health_check_grace_period_seconds Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 7200. Only valid for services configured to use load balancers string 0 no
ignore_changes_task_definition Whether to ignore changes in container definition and task definition in the ECS service string true no
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
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
subnet_ids Subnet IDs list - 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
volumes Task volume definitions as list of maps list <list> no
vpc_id The VPC ID where resources are created string - yes

Outputs

Name Description
ecs_exec_role_policy_id The ECS service role policy ID, in the form of role_name:role_policy_name
ecs_exec_role_policy_name ECS service role name
service_name ECS Service name
service_role_arn ECS Service role ARN
service_security_group_id Security Group ID of the ECS task
task_definition_family ECS task definition family
task_definition_revision ECS task definition revision
task_exec_role_arn ECS Task exec role ARN
task_exec_role_name ECS Task role name
task_role_arn ECS Task role ARN
task_role_id ECS Task role id
task_role_name ECS Task role name

Share the Love

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. =)

Related Projects

Check out these related projects.

Help

Got a question?

File a GitHub issue, send us an email or join our Slack Community.

README Commercial Support

Commercial Support

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.

E-Mail

  • 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.

Terraform Module Development

Are you interested in custom Terraform module development? Submit your inquiry using our form today and we'll get back to you ASAP.

Slack Community

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.

Newsletter

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.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

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.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. 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

Copyright © 2017-2019 Cloud Posse, LLC

License

License

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.

Trademarks

All other trademarks referenced herein are the property of their respective owners.

About

This project is maintained and funded by Cloud Posse, LLC. Like it? Please let us know by leaving a testimonial!

Cloud Posse

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.

Contributors

Erik Osterman
Erik Osterman
Igor Rodionov
Igor Rodionov
Andriy Knysh
Andriy Knysh
Sarkis Varozian
Sarkis Varozian

README Footer Beacon