{"id":21202502,"url":"https://github.com/infrablocks/terraform-aws-ecs-service","last_synced_at":"2025-07-10T06:33:03.008Z","repository":{"id":17536425,"uuid":"82189330","full_name":"infrablocks/terraform-aws-ecs-service","owner":"infrablocks","description":"Terraform module for deploying a service to an existing ECS cluster in AWS","archived":false,"fork":false,"pushed_at":"2024-10-28T02:32:19.000Z","size":820,"stargazers_count":36,"open_issues_count":2,"forks_count":20,"subscribers_count":15,"default_branch":"main","last_synced_at":"2024-10-28T06:16:11.737Z","etag":null,"topics":["ecs","ecs-cluster","ecs-service","infrastructure","terraform","terraform-modules"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/infrablocks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security_groups.tf","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-16T14:28:53.000Z","updated_at":"2024-10-28T02:32:21.000Z","dependencies_parsed_at":"2023-12-12T03:29:07.863Z","dependency_job_id":"213b2080-3d57-477a-83ae-89974a2606d7","html_url":"https://github.com/infrablocks/terraform-aws-ecs-service","commit_stats":null,"previous_names":[],"tags_count":91,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infrablocks","download_url":"https://codeload.github.com/infrablocks/terraform-aws-ecs-service/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225622825,"owners_count":17498170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecs","ecs-cluster","ecs-service","infrastructure","terraform","terraform-modules"],"created_at":"2024-11-20T20:16:20.015Z","updated_at":"2024-11-20T20:16:20.632Z","avatar_url":"https://github.com/infrablocks.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Terraform AWS ECS Service\n=========================\n\n[![CircleCI](https://circleci.com/gh/infrablocks/terraform-aws-ecs-service.svg?style=svg)](https://circleci.com/gh/infrablocks/terraform-aws-ecs-service)\n\nA Terraform module for deploying an ECS service in AWS.\n\nThe ECS service requires:\n* An existing VPC containing an ECS cluster\n* A service role ARN allowing ECS to manage load balancers\n* An ELB for the service\n* A CloudWatch log group\n\nThe ECS service consists of:\n* An ECS task definition for the containers making up the service\n* An ECS service to maintain a number of instances of the task\n* Log collection via the provided CloudWatch log group\n\n![Diagram of infrastructure managed by this module](https://raw.githubusercontent.com/infrablocks/terraform-aws-ecs-service/main/docs/architecture.png)\n\nUsage\n-----\n\nTo use the module, include something like the following in your Terraform\nconfiguration:\n\n```hcl-terraform\nmodule \"ecs_service\" {\n  source = \"infrablocks/ecs-service/aws\"\n  version = \"2.0.0\"\n\n  vpc_id = \"vpc-fb7dc365\"\n\n  component = \"important-component\"\n  deployment_identifier = \"production\"\n\n  service_name = \"web-app\"\n  service_image = \"images/web-app:0.3.1\"\n  service_port = \"8000\"\n  service_command = \"[\\\"node\\\", \\\"server.js\\\"]\"\n\n  service_desired_count = \"3\"\n  service_deployment_maximum_percent = \"50\"\n  service_deployment_minimum_healthy_percent = \"200\"\n\n  service_elb_name = \"elb-service-web-app\"\n\n  service_role = \"arn:aws:iam::151388205202:role/service-task-role\"\n\n  service_volumes = [\n    {\n      name = \"data\"\n    }\n  ]\n\n  ecs_cluster_id = \"arn:aws:ecs:eu-west-2:151388205202:cluster/web-app\"\n  ecs_cluster_service_role_arn = \"arn:aws:iam::151388205202:role/cluster-service-role-web-app\"\n}\n```\n\nBy default, the module will use the provided region, log group, service name,\nimage, port and command to build a suitable task definition. Set `service_use_latest_task_definition = true` to use the latest active revision.\n\nIf further configuration of the task definition is required, provide the task\ndefinition content using the var `service_task_definition`. In this case,\n`service_image` and `service_command` need not be provided.\n\nAs mentioned above, the ECS service deploys into an existing base network and\nECS cluster using an existing ELB. Whilst these can be created using any\nmechanism you like, the following modules may be of use:\n* [AWS Base Networking](https://github.com/infrablocks/terraform-aws-base-networking)\n* [AWS ECS Cluster](https://github.com/infrablocks/terraform-aws-ecs-cluster)\n* [AWS ECS Load Balancer](https://github.com/infrablocks/terraform-aws-ecs-load-balancer)\n\nSee the\n[Terraform registry entry](https://registry.terraform.io/modules/infrablocks/ecs-service/aws/latest)\nfor more details.\n\n### Inputs\n\n| Name                                       | Description                                                                  | Default                   | Required                                                                |\n|--------------------------------------------|------------------------------------------------------------------------------|:-------------------------:|:-----------------------------------------------------------------------:|\n| region                                     | The region into which to deploy the service                                  | -                         | yes                                                                     |\n| vpc_id                                     | The ID of the VPC into which to deploy the service                           | -                         | yes                                                                     |\n| component                                  | The component this service will contain                                      | -                         | yes                                                                     |\n| deployment_identifier                      | An identifier for this instantiation                                         | -                         | yes                                                                     |\n| service_task_container_definitions         | A template for the container definitions in the task                         | see container-definitions | no                                                                      |\n| service_use_latest_task_definition         | if true use the latest ACTIVE revision of the task definition                | false                     | no                                                                      |\n| service_name                               | The name of the service being created                                        | -                         | yes                                                                     |\n| service_image                              | The docker image (including version) to deploy                               | -                         | no                                                                      |\n| service_command                            | The command to run to start the container                                    | []                        | no                                                                      |\n| service_port                               | The port the containers will be listening on                                 | -                         | yes                                                                     |\n| service_task_network_mode                  | The network mode used for the containers in the task                         | bridge                    | yes                                                                     |\n| service_desired_count                      | The desired number of tasks in the service                                   | 3                         | yes                                                                     |\n| service_deployment_maximum_percent         | The maximum percentage of the desired count that can be running              | 200                       | yes                                                                     |\n| service_deployment_minimum_healthy_percent | The minimum healthy percentage of the desired count to keep running          | 50                        | yes                                                                     |\n| scheduling_strategy                        | The scheduling strategy to use for the service (\"REPLICA\" or \"DAEMON\")       | \"REPLICA\"                 | yes                                                                     |\n| attach_to_load_balancer                    | Whether or not this service should attach to a load balancer (\"yes\" or \"no\") | \"yes\"                     | yes                                                                     |\n| service_elb_name                           | The name of the ELB to configure to point at the service containers          | -                         | if attach_to_load_balancer is yes and target_group_arn is not specified |\n| target_group_arn                           | The ARN of the ALB's target group to point at the service containers         | -                         | if attach_to_load_balancer is yes and service_elb_name is not specified |\n| service_role                               | The ARN of the service task role to use                                      | No task role              | yes                                                                     |\n| service_volumes                            | A list of volumes to make available to the containers in the service         | []                        | yes                                                                     |\n| ecs_cluster_id                             | The ID of the ECS cluster in which to deploy the service                     | -                         | yes                                                                     |\n| ecs_cluster_service_role_arn               | The ARN of the IAM role to provide to ECS to manage the service              | -                         | yes                                                                     |\n\n\n### Outputs\n\n| Name                | Description                                         |\n|---------------------|-----------------------------------------------------|\n| task_definition_arn | The ARN of the created ECS task definition          |\n| log_group           | The name of the log group capturing all task output |\n\n### Compatibility\n\nThis module is compatible with Terraform 1.1 and higher and requires Terraform AWS provider version 4.59 or higher.\n\nDevelopment\n-----------\n\n### Machine Requirements\n\nIn order for the build to run correctly, a few tools will need to be installed\non your development machine:\n\n* Ruby (3.1.1)\n* Bundler\n* git\n* git-crypt\n* gnupg\n* direnv\n* aws-vault\n\n#### Mac OS X Setup\n\nInstalling the required tools is best managed by [homebrew](http://brew.sh).\n\nTo install homebrew:\n\n```\nruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"\n```\n\nThen, to install the required tools:\n\n```\n# ruby\nbrew install rbenv\nbrew install ruby-build\necho 'eval \"$(rbenv init - bash)\"' \u003e\u003e ~/.bash_profile\necho 'eval \"$(rbenv init - zsh)\"' \u003e\u003e ~/.zshrc\neval \"$(rbenv init -)\"\nrbenv install 3.1.1\nrbenv rehash\nrbenv local 3.1.1\ngem install bundler\n\n# git, git-crypt, gnupg\nbrew install git\nbrew install git-crypt\nbrew install gnupg\n\n# aws-vault\nbrew cask install\n\n# direnv\nbrew install direnv\necho \"$(direnv hook bash)\" \u003e\u003e ~/.bash_profile\necho \"$(direnv hook zsh)\" \u003e\u003e ~/.zshrc\neval \"$(direnv hook $SHELL)\"\n\ndirenv allow \u003crepository-directory\u003e\n```\n\n### Running the build\n\nRunning the build requires an AWS account and AWS credentials. You are free to\nconfigure credentials however you like as long as an access key ID and secret\naccess key are available. These instructions utilise\n[aws-vault](https://github.com/99designs/aws-vault) which makes credential\nmanagement easy and secure.\n\nTo provision module infrastructure, run tests and then destroy that\ninfrastructure, execute:\n\n```bash\naws-vault exec \u003cprofile\u003e -- ./go\n```\n\nTo provision the module prerequisites:\n\n```bash\naws-vault exec \u003cprofile\u003e -- ./go deployment:prerequisites:provision[\u003cdeployment_identifier\u003e]\n```\n\nTo provision the module contents:\n\n```bash\naws-vault exec \u003cprofile\u003e -- ./go deployment:root:provision[\u003cdeployment_identifier\u003e]\n```\n\nTo destroy the module contents:\n\n```bash\naws-vault exec \u003cprofile\u003e -- ./go deployment:root:destroy[\u003cdeployment_identifier\u003e]\n```\n\nTo destroy the module prerequisites:\n\n```bash\naws-vault exec \u003cprofile\u003e -- ./go deployment:prerequisites:destroy[\u003cdeployment_identifier\u003e]\n```\n\nConfiguration parameters can be overridden via environment variables:\n\n```bash\nDEPLOYMENT_IDENTIFIER=testing aws-vault exec \u003cprofile\u003e -- ./go\n```\n\n\n### Common Tasks\n\n#### Generating an SSH key pair\n\nTo generate an SSH key pair:\n\n```\nssh-keygen -m PEM -t rsa -b 4096 -C integration-test@example.com -N '' -f config/secrets/keys/bastion/ssh\n```\n\n#### Generating a self-signed certificate\n\nTo generate a self signed certificate:\n```\nopenssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365\n```\n\nTo decrypt the resulting key:\n\n```\nopenssl rsa -in key.pem -out ssl.key\n```\n\n#### Managing CircleCI keys\n\nTo encrypt a GPG key for use by CircleCI:\n\n```bash\nopenssl aes-256-cbc \\\n  -e \\\n  -md sha1 \\\n  -in ./config/secrets/ci/gpg.private \\\n  -out ./.circleci/gpg.private.enc \\\n  -k \"\u003cpassphrase\u003e\"\n```\n\nTo check decryption is working correctly:\n\n```bash\nopenssl aes-256-cbc \\\n  -d \\\n  -md sha1 \\\n  -in ./.circleci/gpg.private.enc \\\n  -k \"\u003cpassphrase\u003e\"\n```\n\nContributing\n------------\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/infrablocks/terraform-aws-ecs-service. This project is\nintended to be a safe, welcoming space for collaboration, and contributors are\nexpected to adhere to the\n[Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\nLicense\n-------\n\nThe library is available as open source under the terms of the\n[MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfrablocks%2Fterraform-aws-ecs-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfrablocks%2Fterraform-aws-ecs-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfrablocks%2Fterraform-aws-ecs-service/lists"}