This folder shows examples of how to use the asg-instance-refresh module to create an Auto Scaling Group (ASG) that supports rolling deployment via instance refresh:
with-elb: An example of how to deploy an ASG where each instance registers with an Elastic Load Balancer (ELB).
without-elb: An example of how to deploy an ASG without any load balancer.
On each EC2 Instance in the ASG, for demonstration and testing purposes, we run a dummy web server that just returns "Hello World". If you update this app (e.g. change the text to "Hello, World v2" or replace the app with a totally different AMI of your own), the next time you run terraform apply, the new version of the app will roll out automatically, with no downtime, across your ASG.
Open variables.tf, set the environment variables specified at the top of the file, and fill in any other variables that
don't have a default.
Run terraform get.
Run terraform plan.
If the plan looks good, run terraform apply.
Deploying a new version
Once you have the app up and running, to test out the rolling deployment, make a change to any of the variables passed into the ASG. For example, as a quick test, you could change the server_text variable to "Hello, World, v2.0!". Once you've made your changes, do the following:
Commit your changes to Git so your teammates have access to them.
Run terraform plan.
If the plan looks good, run terraform apply.
The new version of the app will automatically deploy across the Auto Scaling Cluster. This is accomplished by taking advantage of AWS's Instance Refresh via the Terraform instance_refresh resource, which allows the Auto Scaling Group to perform a rolling replacement of all running instances based on completion of instance warmup, passing of health checks, and completion of checkpoints.
Questions? Ask away.
We're here to talk about our services, answer any questions, give advice, or just to chat.
{"treedata":{"name":"root","toggled":true,"children":[{"name":".circleci","children":[{"name":"config.yml","path":".circleci/config.yml","sha":"7374d1255fd61c4b4c97b904e90f97cd7597b7ca"},{"name":"post-upgrade-test-results.sh","path":".circleci/post-upgrade-test-results.sh","sha":"a4867e8fbdc334b7a90259568ee41ea577fbe764"},{"name":"set-upgrade-test-vars.sh","path":".circleci/set-upgrade-test-vars.sh","sha":"8d961461f09584ccd42432b5d56d64db43da1a6e"}]},{"name":".github","children":[{"name":"ISSUE_TEMPLATE","children":[{"name":"bug_report.md","path":".github/ISSUE_TEMPLATE/bug_report.md","sha":"d2e87e27c601e423865ed660ec697082470ca60f"},{"name":"feature_request.md","path":".github/ISSUE_TEMPLATE/feature_request.md","sha":"023a33099be2336476930c96e17ff1ba5dc55348"}]},{"name":"pull_request_template.md","path":".github/pull_request_template.md","sha":"6b100e40e323b5b07f40ed30616277c51c9f4b9e"}]},{"name":".gitignore","path":".gitignore","sha":"fd04ff401a18d9c8595968dbbd3a9996d37b6a8b"},{"name":".pre-commit-config.yaml","path":".pre-commit-config.yaml","sha":"605d316ff7fc0ae6e303f790b71c61a2dc31337a"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"5ec6c488d1e6577b86c42b21fb2daf162c3e160a"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","sha":"c992069269419c83cb1f032fd80124cdca22fb02"},{"name":"LICENSE.txt","path":"LICENSE.txt","sha":"f4e3d9bd4717a044ed31ad847a300eee74371a78"},{"name":"README.md","path":"README.md","sha":"28a4240bb0352e8f94eb1f07dd6b602e5858990a"},{"name":"examples","children":[{"name":"asg-instance-refresh-with-launch-template","children":[{"name":"README.md","path":"examples/asg-instance-refresh-with-launch-template/README.md","sha":"a4aee07ff69ae8b4b095168c4f8f31a5168b3437"},{"name":"main.tf","path":"examples/asg-instance-refresh-with-launch-template/main.tf","sha":"f80f629dc70caf62a2389f3a3dc488f11fd6f396"},{"name":"outputs.tf","path":"examples/asg-instance-refresh-with-launch-template/outputs.tf","sha":"c8db3c807aab3d75888c2dd039b9e81b1312a137"},{"name":"variables.tf","path":"examples/asg-instance-refresh-with-launch-template/variables.tf","sha":"d4d4c041884de1f2e31ca0d64c0f4a6031b88ea8"}]},{"name":"asg-instance-refresh","children":[{"name":"README.md","path":"examples/asg-instance-refresh/README.md","sha":"f566fae0867be0be2cecbd8ca6d20234c5cc17dc","toggled":true},{"name":"with-elb","children":[{"name":"main.tf","path":"examples/asg-instance-refresh/with-elb/main.tf","sha":"13cb1ff317d66687de797feed5e0f83d8e528021"},{"name":"outputs.tf","path":"examples/asg-instance-refresh/with-elb/outputs.tf","sha":"330a02ec9378c2c9c4a1423b075384f4ae3ed241"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/asg-instance-refresh/with-elb/user-data/user-data.sh","sha":"7b5fbe6f33805eb5356e9c49db9bd5b141b0816a"}]},{"name":"variables.tf","path":"examples/asg-instance-refresh/with-elb/variables.tf","sha":"2056963b26c09d4579a5a860075e4a7a3d7875e5"}]},{"name":"without-elb","children":[{"name":"main.tf","path":"examples/asg-instance-refresh/without-elb/main.tf","sha":"b458ffc6deb91c26382bd99c5381cc8ad2619db3"},{"name":"outputs.tf","path":"examples/asg-instance-refresh/without-elb/outputs.tf","sha":"c8db3c807aab3d75888c2dd039b9e81b1312a137"},{"name":"variables.tf","path":"examples/asg-instance-refresh/without-elb/variables.tf","sha":"42452d0ed062cf8afce3f23319bb5e81690d12a1"}]}],"toggled":true},{"name":"asg-rolling-deploy","children":[{"name":"README.md","path":"examples/asg-rolling-deploy/README.md","sha":"6b9a213c73ec5c5bff3b270695f9c6c749c0d642"},{"name":"with-elb","children":[{"name":"main.tf","path":"examples/asg-rolling-deploy/with-elb/main.tf","sha":"429845439e56161743cd20ec1c0688f7d65898e5"},{"name":"outputs.tf","path":"examples/asg-rolling-deploy/with-elb/outputs.tf","sha":"330a02ec9378c2c9c4a1423b075384f4ae3ed241"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/asg-rolling-deploy/with-elb/user-data/user-data.sh","sha":"7b5fbe6f33805eb5356e9c49db9bd5b141b0816a"}]},{"name":"variables.tf","path":"examples/asg-rolling-deploy/with-elb/variables.tf","sha":"dab89e417460b5fa2676796e945acf27803c6553"}]},{"name":"without-elb","children":[{"name":"main.tf","path":"examples/asg-rolling-deploy/without-elb/main.tf","sha":"2e1ef6f1bebbbb62cecc48cc99930a8aeeaa53ac"},{"name":"outputs.tf","path":"examples/asg-rolling-deploy/without-elb/outputs.tf","sha":"c8db3c807aab3d75888c2dd039b9e81b1312a137"},{"name":"variables.tf","path":"examples/asg-rolling-deploy/without-elb/variables.tf","sha":"1d6d2ee9904841723c7e7c29d9fe5e12e7f6fd6a"}]}]},{"name":"server-group","children":[{"name":"README.md","path":"examples/server-group/README.md","sha":"10cda1da76dedb61ef2ff8ec8dc11a619d71fff9"},{"name":"ami","children":[{"name":"server.json","path":"examples/server-group/ami/server.json","sha":"01afa473255bad78f379b8bb6b6817f58b59adfe"}]},{"name":"with-alb","children":[{"name":"main.tf","path":"examples/server-group/with-alb/main.tf","sha":"6d5e6145442a965b1d743f5e4a6e3e8406372bd5"},{"name":"outputs.tf","path":"examples/server-group/with-alb/outputs.tf","sha":"3565caece2f11d61dc0b0a6ed23cc58ce7e6e61c"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/server-group/with-alb/user-data/user-data.sh","sha":"55d5dff9d84f2e3793f6c669fd0cfa4bd65f287a"}]},{"name":"variables.tf","path":"examples/server-group/with-alb/variables.tf","sha":"dc708850a0e1169ba4101135f6a707e79bd82850"}]},{"name":"with-elb","children":[{"name":"main.tf","path":"examples/server-group/with-elb/main.tf","sha":"0de589319bf9e3acab48d7fd78021c8fc5426b8a"},{"name":"outputs.tf","path":"examples/server-group/with-elb/outputs.tf","sha":"fd38915d96770f9588e2fcc79369e64449492286"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/server-group/with-elb/user-data/user-data.sh","sha":"3800df7ab47bf43e6253ebeb21d5900585d32b6a"}]},{"name":"variables.tf","path":"examples/server-group/with-elb/variables.tf","sha":"4eb70bfff00b837c8404d044fee311b16e0e0c73"}]},{"name":"without-load-balancer","children":[{"name":"main.tf","path":"examples/server-group/without-load-balancer/main.tf","sha":"66bf40bd0488db96cad11d4ba07ca480b4fa8f92"},{"name":"outputs.tf","path":"examples/server-group/without-load-balancer/outputs.tf","sha":"27911554f10688f23ba9f8e31eadd4409c635f97"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/server-group/without-load-balancer/user-data/user-data.sh","sha":"55d5dff9d84f2e3793f6c669fd0cfa4bd65f287a"}]},{"name":"variables.tf","path":"examples/server-group/without-load-balancer/variables.tf","sha":"0724aa38905b313165b621e7866575e0e0abdd4b"}]}]}],"toggled":true},{"name":"modules","children":[{"name":"asg-instance-refresh","children":[{"name":"README.md","path":"modules/asg-instance-refresh/README.md","sha":"972cfd23e4a68b4b77839549b15392eaa1fbc0a3"},{"name":"main.tf","path":"modules/asg-instance-refresh/main.tf","sha":"a5a8f68d20d4a1197181ea24fda11a5d4fd7adbd"},{"name":"outputs.tf","path":"modules/asg-instance-refresh/outputs.tf","sha":"5225c1f98cfc9f91411d91eae7bd692168ea8f4c"},{"name":"variables.tf","path":"modules/asg-instance-refresh/variables.tf","sha":"0bfddab822b450846e5d413dd91aa3ee7b863b79"}]},{"name":"asg-rolling-deploy","children":[{"name":"README.md","path":"modules/asg-rolling-deploy/README.md","sha":"fbbc6657f0cef2493e9fdb7b42549d69e5ff4080"},{"name":"describe-autoscaling-group","children":[{"name":"README.md","path":"modules/asg-rolling-deploy/describe-autoscaling-group/README.md","sha":"30ba6d6cfb97a09deb821a9037108bbc6abcc276"},{"name":"boto3-1.20.24.zip","path":"modules/asg-rolling-deploy/describe-autoscaling-group/boto3-1.20.24.zip","sha":"b4b675780634cea8a0eb06a0b0458dbb0a39385d"},{"name":"get-desired-capacity.py","path":"modules/asg-rolling-deploy/describe-autoscaling-group/get-desired-capacity.py","sha":"a980df805a4d65e77ecd1dbba5892803415c9c5b"}]},{"name":"main.tf","path":"modules/asg-rolling-deploy/main.tf","sha":"72fd980910d7cf4846d1616be58151ce812637a4"},{"name":"outputs.tf","path":"modules/asg-rolling-deploy/outputs.tf","sha":"5225c1f98cfc9f91411d91eae7bd692168ea8f4c"},{"name":"variables.tf","path":"modules/asg-rolling-deploy/variables.tf","sha":"a599c1aa7504e2ec91932564c93d216b6fe63f62"}]},{"name":"server-group","children":[{"name":"README.md","path":"modules/server-group/README.md","sha":"10ff38cf380db99bf9e336081a59acb18c072198"},{"name":"main.tf","path":"modules/server-group/main.tf","sha":"2d882e86cfdc13b1f520df6932d03337168b7556"},{"name":"outputs.tf","path":"modules/server-group/outputs.tf","sha":"b5666cf3e0d9b85cbb9f13cb5d87f27b148c39f8"},{"name":"rolling-deploy","children":[{"name":"boto3-1.20.24.zip","path":"modules/server-group/rolling-deploy/boto3-1.20.24.zip","sha":"b4b675780634cea8a0eb06a0b0458dbb0a39385d"},{"name":"helpers.py","path":"modules/server-group/rolling-deploy/helpers.py","sha":"37ee35c8f200ceafdb9f7acf09d2ece1e6adddcb"},{"name":"rolling_deployment.py","path":"modules/server-group/rolling-deploy/rolling_deployment.py","sha":"e63f3e9a2072daf9d261b739ea9b6eddb2a95f0f"}]},{"name":"variables.tf","path":"modules/server-group/variables.tf","sha":"fdb00a4d0154c1930cbdd425c1ca06eed7898166"}]}]},{"name":"terraform-cloud-enterprise-private-module-registry-placeholder.tf","path":"terraform-cloud-enterprise-private-module-registry-placeholder.tf","sha":"ae586c0fe830819580e1009d41a9074f16e65bed"},{"name":"test","children":[{"name":"README.md","path":"test/README.md","sha":"cfa55a38cc6fbd09a311291216eb758159973629"},{"name":"asg_instance_refresh_test.go","path":"test/asg_instance_refresh_test.go","sha":"78157f674961278f1381fa9f688c87e7ffabaec4"},{"name":"asg_rolling_deploy_test.go","path":"test/asg_rolling_deploy_test.go","sha":"ca7bc5e7ac8b57f3eaee07f4f7417d1ab1e67cd3"},{"name":"go.mod","path":"test/go.mod","sha":"914dc7f51dccc6f9543903be303adef1c39239a1"},{"name":"go.sum","path":"test/go.sum","sha":"356aa577d3a974784d530acf5c50856bfe0eca4c"},{"name":"server_group_test.go","path":"test/server_group_test.go","sha":"226a95bf2bbddcddc3635db15003e9f39e1ab58d"},{"name":"test_helpers.go","path":"test/test_helpers.go","sha":"66805d579a7b57fe719de365473effd2cb34602f"},{"name":"upgrades","children":[{"name":"upgrade_test.go","path":"test/upgrades/upgrade_test.go","sha":"40101dddb57afddbca8c8fe5e329eecbfd28efb6"}]},{"name":"validation","children":[{"name":"validate_all_modules_and_examples_test.go","path":"test/validation/validate_all_modules_and_examples_test.go","sha":"74c928d0cbc2914e5cd708277bd857cb2375b660"}]}]}]},"detailsContent":"<h1 class=\"preview__body--title\" id=\"auto-scaling-group-with-instance-refresh-examples\">Auto Scaling Group with Instance Refresh Examples</h1><div class=\"preview__body--border\"></div><p>This folder shows examples of how to use the <a href=\"/repos/v0.17.3/module-asg/modules/asg-instance-refresh\" class=\"preview__body--description--blue\">asg-instance-refresh module</a> to create an Auto Scaling Group (ASG) that supports rolling deployment via instance refresh:</p>\n<ul>\n<li><a href=\"/repos/v0.17.3/module-asg/examples/asg-instance-refresh/with-elb\" class=\"preview__body--description--blue\">with-elb</a>: An example of how to deploy an ASG where each instance registers with an Elastic Load Balancer (ELB).</li>\n<li><a href=\"/repos/v0.17.3/module-asg/examples/asg-instance-refresh/without-elb\" class=\"preview__body--description--blue\">without-elb</a>: An example of how to deploy an ASG without any load balancer.</li>\n</ul>\n<p>On each EC2 Instance in the ASG, for demonstration and testing purposes, we run a dummy web server that just returns "Hello World". If you update this app (e.g. change the text to "Hello, World v2" or replace the app with a totally different AMI of your own), the next time you run <code>terraform apply</code>, the new version of the app will roll out automatically, with no downtime, across your ASG.</p>\n<h2 class=\"preview__body--subtitle\" id=\"how-do-you-run-these-examples\">How do you run these examples?</h2>\n<ol>\n<li>Install <a href=\"https://www.terraform.io/\" class=\"preview__body--description--blue\" target=\"_blank\">Terraform</a>.</li>\n<li>Open <code>variables.tf</code>, set the environment variables specified at the top of the file, and fill in any other variables that\ndon't have a default.</li>\n<li>Run <code>terraform get</code>.</li>\n<li>Run <code>terraform plan</code>.</li>\n<li>If the plan looks good, run <code>terraform apply</code>.</li>\n</ol>\n<h2 class=\"preview__body--subtitle\" id=\"deploying-a-new-version\">Deploying a new version</h2>\n<p>Once you have the app up and running, to test out the rolling deployment, make a change to any of the variables passed into the ASG. For example, as a quick test, you could change the <code>server_text</code> variable to "Hello, World, v2.0!". Once you've made your changes, do the following:</p>\n<ol>\n<li>Commit your changes to Git so your teammates have access to them.</li>\n<li>Run <code>terraform plan</code>.</li>\n<li>If the plan looks good, run <code>terraform apply</code>.</li>\n</ol>\n<p>The new version of the app will automatically deploy across the Auto Scaling Cluster. This is accomplished by taking advantage of AWS's Instance Refresh via the Terraform <a href=\"https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#instance_refresh\" class=\"preview__body--description--blue\" target=\"_blank\">instance_refresh</a> resource, which allows the Auto Scaling Group to perform a rolling replacement of all running instances based on completion of instance warmup, passing of health checks, and completion of checkpoints.</p>\n","repoName":"module-asg","repoRef":"v0.19.4","serviceDescriptor":{"serviceName":"Auto Scaling Group (stateless)","serviceRepoName":"module-asg","serviceRepoOrg":"gruntwork-io","serviceMainReadmePath":"/modules/asg-rolling-deploy","cloudProviders":["aws"],"description":"Run an Auto Scaling Group for stateless apps. Supports zero-downtime, rolling deployment, auto healing, auto scaling, and IAM Roles.","imageUrl":"auto-scaling2.png","licenseType":"subscriber","technologies":["Terraform","Python","Bash"],"compliance":[],"tags":[""]},"serviceCategoryName":"Server orchestration","fileName":"README.md","filePath":"/examples/asg-instance-refresh","title":"Repo Browser: Auto Scaling Group (stateless)","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}