{"id":22347737,"url":"https://github.com/wearetechnative/terraform-aws-ec2-asg","last_synced_at":"2026-03-19T22:29:06.288Z","repository":{"id":258505014,"uuid":"706679194","full_name":"wearetechnative/terraform-aws-ec2-asg","owner":"wearetechnative","description":"AWS auto scaling is used to scale up and scale down the EC2-instance by depending up on the incoming traffic.","archived":false,"fork":false,"pushed_at":"2025-04-22T10:33:11.000Z","size":210,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-22T11:34:58.585Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wearetechnative.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-10-18T12:23:20.000Z","updated_at":"2025-04-22T10:33:13.000Z","dependencies_parsed_at":"2025-01-14T10:40:52.851Z","dependency_job_id":"df3be590-0a16-4a46-9677-060761c8faac","html_url":"https://github.com/wearetechnative/terraform-aws-ec2-asg","commit_stats":null,"previous_names":["wearetechnative/terraform-aws-ec2-asg"],"tags_count":0,"template":false,"template_full_name":"TechNative-B-V/terraform-aws-module-template","purl":"pkg:github/wearetechnative/terraform-aws-ec2-asg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearetechnative%2Fterraform-aws-ec2-asg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearetechnative%2Fterraform-aws-ec2-asg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearetechnative%2Fterraform-aws-ec2-asg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearetechnative%2Fterraform-aws-ec2-asg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wearetechnative","download_url":"https://codeload.github.com/wearetechnative/terraform-aws-ec2-asg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearetechnative%2Fterraform-aws-ec2-asg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017232,"owners_count":26086016,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-04T10:10:39.909Z","updated_at":"2025-10-13T23:43:20.235Z","avatar_url":"https://github.com/wearetechnative.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform AWS EC2 ASG\n\nThis module implements an EC2 Auto Scaling Group\n\n[![](we-are-technative.png)](https://www.technative.nl)\n\n## When to use terraform-aws-ec2-asg\n\nUse `terraform-aws-ec2-asg` if:\n\n- You need to provide a fail-over setup with one EC2 (i.e. the initial use of terraform-aws-ec2-asg).\n  - Generally used with `use_floating_ip = true` to host applications that are\n    not Dockerized. An EIP will be used and floats to another EC2 instance if\n    the current instance fails.\n  - Also used for setting up reliable Bastion hosts.\n- You need to provide compute resources for ECS clusters.\n\nDo not use `terraform-aws-ec2-asg` if:\n\n- If you need to provision EC2 instances for EKS, we have `eks_custom_nodegroup` for this. (Altough we should/could refactor the `ec2_asg` module for use with EKS as well...) or at least use it in `eks_custom_nodegroup`.\n\n## Todo\n\n- Implement spot instance functionality in `launch_template`.\n\n## Troubleshooting / Known issues\n\n### ARN specified for Service-Linked Role does not exist\n\nSometimes you receive the following error:\n\n```\n│ Error: creating Auto Scaling Group (ec2-asg-website_stack_dev-eu-central-1b): ValidationError: ARN specified for Service-Linked Role does not exist.\n│       status code: 400, request id: 3dcf1ff4-d46f-4724-9586-f1e4957b5dd4\n│\n│   with module.network_compute.module.network.module.nat_instances[\"eu-central-1b\"].module.ec2_asg.aws_autoscaling_group.this,\n│   on ../../modules/ec2_asg/autoscaling_group.tf line 16, in resource \"aws_autoscaling_group\" \"this\":\n│   16: resource \"aws_autoscaling_group\" \"this\" {\n```\n\nRun `terraform apply` again. This is because of a race condition in AWS.\n\n### Initial lifecycle hooks are not updated in ASG when changed.\n\nWe currently do not know a solution other than deleting and recreating the ASG.\n\n\u003c!-- BEGIN_TF_DOCS --\u003e\n## Providers\n\n| Name | Version |\n|------|---------|\n| \u003ca name=\"provider_aws\"\u003e\u003c/a\u003e [aws](#provider\\_aws) | \u003e=4.8.0 |\n| \u003ca name=\"provider_random\"\u003e\u003c/a\u003e [random](#provider\\_random) | n/a |\n\n## Modules\n\n| Name | Source | Version |\n|------|--------|---------|\n| \u003ca name=\"module_eip_lambda\"\u003e\u003c/a\u003e [eip\\_lambda](#module\\_eip\\_lambda) | ./eip_lambda | n/a |\n| \u003ca name=\"module_iam_role\"\u003e\u003c/a\u003e [iam\\_role](#module\\_iam\\_role) | git@github.com:wearetechnative/terraform-aws-iam-role | 0fe916c27097706237692122e09f323f55e8237e |\n\n## Resources\n\n| Name | Type |\n|------|------|\n| [aws_autoscaling_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group) | resource |\n| [aws_eip.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eip) | resource |\n| [aws_iam_instance_profile.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |\n| [aws_iam_policy.userdata-lifecycle](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |\n| [aws_iam_role_policy_attachment.userdata-lifecycle](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |\n| [aws_iam_service_linked_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_service_linked_role) | resource |\n| [aws_kms_grant.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_grant) | resource |\n| [aws_launch_template.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource |\n| [aws_ssm_parameter.public-ip](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |\n| [random_string.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |\n| [aws_ami.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |\n| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |\n| [aws_eip.own_eip](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eip) | data source |\n| [aws_iam_policy_document.userdata-lifecycle](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |\n| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |\n\n## Inputs\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| \u003ca name=\"input_additional_tags\"\u003e\u003c/a\u003e [additional\\_tags](#input\\_additional\\_tags) | Additional tags on the ASG that will be propagated to the hosts. Useful for EKS \u0026 Systems Manager state management. Always propagated to EC2 instances. | `map(string)` | `{}` | no |\n| \u003ca name=\"input_ec2_ami_name_filter_list\"\u003e\u003c/a\u003e [ec2\\_ami\\_name\\_filter\\_list](#input\\_ec2\\_ami\\_name\\_filter\\_list) | Optional regex value to filter the AMI image. Most recently is used. Only AMIs with root device EBS and virtualization type HVM are currently allowed. Default is Ubuntu. | `list(string)` | \u003cpre\u003e[\u003cbr\u003e  \"ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*\"\u003cbr\u003e]\u003c/pre\u003e | no |\n| \u003ca name=\"input_ec2_ami_owner_list\"\u003e\u003c/a\u003e [ec2\\_ami\\_owner\\_list](#input\\_ec2\\_ami\\_owner\\_list) | Optional list of owners as an additional filter. This is a safeguard to prevent AMI names from being reused by malicious third parties. Default is Canonical. | `list(string)` | \u003cpre\u003e[\u003cbr\u003e  \"099720109477\"\u003cbr\u003e]\u003c/pre\u003e | no |\n| \u003ca name=\"input_ec2_instance_type\"\u003e\u003c/a\u003e [ec2\\_instance\\_type](#input\\_ec2\\_instance\\_type) | Optional instance type for EC2. Defaults to t3a.small. | `string` | `\"t3a.small\"` | no |\n| \u003ca name=\"input_ec2_root_initial_size\"\u003e\u003c/a\u003e [ec2\\_root\\_initial\\_size](#input\\_ec2\\_root\\_initial\\_size) | Optional initial size of the EC2 root instance disk. Must be sufficient for the AMI that is used. Defaults to 8Gb. | `number` | `8` | no |\n| \u003ca name=\"input_initial_amount_of_pods\"\u003e\u003c/a\u003e [initial\\_amount\\_of\\_pods](#input\\_initial\\_amount\\_of\\_pods) | Initial amount of pods to set when the ASG is (re)created. | `number` | `0` | no |\n| \u003ca name=\"input_instance_role_name\"\u003e\u003c/a\u003e [instance\\_role\\_name](#input\\_instance\\_role\\_name) | Optional instance role name. If not specified a default role with some policies like AmazonSSMManagedInstanceCore will be attached. | `string` | `null` | no |\n| \u003ca name=\"input_kms_key_arn\"\u003e\u003c/a\u003e [kms\\_key\\_arn](#input\\_kms\\_key\\_arn) | KMS key to use for encrypting EBS volumes. | `string` | n/a | yes |\n| \u003ca name=\"input_lifecycle_hooks\"\u003e\u003c/a\u003e [lifecycle\\_hooks](#input\\_lifecycle\\_hooks) | Additional lifecycle hooks for this ASG. They are implemented as initial lifecycle hooks so they will apply to all created EC2 instances. The map key is the name. | \u003cpre\u003emap(object({\u003cbr\u003e    timeout_in_seconds = number\u003cbr\u003e    launch_lifecycle = bool\u003cbr\u003e    notification_metadata = string\u003cbr\u003e  }))\u003c/pre\u003e | `{}` | no |\n| \u003ca name=\"input_name\"\u003e\u003c/a\u003e [name](#input\\_name) | Unique name for EC2 with ASG setup. | `string` | n/a | yes |\n| \u003ca name=\"input_own_eip_for_floaing_ip\"\u003e\u003c/a\u003e [own\\_eip\\_for\\_floaing\\_ip](#input\\_own\\_eip\\_for\\_floaing\\_ip) | Optionally own EIP if floating IP is set to true. | `string` | `null` | no |\n| \u003ca name=\"input_security_group_ids\"\u003e\u003c/a\u003e [security\\_group\\_ids](#input\\_security\\_group\\_ids) | Optional security groups to be associated with EC2 instances. Make sure that SSM endpoints or WAN access is allowed if you want SSM to work. | `list(string)` | `[]` | no |\n| \u003ca name=\"input_sqs_dlq_arn\"\u003e\u003c/a\u003e [sqs\\_dlq\\_arn](#input\\_sqs\\_dlq\\_arn) | Optionally specify a normal SQS queue to be used as DLQ for EventBridge and Lambda. | `string` | `null` | no |\n| \u003ca name=\"input_subnet_ids\"\u003e\u003c/a\u003e [subnet\\_ids](#input\\_subnet\\_ids) | Required list of subnets to launch instances in. | `list(string)` | n/a | yes |\n| \u003ca name=\"input_target_group_arns\"\u003e\u003c/a\u003e [target\\_group\\_arns](#input\\_target\\_group\\_arns) | Target groups to add the managed EC2 instances to. | `list(string)` | `[]` | no |\n| \u003ca name=\"input_use_floating_ip\"\u003e\u003c/a\u003e [use\\_floating\\_ip](#input\\_use\\_floating\\_ip) | Use floating IP for standard endpoint entry. | `bool` | `true` | no |\n| \u003ca name=\"input_use_public_ip\"\u003e\u003c/a\u003e [use\\_public\\_ip](#input\\_use\\_public\\_ip) | Associate public IPs to EC2 instance. | `bool` | `false` | no |\n| \u003ca name=\"input_user_data\"\u003e\u003c/a\u003e [user\\_data](#input\\_user\\_data) | Optional userdata in cleartext.\u003cbr\u003e- Especially if var.user\\_data\\_completion\\_hook is set as well then keep the 16Kb limit in mind for these scripts.\u003cbr\u003e- The script always initiates a server reboot at the end. | `string` | `\"\"` | no |\n| \u003ca name=\"input_user_data_completion_hook\"\u003e\u003c/a\u003e [user\\_data\\_completion\\_hook](#input\\_user\\_data\\_completion\\_hook) | Append completion hook to userdata. Make sure you install awscli and jq in the userdata script. This assumes the userdata script is a bash shell script! | `bool` | `false` | no |\n| \u003ca name=\"input_user_data_lifecyclehook_timeout\"\u003e\u003c/a\u003e [user\\_data\\_lifecyclehook\\_timeout](#input\\_user\\_data\\_lifecyclehook\\_timeout) | Max timeout on userdata lifecycle hook in seconds. Default to 1800 seconds. | `number` | `1800` | no |\n\n## Outputs\n\n| Name | Description |\n|------|-------------|\n| \u003ca name=\"output_autoscaling_group_arn\"\u003e\u003c/a\u003e [autoscaling\\_group\\_arn](#output\\_autoscaling\\_group\\_arn) | n/a |\n| \u003ca name=\"output_autoscaling_group_name\"\u003e\u003c/a\u003e [autoscaling\\_group\\_name](#output\\_autoscaling\\_group\\_name) | n/a |\n| \u003ca name=\"output_elasticip_parameter_arn\"\u003e\u003c/a\u003e [elasticip\\_parameter\\_arn](#output\\_elasticip\\_parameter\\_arn) | n/a |\n\u003c!-- END_TF_DOCS --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearetechnative%2Fterraform-aws-ec2-asg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwearetechnative%2Fterraform-aws-ec2-asg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearetechnative%2Fterraform-aws-ec2-asg/lists"}