{"id":21202461,"url":"https://github.com/infrablocks/terraform-aws-ecs-cluster","last_synced_at":"2026-03-16T20:32:30.351Z","repository":{"id":17534678,"uuid":"82186128","full_name":"infrablocks/terraform-aws-ecs-cluster","owner":"infrablocks","description":"Terraform module for building an ECS cluster in AWS","archived":false,"fork":false,"pushed_at":"2025-04-03T17:54:39.000Z","size":898,"stargazers_count":50,"open_issues_count":4,"forks_count":50,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-03T18:38:03.326Z","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":".github/FUNDING.yml","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},"funding":{"github":["tobyclemson"]}},"created_at":"2017-02-16T13:56:35.000Z","updated_at":"2025-04-03T17:54:41.000Z","dependencies_parsed_at":"2023-02-19T06:15:37.894Z","dependency_job_id":"564f19c5-ded6-46f8-8837-d0fb41fb43fa","html_url":"https://github.com/infrablocks/terraform-aws-ecs-cluster","commit_stats":null,"previous_names":[],"tags_count":117,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Fterraform-aws-ecs-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infrablocks","download_url":"https://codeload.github.com/infrablocks/terraform-aws-ecs-cluster/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419861,"owners_count":20936012,"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:05.808Z","updated_at":"2026-03-16T20:32:25.334Z","avatar_url":"https://github.com/infrablocks.png","language":"Ruby","funding_links":["https://github.com/sponsors/tobyclemson"],"categories":[],"sub_categories":[],"readme":"Terraform AWS ECS Cluster\n=========================\n\n[![CircleCI](https://circleci.com/gh/infrablocks/terraform-aws-ecs-cluster.svg?style=svg)](https://circleci.com/gh/infrablocks/terraform-aws-ecs-cluster)\n\nA Terraform module for building an ECS Cluster in AWS.\n\nThe ECS cluster requires:\n\n* An existing VPC\n* Some existing subnets\n\nThe ECS cluster consists of:\n\n* A cluster in ECS\n* A launch template and auto-scaling group for a cluster of ECS container\n  instances\n* An SSH key to connect to the ECS container instances\n* A security group for the container instances optionally allowing:\n    * Outbound internet access for all containers\n    * Inbound TCP access on any port from the VPC network\n* An IAM role and policy for the container instances allowing:\n    * ECS interactions\n    * ECR image pulls\n    * S3 object fetches\n    * Logging to cloudwatch\n* An IAM role and policy for ECS services allowing:\n    * Elastic load balancer registration / deregistration\n    * EC2 describe actions and security group ingress rule creation\n* A CloudWatch log group\n\n![Diagram of infrastructure managed by this module](https://raw.githubusercontent.com/infrablocks/terraform-aws-ecs-cluster/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_cluster\" {\n  source  = \"infrablocks/ecs-cluster/aws\"\n  version = \"5.0.0\"\n\n  region     = \"eu-west-2\"\n  vpc_id     = \"vpc-fb7dc365\"\n  subnet_ids = [\n    \"subnet-eb32c271\",\n    \"subnet-64872d1f\"\n  ]\n\n  component             = \"important-component\"\n  deployment_identifier = \"production\"\n\n  cluster_name                         = \"services\"\n  cluster_instance_ssh_public_key_path = \"~/.ssh/id_rsa.pub\"\n  cluster_instance_type                = \"t3.small\"\n\n  cluster_minimum_size     = 2\n  cluster_maximum_size     = 10\n  cluster_desired_capacity = 4\n}\n```\n\nAs mentioned above, the ECS cluster deploys into an existing base network.\nWhilst the base network can be created using any mechanism you like, the\n[AWS Base Networking](https://github.com/infrablocks/terraform-aws-base-networking)\nmodule will create everything you need. See the\n[docs](https://github.com/infrablocks/terraform-aws-base-networking/blob/main/README.md)\nfor usage instructions.\n\nSee the\n[Terraform registry entry](https://registry.terraform.io/modules/infrablocks/ecs-cluster/aws/latest)\nfor more details.\n\n### Inputs\n\n| Name                                                | Description                                                                                            |      Default      |            Required             |\n|-----------------------------------------------------|--------------------------------------------------------------------------------------------------------|:-----------------:|:-------------------------------:|\n| region                                              | The region into which to deploy the cluster                                                            |         -         |               yes               |\n| vpc_id                                              | The ID of the VPC into which to deploy the cluster                                                     |         -         |               yes               |\n| subnet_ids                                          | The IDs of the subnets for container instances                                                         |         -         |               yes               |\n| component                                           | The component this cluster will contain                                                                |         -         |               yes               |\n| deployment_identifier                               | An identifier for this instantiation                                                                   |         -         |               yes               |\n| tags                                                | A map of additional tags to add to all resources                                                       |         -         |               no                |\n| cluster_name                                        | The name of the cluster to create                                                                      |      default      |               yes               |\n| cluster_instance_ssh_public_key_path                | The path to the public key to use for the container instances                                          |         -         |               yes               |\n| cluster_instance_type                               | The instance type of the container instances                                                           |     t2.medium     |               yes               |\n| cluster_instance_root_block_device_size             | The size in GB of the root block device on cluster instances                                           |        30         |               yes               |\n| cluster_instance_root_block_device_path             | Path of the instance root block storage volume                                                         |     /dev/xvda     |               yes               |\n| cluster_instance_root_block_device_type             | The type of the root block device on cluster instances ('standard', 'gp2', or 'io1')                   |     standard      |               yes               |\n| cluster_instance_user_data_template                 | The contents of a template for container instance user data                                            |   see user-data   |               no                |\n| cluster_instance_ami                                | AMI for the container instances                                                                        | ECS optimised AMI |               yes               |\n| cluster_instance_metadata_options                   | A map of metadata options for cluster instances.                                                       |         -         |               no                |\n| cluster_instance_iam_policy_contents                | The contents of the cluster instance IAM policy                                                        |   see policies    |               no                |\n| cluster_service_iam_policy_contents                 | The contents of the cluster service IAM policy                                                         |   see policies    |               no                |\n| cluster_minimum_size                                | The minimum size of the ECS cluster                                                                    |         1         |               yes               |\n| cluster_maximum_size                                | The maximum size of the ECS cluster                                                                    |        10         |               yes               |\n| cluster_desired_capacity                            | The desired capacity of the ECS cluster                                                                |         3         |               yes               |\n| associate_public_ip_addresses                       | Whether or not to associate public IP addresses with ECS container instances                           |       false       |               no                |\n| include_default_ingress_rule                        | Whether or not to include the default ingress rule on the ECS container instances security group       |       true        |               no                |\n| include_default_egress_rule                         | Whether or not to include the default egress rule on the ECS container instances security group        |       true        |               no                |\n| default_ingress_cidrs                               | The CIDRs allowed access to containers                                                                 |  [\"10.0.0.0/8\"]   | if include_default_ingress_rule |\n| default_egress_cidrs                                | The CIDRs accessible from containers                                                                   |   [\"0.0.0.0/0\"]   | if include_default_egress_rule  |\n| security_groups                                     | The list of security group IDs to associate with the cluster in addition to the default security group |        []         |               no                |\n| cluster_log_group_retention                         | The number of days logs will be retained in the CloudWatch log group of the cluster (0 = unlimited)    |         0         |               no                |\n| enable_detailed_monitoring                          | Enable detailed monitoring of EC2 instance(s)                                                          |       true        |               no                |\n| enable_container_insights                           | Whether or not to enable container insights on the ECS cluster                                         |       false       |               no                |\n| protect_cluster_instances_from_scale_in             | Whether or not to protect cluster instances in the autoscaling group from scale in                     |       false       |               no                |\n| include_asg_capacity_provider                       | Whether or not to add the created ASG as a capacity provider for the ECS cluster                       |       false       |               no                |\n| asg_capacity_provider_manage_termination_protection | Whether or not to allow ECS to manage termination protection for the ASG capacity provider             |       true        |               no                |\n| asg_capacity_provider_manage_scaling                | Whether or not to allow ECS to manage scaling for the ASG capacity provider                            |       true        |               no                |\n| asg_capacity_provider_minimum_scaling_step_size     | The minimum scaling step size for ECS managed scaling of the ASG capacity provider                     |         1         |               no                |\n| asg_capacity_provider_maximum_scaling_step_size     | The maximum scaling step size for ECS managed scaling of the ASG capacity provider                     |       1000        |               no                |\n| asg_capacity_provider_target_capacity               | The target capacity, as a percentage from 1 to 100, for the ASG capacity provider                      |        100        |               no                |\n| cluster_instance_enable_ebs_volume_encryption       | Determines whether encryption is enabled on the EBS volume                                             |       true        |               no                |\n| cluster_instance_ebs_volume_kms_key_id              | KMS key to use for encryption of the EBS volume when enabled                                           |   alias/aws/ebs   |               no                |\n\nNotes:\n\n* By default, the latest available Amazon Linux 2 AMI is used.\n* For Amazon Linux 1 AMIs use version \u003c= 0.6.0 of this module for terraform 0.11\n  or version = 1.0.0 for terraform 0.12.\n* When a specific AMI is provided via `cluster_instance_ami`, only the root\n  block device can be customised, using the\n  `cluster_instance_root_block_device_size` and\n  `cluster_instance_root_block_device_type` variables.\n* The user data template will get the cluster name as `cluster_name`. If\n  none is supplied, a default will be used.\n\n### Outputs\n\n| Name                   | Description                                                                      |\n|------------------------|----------------------------------------------------------------------------------|\n| cluster_id             | The ID of the created ECS cluster                                                |\n| cluster_name           | The name of the created ECS cluster                                              |\n| cluster_arn            | The ARN of the created ECS cluster                                               |\n| autoscaling_group_name | The name of the autoscaling group for the ECS container instances                |\n| launch_template_name   | The name of the launch template for the ECS container instances                  |\n| launch_template_id     | The ID of the launch template for the ECS container instances                    |\n| security_group_id      | The ID of the default security group associated with the ECS container instances |\n| instance_role_arn      | The ARN of the container instance role                                           |\n| instance_role_id       | The ID of the container instance role                                            |\n| instance_policy_arn    | The ARN of the container instance policy                                         |\n| instance_policy_id     | The ID of the container instance policy                                          |\n| service_role_arn       | The ARN of the ECS service role                                                  |\n| service_role_id        | The ID of the ECS service role                                                   |\n| service_policy_arn     | The ARN of the ECS service policy                                                |\n| service_policy_id      | The ID of the ECS service policy                                                 |\n| log_group              | The name of the default log group for the cluster                                |\n\n### Compatibility\n\nThis module is compatible with Terraform versions greater than or equal to\nTerraform 1.0.\n\n### Required Permissions\n\n* iam:GetPolicy\n* iam:GetPolicyVersion\n* iam:ListPolicyVersions\n* iam:ListEntitiesForPolicy\n* iam:CreatePolicy\n* iam:DeletePolicy\n* iam:GetRole\n* iam:PassRole\n* iam:CreateRole\n* iam:DeleteRole\n* iam:ListRolePolicies\n* iam:AttachRolePolicy\n* iam:DetachRolePolicy\n* iam:GetInstanceProfile\n* iam:CreateInstanceProfile\n* iam:ListInstanceProfilesForRole\n* iam:AddRoleToInstanceProfile\n* iam:RemoveRoleFromInstanceProfile\n* iam:DeleteInstanceProfile\n* ec2:DescribeSecurityGroups\n* ec2:CreateSecurityGroup\n* ec2:DeleteSecurityGroup\n* ec2:AuthorizeSecurityGroupIngress\n* ec2:AuthorizeSecurityGroupEgress\n* ec2:RevokeSecurityGroupEgress\n* ec2:ImportKeyPair\n* ec2:DescribeKeyPairs\n* ec2:DeleteKeyPair\n* ec2:CreateTags\n* ec2:DescribeImages\n* ec2:DescribeNetworkInterfaces\n* ecs:DescribeClusters\n* ecs:CreateCluster\n* ecs:DeleteCluster\n* autoscaling:DescribeLaunchConfigurations\n* autoscaling:CreateLaunchConfiguration\n* autoscaling:DeleteLaunchConfiguration\n* autoscaling:DescribeScalingActivities\n* autoscaling:DescribeAutoScalingGroups\n* autoscaling:CreateAutoScalingGroup\n* autoscaling:UpdateAutoScalingGroup\n* autoscaling:DeleteAutoScalingGroup\n* logs:CreateLogGroup\n* logs:DescribeLogGroups\n* logs:ListTagsLogGroup\n* logs:DeleteLogGroup\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)\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```shell\nruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"\n```\n\nThen, to install the required tools:\n\n```shell\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\nWhen a deployment identifier is provided via an environment variable,\ninfrastructure will not be destroyed at the end of test execution. This can\nbe useful during development to avoid lengthy provision and destroy cycles.\n\n### Common Tasks\n\n#### Generating an SSH key pair\n\nTo generate an SSH key pair:\n\n```bash\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\n```bash\nopenssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365\n```\n\nTo decrypt the resulting key:\n\n```bash\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-assumable-roles-policy.\nThis project is intended to be a safe, welcoming space for collaboration, and\ncontributors are expected to adhere to\nthe [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-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfrablocks%2Fterraform-aws-ecs-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfrablocks%2Fterraform-aws-ecs-cluster/lists"}