This folder shows examples of how to use the asg-rolling-deploy module
to create an Auto Scaling Group (ASG) that supports rolling deployment:
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.
Make sure you have Python installed (version 2.x) and in your PATH.
Open vars.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. Under the hood, this is done by
taking advantage of Terraform's create_before_destroy lifecycle property. This is the same strategy used by HashiCorp
for it's own rolling deployments, as as described by Paul Hinze
here.
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":"b94d0a76cfd53c1c265cecdfb7fc5709783c6cb5"}]},{"name":".gitignore","path":".gitignore","sha":"fd04ff401a18d9c8595968dbbd3a9996d37b6a8b"},{"name":".pre-commit-config.yaml","path":".pre-commit-config.yaml","sha":"addd5d0b1e36748c1c8c751c3fa7755f5dd2522d"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"555c0c6e23a7502acbef94fb0b77bfa759ba11e8"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","sha":"2fb126e11410f30d644f9219847f0a24a52ef4dc"},{"name":"LICENSE.txt","path":"LICENSE.txt","sha":"f4e3d9bd4717a044ed31ad847a300eee74371a78"},{"name":"README.md","path":"README.md","sha":"f8cc0a2b41af68c7781d726a6adb5c68f97ba274"},{"name":"examples","children":[{"name":"asg-rolling-deploy","children":[{"name":"README.md","path":"examples/asg-rolling-deploy/README.md","sha":"f5f2a8e2db00bb7c95975437ac913ef2f9769f7c","toggled":true},{"name":"with-elb","children":[{"name":"main.tf","path":"examples/asg-rolling-deploy/with-elb/main.tf","sha":"3b6af13eb434d64ebace8b5b95752c6e9d45387d"},{"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":"vars.tf","path":"examples/asg-rolling-deploy/with-elb/vars.tf","sha":"dab89e417460b5fa2676796e945acf27803c6553"}]},{"name":"without-elb","children":[{"name":"main.tf","path":"examples/asg-rolling-deploy/without-elb/main.tf","sha":"04a3e849d0484816b5c7144c0a52276fadf8af6e"},{"name":"outputs.tf","path":"examples/asg-rolling-deploy/without-elb/outputs.tf","sha":"c8db3c807aab3d75888c2dd039b9e81b1312a137"},{"name":"vars.tf","path":"examples/asg-rolling-deploy/without-elb/vars.tf","sha":"1d6d2ee9904841723c7e7c29d9fe5e12e7f6fd6a"}]}],"toggled":true},{"name":"server-group","children":[{"name":"README.md","path":"examples/server-group/README.md","sha":"63c6917a20e10cb2b569e5314bbf3d4ec38ff491"},{"name":"ami","children":[{"name":"server.json","path":"examples/server-group/ami/server.json","sha":"bb08fa43aa2c146a2280af4df25fabc1a39cf65f"}]},{"name":"with-alb","children":[{"name":"main.tf","path":"examples/server-group/with-alb/main.tf","sha":"fac9c2eb58f114d0504d2a95a7eecf5c583314c2"},{"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":"064d042a5d0ba6956f4eb8d7ece309b4d6eb4b33"}]},{"name":"vars.tf","path":"examples/server-group/with-alb/vars.tf","sha":"dc708850a0e1169ba4101135f6a707e79bd82850"}]},{"name":"with-elb","children":[{"name":"main.tf","path":"examples/server-group/with-elb/main.tf","sha":"02072d1d82f8f4b87485dab724e562a1513a49f5"},{"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":"f0b175520e85da002b8c26a4a92347fb1eaa1d13"}]},{"name":"vars.tf","path":"examples/server-group/with-elb/vars.tf","sha":"4eb70bfff00b837c8404d044fee311b16e0e0c73"}]},{"name":"without-load-balancer","children":[{"name":"main.tf","path":"examples/server-group/without-load-balancer/main.tf","sha":"36c01e4999e6198d81987ce01383361fcc19d9e8"},{"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":"064d042a5d0ba6956f4eb8d7ece309b4d6eb4b33"}]},{"name":"vars.tf","path":"examples/server-group/without-load-balancer/vars.tf","sha":"0724aa38905b313165b621e7866575e0e0abdd4b"}]}]}],"toggled":true},{"name":"modules","children":[{"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":"062e4ebc0b65610874998a354f441f56114b4e7e"},{"name":"boto3-1.7.10.zip","path":"modules/asg-rolling-deploy/describe-autoscaling-group/boto3-1.7.10.zip","sha":"4b76be11cfa98ddb4314e11a0b28700a11cd2fcc"},{"name":"get-desired-capacity.py","path":"modules/asg-rolling-deploy/describe-autoscaling-group/get-desired-capacity.py","sha":"a8e429f631655ba95eebc11a76fa4100b78eb4a6"}]},{"name":"main.tf","path":"modules/asg-rolling-deploy/main.tf","sha":"9d47a006f041c60c2db5f8526335cac88e5b071a"},{"name":"outputs.tf","path":"modules/asg-rolling-deploy/outputs.tf","sha":"5225c1f98cfc9f91411d91eae7bd692168ea8f4c"},{"name":"vars.tf","path":"modules/asg-rolling-deploy/vars.tf","sha":"321d479f093d8abb0234197b73788580748126a7"}]},{"name":"server-group","children":[{"name":"README.md","path":"modules/server-group/README.md","sha":"13d133fb833f3298f4e4755ad9fe0d767a0682ad"},{"name":"main.tf","path":"modules/server-group/main.tf","sha":"73cf9740aee0dd7a3bdd14f834c68e810d006ecd"},{"name":"outputs.tf","path":"modules/server-group/outputs.tf","sha":"42217027f4a9807a5eae6e786b7a1cd0f6976137"},{"name":"rolling-deploy","children":[{"name":"boto3-1.7.10.zip","path":"modules/server-group/rolling-deploy/boto3-1.7.10.zip","sha":"852dcda88e4e760ce8bdb5c56823f08659959a50"},{"name":"helpers.py","path":"modules/server-group/rolling-deploy/helpers.py","sha":"35dc0d9d154895e3ede805fcb72a7fd6ac8c7c1f"},{"name":"rolling_deployment.py","path":"modules/server-group/rolling-deploy/rolling_deployment.py","sha":"e63f3e9a2072daf9d261b739ea9b6eddb2a95f0f"}]},{"name":"vars.tf","path":"modules/server-group/vars.tf","sha":"0e1897c77a9f88117e5c804acfd7cf5e1d52d72c"}]}]},{"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_rolling_deploy_test.go","path":"test/asg_rolling_deploy_test.go","sha":"ca7bc5e7ac8b57f3eaee07f4f7417d1ab1e67cd3"},{"name":"go.mod","path":"test/go.mod","sha":"bcd74270514848b3d05920090296c46c3c992d6a"},{"name":"go.sum","path":"test/go.sum","sha":"ffcbd50ec065ec260e1e7c32a867d8acc8b25c58"},{"name":"server_group_test.go","path":"test/server_group_test.go","sha":"7248bb6bbb54a515d8ec9363febf4b4fed90390b"},{"name":"test_helpers.go","path":"test/test_helpers.go","sha":"6541cfcd06db09ede8a03dab111f93baea44e51a"}]}]},"detailsContent":"<h1 class=\"preview__body--title\" id=\"auto-scaling-group-with-rolling-deploy-examples\">Auto Scaling Group with Rolling Deploy Examples</h1><div class=\"preview__body--border\"></div><p>This folder shows examples of how to use the <a href=\"/repos/v0.8.7/module-asg/modules/asg-rolling-deploy\" class=\"preview__body--description--blue\">asg-rolling-deploy module</a>\nto create an Auto Scaling Group (ASG) that supports rolling deployment:</p>\n<ul>\n<li><a href=\"/repos/v0.8.7/module-asg/examples/asg-rolling-deploy/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\nBalancer (ELB).</li>\n<li><a href=\"/repos/v0.8.7/module-asg/examples/asg-rolling-deploy/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\n"Hello World". If you update this app (e.g. change the text to "Hello, World v2" or replace the app with a totally\ndifferent AMI of your own), the next time you run <code>terraform apply</code>, the new version of the app will roll out\nautomatically, 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>Make sure you have Python installed (version 2.x) and in your <code>PATH</code>.</li>\n<li>Open <code>vars.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\ninto the ASG. For example, as a quick test, you could change the <code>server_text</code> variable to "Hello, World, v2.0!". Once\nyou'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. Under the hood, this is done by\ntaking advantage of Terraform's <code>create_before_destroy</code> lifecycle property. This is the same strategy used by HashiCorp\nfor it's own rolling deployments, as <a href=\"https://groups.google.com/forum/#!msg/terraform-tool/7Gdhv1OAc80/iNQ93riiLwAJ\" class=\"preview__body--description--blue\" target=\"_blank\">as described by Paul Hinze\nhere</a>.</p>\n","repoName":"module-asg","repoRef":"v0.14.1","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-rolling-deploy","title":"Repo Browser: Auto Scaling Group (stateless)","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}