These AMIs will have Consul installed and configured to automatically join a cluster during
boot-up. They also have Dnsmasq installed and configured to use
Consul for DNS lookups of the .consul domain (e.g. foo.service.consul) (see registering
services for instructions on how to register your services
in Consul). To see how to deploy this AMI, check out the consul-cluster example.
Configure your AWS credentials using one of the options supported by the AWS
SDK. Usually, the easiest option is to
set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
Update the variables section of the consul.json Packer template to configure the AWS region, Consul version, and
Dnsmasq version you wish to use. If you want to install Consul Enterprise, skip the version variable and instead set
the download_url to the full url that points to the consul enterprise zipped package.
Run packer build consul.json.
When the build finishes, it will output the IDs of the new AMIs. To see how to deploy one of these AMIs, check out the
consul-cluster example.
Creating your own Packer template for production usage
When creating your own Packer template for production usage, you can copy the example in this folder more or less
exactly, except for one change: we recommend replacing the file provisioner with a call to git clone in the shell
provisioner. Instead of:
NOTE: Amazon Linux 2 users will need to install Git first.
You should replace <MODULE_VERSION> in the code above with the version of this module that you want to use (see
the Releases Page for all available versions). That's because for production usage, you should always
use a fixed, known version of this Module, downloaded from the official Git repo. On the other hand, when you're
just experimenting with the Module, it's OK to use a local checkout of the Module, uploaded from your own
computer.
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":"7cd21b1bd9fdbf5101b175a71ed1f83656945145"}]},{"name":".gitignore","path":".gitignore","sha":"866fba08567d4c22683017421abdb60f985833f2"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"5949dbc0fa6d4dd6610575e3c878c353d92da44a"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","sha":"bdfb309d7ff6bb05ffc1ea9453604805c022d13b"},{"name":"LICENSE","path":"LICENSE","sha":"7a4a3ea2424c09fbe48d455aed1eaa94d9124835"},{"name":"NOTICE","path":"NOTICE","sha":"9f6aed2a3cc04e4ef63c90448b2f0ac07378b270"},{"name":"README.md","path":"README.md","sha":"2f70405c336d19685c495170b103691ed604b300"},{"name":"_ci","children":[{"name":"publish-amis-in-new-account.md","path":"_ci/publish-amis-in-new-account.md","sha":"5b5daa55c3e36c1c4739471be92ccb53995f9783"},{"name":"publish-amis.sh","path":"_ci/publish-amis.sh","sha":"e575763ccd2158e49f3b5c53aad2b8f197992260"}]},{"name":"_docs","children":[{"name":"amazon-linux-ami-list.md","path":"_docs/amazon-linux-ami-list.md","sha":"fc523855ab81d4958d77179a64e3bb7d10782664"},{"name":"architecture.png","path":"_docs/architecture.png","sha":"539fece6e8a9fd7a56245e2b63e6640a1e0591ef"},{"name":"consul-ui-screenshot.png","path":"_docs/consul-ui-screenshot.png","sha":"622c7e70d3ab805b1bb8e27e474ff8243d4bc994"},{"name":"package-managers.md","path":"_docs/package-managers.md","sha":"f382b6997245e03adba61c02346519a70ee016d4"},{"name":"ubuntu16-ami-list.md","path":"_docs/ubuntu16-ami-list.md","sha":"706e3fd289f3aa1ddd4ef9c8555ab36d3b550ed9"}]},{"name":"examples","children":[{"name":"README.md","path":"examples/README.md","sha":"8eca7399ca356c90a307206147362bc35588179c"},{"name":"consul-ami","children":[{"name":"README.md","path":"examples/consul-ami/README.md","sha":"2b71fb3d7a4cd4176ece97a50a859e8106ebcd5a","toggled":true},{"name":"consul.json","path":"examples/consul-ami/consul.json","sha":"cdfc5de67e013670d765c1ee3a3935e4cebac631"}],"toggled":true},{"name":"consul-examples-helper","children":[{"name":"README.md","path":"examples/consul-examples-helper/README.md","sha":"296f6878fd49edb27d6a6b62fa4119b6a407ba26"},{"name":"consul-examples-helper.sh","path":"examples/consul-examples-helper/consul-examples-helper.sh","sha":"fa9beba847bff2270703632a526ffbeb2070974c"}]},{"name":"example-with-custom-asg-role","children":[{"name":"README.md","path":"examples/example-with-custom-asg-role/README.md","sha":"fa1fbb9d7416fa96f13afb6b82664bbe1638ea3f"},{"name":"main.tf","path":"examples/example-with-custom-asg-role/main.tf","sha":"ed53539e6440f8b9a0b951c78b90270409daf07b"},{"name":"outputs.tf","path":"examples/example-with-custom-asg-role/outputs.tf","sha":"347e121901e654df4aaabe434af02c7ced60c051"},{"name":"user-data-client.sh","path":"examples/example-with-custom-asg-role/user-data-client.sh","sha":"fd0158b0287de6bf2a6956718c7aa802076fe489"},{"name":"user-data-server.sh","path":"examples/example-with-custom-asg-role/user-data-server.sh","sha":"c78ebc05584513fa04f44d44ef2b9d17c98e2ea6"},{"name":"variables.tf","path":"examples/example-with-custom-asg-role/variables.tf","sha":"a7f5025a21c9252bdb592a852bf485a426bc9347"}]},{"name":"example-with-encryption","children":[{"name":"README.md","path":"examples/example-with-encryption/README.md","sha":"0f2de7374cf63ee0b18cae4b960b85ec88403866"},{"name":"main.tf","path":"examples/example-with-encryption/main.tf","sha":"90b3095339a0ac6234c4165412534025ffe5e403"},{"name":"outputs.tf","path":"examples/example-with-encryption/outputs.tf","sha":"347e121901e654df4aaabe434af02c7ced60c051"},{"name":"packer","children":[{"name":"README.md","path":"examples/example-with-encryption/packer/README.md","sha":"b7b8ca11120c5f69565dab81eeeed659223538e9"},{"name":"ca.crt.pem","path":"examples/example-with-encryption/packer/ca.crt.pem","sha":"c41779f19be6d742d10be51d80c29aa5d41a660c"},{"name":"consul-with-certs.json","path":"examples/example-with-encryption/packer/consul-with-certs.json","sha":"fc2340056320869cd4ca98a10157e8d5ece038f7"},{"name":"consul.crt.pem","path":"examples/example-with-encryption/packer/consul.crt.pem","sha":"4a4ea11b89006f41fe2cb8b707d62463bb739184"},{"name":"consul.key.pem","path":"examples/example-with-encryption/packer/consul.key.pem","sha":"b7de428c63382b087007a236602797cc0a0a45f5"}]},{"name":"user-data-client.sh","path":"examples/example-with-encryption/user-data-client.sh","sha":"2ab3735d96777ce9324bc55f7be29c338ef0c1bb"},{"name":"user-data-server.sh","path":"examples/example-with-encryption/user-data-server.sh","sha":"5e97fc02da696b348ee26a2c1803bf7e3e018c79"},{"name":"variables.tf","path":"examples/example-with-encryption/variables.tf","sha":"2f741e848bd95f3d7798f4fd52021ddfdb30d3bd"}]},{"name":"root-example","children":[{"name":"README.md","path":"examples/root-example/README.md","sha":"6c562cb22c28cc5e35b5a21a94b66d6af9101081"},{"name":"user-data-client.sh","path":"examples/root-example/user-data-client.sh","sha":"fd0158b0287de6bf2a6956718c7aa802076fe489"},{"name":"user-data-server.sh","path":"examples/root-example/user-data-server.sh","sha":"c78ebc05584513fa04f44d44ef2b9d17c98e2ea6"}]}],"toggled":true},{"name":"main.tf","path":"main.tf","sha":"ce92b8206ed5e2be29d5e877235dca412bfdb47a"},{"name":"modules","children":[{"name":"README.md","path":"modules/README.md","sha":"8eca7399ca356c90a307206147362bc35588179c"},{"name":"consul-client-security-group-rules","children":[{"name":"README.md","path":"modules/consul-client-security-group-rules/README.md","sha":"777b679a73df3d5c96fb584176e91449c3a72615"},{"name":"main.tf","path":"modules/consul-client-security-group-rules/main.tf","sha":"a90c7a072a8d939094a0171f03520b22986a72d2"},{"name":"variables.tf","path":"modules/consul-client-security-group-rules/variables.tf","sha":"c9c25d00fdc683748570ba5e2ee718c9af8e6697"}]},{"name":"consul-cluster","children":[{"name":"README.md","path":"modules/consul-cluster/README.md","sha":"b9a3c55973ef27b0022f5eda05840f7cc65cea03"},{"name":"main.tf","path":"modules/consul-cluster/main.tf","sha":"139789c8b623fd4523b9eb3ab15a57b48246d1e4"},{"name":"outputs.tf","path":"modules/consul-cluster/outputs.tf","sha":"a980d658e1be410a013a7e7febcc38a49899ffdc"},{"name":"variables.tf","path":"modules/consul-cluster/variables.tf","sha":"762180c029cf615583e163eaf5f7e91b00dc67c3"}]},{"name":"consul-iam-policies","children":[{"name":"README.md","path":"modules/consul-iam-policies/README.md","sha":"7725295fbdbf3d2fe881796e63074e3215854f5f"},{"name":"main.tf","path":"modules/consul-iam-policies/main.tf","sha":"815931541fb65a51755fd053e0e5f264eaf14111"},{"name":"variables.tf","path":"modules/consul-iam-policies/variables.tf","sha":"1bda7959f19ea4ab20108ec9fb8802036bfd22fd"}]},{"name":"consul-security-group-rules","children":[{"name":"README.md","path":"modules/consul-security-group-rules/README.md","sha":"315155181f5b42ff0fc6f16b86eaa930811366fe"},{"name":"main.tf","path":"modules/consul-security-group-rules/main.tf","sha":"2874ce4405e19fdb2d334911a2dc8098a8482b21"},{"name":"variables.tf","path":"modules/consul-security-group-rules/variables.tf","sha":"b9f5fe2bd11994d2d8eeb932db8650b43c47add1"}]},{"name":"install-consul","children":[{"name":"README.md","path":"modules/install-consul/README.md","sha":"1d451e16e08a4f6259cb3ee643e39d6171d5a4d9"},{"name":"install-consul","path":"modules/install-consul/install-consul","sha":"d1505e023bf0b9f4c779fa1f1b089879d6d864ba"}]},{"name":"install-dnsmasq","children":[{"name":"README.md","path":"modules/install-dnsmasq/README.md","sha":"80f0d44b7c7e916821ec8fd624d624f16eb2cb20"},{"name":"install-dnsmasq","path":"modules/install-dnsmasq/install-dnsmasq","sha":"b74b5307696bf4fbaa94192ba0e18ceccb0d947f"}]},{"name":"run-consul","children":[{"name":"README.md","path":"modules/run-consul/README.md","sha":"0b990a784db0354a8bd0401c8a64033765e01c05"},{"name":"run-consul","path":"modules/run-consul/run-consul","sha":"56c5054fe13c47a92fce0b8cfac4dcc510c52a34"}]},{"name":"setup-systemd-resolved","children":[{"name":"README.md","path":"modules/setup-systemd-resolved/README.md","sha":"92a5fb39c0eabefcfc84f20ebe7a994156774fc0"},{"name":"setup-systemd-resolved","path":"modules/setup-systemd-resolved/setup-systemd-resolved","sha":"d81c2bf0966dd1d1a1a97fc24c5862048b05b2cd"}]}]},{"name":"outputs.tf","path":"outputs.tf","sha":"347e121901e654df4aaabe434af02c7ced60c051"},{"name":"test","children":[{"name":"Gopkg.lock","path":"test/Gopkg.lock","sha":"880e78457fe502e2150412e5f511aaf0daa32d54"},{"name":"Gopkg.toml","path":"test/Gopkg.toml","sha":"9f0c0396c0addc41d8dcd195de8d9b4e63c81b18"},{"name":"README.md","path":"test/README.md","sha":"874818e6da7a9c0c9338edde0c27fa3f8a3b3d05"},{"name":"aws_helpers.go","path":"test/aws_helpers.go","sha":"867034abaf29d9c6e641daa9c4a51a8286ffb0ed"},{"name":"consul_cluster_test.go","path":"test/consul_cluster_test.go","sha":"179f09e027f87ee8b94debdd0a01a610708cc4b4"},{"name":"consul_cluster_with_custom_asg_role_test.go","path":"test/consul_cluster_with_custom_asg_role_test.go","sha":"96595f03771d0bb27d07ac9739284a9190be3530"},{"name":"consul_cluster_with_encryption_test.go","path":"test/consul_cluster_with_encryption_test.go","sha":"2149dd3a2eb3a0fbab52b17db8d0c18970df5d72"},{"name":"consul_enterprise_test.go","path":"test/consul_enterprise_test.go","sha":"6632f0529b899a314093b489335233108af86d21"},{"name":"consul_helpers.go","path":"test/consul_helpers.go","sha":"6c3cf0f8615f34d032114161d1fb0f580e930c9f"},{"name":"terratest_helpers.go","path":"test/terratest_helpers.go","sha":"cfe73dfea67dc40877e7df715c73dda501e614fd"}]},{"name":"variables.tf","path":"variables.tf","sha":"a2ab5424fac8bd42c8e48a9073ec2e1a403d5db3"}]},"detailsContent":"<h1 class=\"preview__body--title\" id=\"consul-ami\">Consul AMI</h1><div class=\"preview__body--border\"></div><p>This folder shows an example of how to use the <a href=\"/repos/v0.7.9/terraform-aws-consul/modules/install-consul\" class=\"preview__body--description--blue\">install-consul</a> and\neither <a href=\"/repos/v0.7.9/terraform-aws-consul/modules/install-dnsmasq\" class=\"preview__body--description--blue\">install-dnsmasq</a> for Ubuntu 16.04 and Amazon Linux 2 or <a href=\"/repos/v0.7.9/terraform-aws-consul/modules/setup-systemd-resolved\" class=\"preview__body--description--blue\">setup-systemd-resolved</a> for Ubuntu 18.04 modules with <a href=\"https://www.packer.io/\" class=\"preview__body--description--blue\" target=\"_blank\">Packer</a> to create <a href=\"http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html\" class=\"preview__body--description--blue\" target=\"_blank\">Amazon Machine\nImages (AMIs)</a> that have Consul and Dnsmasq installed on\ntop of:</p>\n<ol>\n<li>Ubuntu 16.04</li>\n<li>Ubuntu 18.04</li>\n<li>Amazon Linux 2</li>\n</ol>\n<p>These AMIs will have <a href=\"https://www.consul.io/\" class=\"preview__body--description--blue\" target=\"_blank\">Consul</a> installed and configured to automatically join a cluster during\nboot-up. They also have <a href=\"http://www.thekelleys.org.uk/dnsmasq/doc.html\" class=\"preview__body--description--blue\" target=\"_blank\">Dnsmasq</a> installed and configured to use\nConsul for DNS lookups of the <code>.consul</code> domain (e.g. <code>foo.service.consul</code>) (see <a href=\"https://www.consul.io/intro/getting-started/services.html\" class=\"preview__body--description--blue\" target=\"_blank\">registering\nservices</a> for instructions on how to register your services\nin Consul). To see how to deploy this AMI, check out the <a href=\"/repos/v0.7.9/terraform-aws-consul/examples/root-example\" class=\"preview__body--description--blue\">consul-cluster example</a>.</p>\n<p>For more info on Consul installation and configuration, check out the\n<a href=\"/repos/v0.7.9/terraform-aws-consul/modules/install-consul\" class=\"preview__body--description--blue\">install-consul</a> and <a href=\"/repos/v0.7.9/terraform-aws-consul/modules/install-dnsmasq\" class=\"preview__body--description--blue\">install-dnsmasq</a> for Ubuntu 16.04 and Amazon Linux 2 or <a href=\"/repos/v0.7.9/terraform-aws-consul/modules/setup-systemd-resolved\" class=\"preview__body--description--blue\">setup-systemd-resolved</a> for Ubuntu 18.04 documentation.</p>\n<h2 class=\"preview__body--subtitle\" id=\"dependencies\">Dependencies</h2>\n<ol>\n<li>AWSCLI must be installed on the base AMI in order for run-consul to run</li>\n<li>Git CAN be installed on the base AMI if you want to use clone commands</li>\n</ol>\n<h2 class=\"preview__body--subtitle\" id=\"quick-start\">Quick start</h2>\n<p>To build the Consul AMI:</p>\n<ol>\n<li><code>git clone</code> this repo to your computer.</li>\n<li>Install <a href=\"https://www.packer.io/\" class=\"preview__body--description--blue\" target=\"_blank\">Packer</a>.</li>\n<li>Configure your AWS credentials using one of the <a href=\"http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html\" class=\"preview__body--description--blue\" target=\"_blank\">options supported by the AWS\nSDK</a>. Usually, the easiest option is to\nset the <code>AWS_ACCESS_KEY_ID</code> and <code>AWS_SECRET_ACCESS_KEY</code> environment variables.</li>\n<li>Update the <code>variables</code> section of the <code>consul.json</code> Packer template to configure the AWS region, Consul version, and\nDnsmasq version you wish to use. If you want to install Consul Enterprise, skip the version variable and instead set\nthe <code>download_url</code> to the full url that points to the consul enterprise zipped package.</li>\n<li>Run <code>packer build consul.json</code>.</li>\n</ol>\n<p>When the build finishes, it will output the IDs of the new AMIs. To see how to deploy one of these AMIs, check out the\n<a href=\"/repos/v0.7.9/terraform-aws-consul/examples/root-example\" class=\"preview__body--description--blue\">consul-cluster example</a>.</p>\n<h2 class=\"preview__body--subtitle\" id=\"creating-your-own-packer-template-for-production-usage\">Creating your own Packer template for production usage</h2>\n<p>When creating your own Packer template for production usage, you can copy the example in this folder more or less\nexactly, except for one change: we recommend replacing the <code>file</code> provisioner with a call to <code>git clone</code> in the <code>shell</code>\nprovisioner. Instead of:</p>\n<pre>{\n <span class=\"hljs-attr\">\"provisioners\"</span>: [{\n <span class=\"hljs-attr\">\"type\"</span>: <span class=\"hljs-string\">\"file\"</span>,\n <span class=\"hljs-attr\">\"source\"</span>: <span class=\"hljs-string\">\"{{template_dir}}/../../../terraform-aws-consul\"</span>,\n <span class=\"hljs-attr\">\"destination\"</span>: <span class=\"hljs-string\">\"/tmp\"</span>\n },{\n <span class=\"hljs-attr\">\"type\"</span>: <span class=\"hljs-string\">\"shell\"</span>,\n <span class=\"hljs-attr\">\"inline\"</span>: [\n <span class=\"hljs-string\">\"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}}\"</span>\n ],\n <span class=\"hljs-attr\">\"pause_before\"</span>: <span class=\"hljs-string\">\"30s\"</span>\n },{\n <span class=\"hljs-attr\">\"type\"</span>: <span class=\"hljs-string\">\"shell\"</span>,\n <span class=\"hljs-attr\">\"only\"</span>: [<span class=\"hljs-string\">\"ubuntu16-ami\"</span>, <span class=\"hljs-string\">\"amazon-linux-2-ami\"</span>],\n <span class=\"hljs-attr\">\"inline\"</span>: [\n <span class=\"hljs-string\">\"/tmp/terraform-aws-consul/modules/install-dnsmasq/install-dnsmasq\"</span>\n ],\n <span class=\"hljs-attr\">\"pause_before\"</span>: <span class=\"hljs-string\">\"30s\"</span>\n },{\n <span class=\"hljs-attr\">\"type\"</span>: <span class=\"hljs-string\">\"shell\"</span>,\n <span class=\"hljs-attr\">\"only\"</span>: [<span class=\"hljs-string\">\"ubuntu18-ami\"</span>],\n <span class=\"hljs-attr\">\"inline\"</span>: [\n <span class=\"hljs-string\">\"/tmp/terraform-aws-consul/modules/setup-systemd-resolved/setup-systemd-resolved\"</span>\n ],\n <span class=\"hljs-attr\">\"pause_before\"</span>: <span class=\"hljs-string\">\"30s\"</span>\n }]\n}\n</pre>\n<p>Your code should look more like this:</p>\n<pre>{\n <span class=\"hljs-attr\">\"provisioners\"</span>: [{\n <span class=\"hljs-attr\">\"type\"</span>: <span class=\"hljs-string\">\"shell\"</span>,\n <span class=\"hljs-attr\">\"inline\"</span>: [\n <span class=\"hljs-string\">\"git clone --branch <MODULE_VERSION> https://github.com/hashicorp/terraform-aws-consul.git /tmp/terraform-aws-consul\"</span>,\n <span class=\"hljs-string\">\"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}}\"</span>\n ],\n <span class=\"hljs-attr\">\"pause_before\"</span>: <span class=\"hljs-string\">\"30s\"</span>\n },{\n <span class=\"hljs-attr\">\"type\"</span>: <span class=\"hljs-string\">\"shell\"</span>,\n <span class=\"hljs-attr\">\"only\"</span>: [<span class=\"hljs-string\">\"ubuntu16-ami\"</span>, <span class=\"hljs-string\">\"amazon-linux-2-ami\"</span>],\n <span class=\"hljs-attr\">\"inline\"</span>: [\n <span class=\"hljs-string\">\"/tmp/terraform-aws-consul/modules/install-dnsmasq/install-dnsmasq\"</span>\n ],\n <span class=\"hljs-attr\">\"pause_before\"</span>: <span class=\"hljs-string\">\"30s\"</span>\n },{\n <span class=\"hljs-attr\">\"type\"</span>: <span class=\"hljs-string\">\"shell\"</span>,\n <span class=\"hljs-attr\">\"only\"</span>: [<span class=\"hljs-string\">\"ubuntu18-ami\"</span>],\n <span class=\"hljs-attr\">\"inline\"</span>: [\n <span class=\"hljs-string\">\"/tmp/terraform-aws-consul/modules/setup-systemd-resolved/setup-systemd-resolved\"</span>\n ],\n <span class=\"hljs-attr\">\"pause_before\"</span>: <span class=\"hljs-string\">\"30s\"</span>\n }]\n}\n</pre>\n<p><strong>NOTE:</strong> Amazon Linux 2 users will need to install Git first.</p>\n<p>You should replace <code><MODULE_VERSION></code> in the code above with the version of this module that you want to use (see\nthe <a href=\"/repos/v0.7.9/terraform-aws-consul/releases\" class=\"preview__body--description--blue\">Releases Page</a> for all available versions). That's because for production usage, you should always\nuse a fixed, known version of this Module, downloaded from the official Git repo. On the other hand, when you're\njust experimenting with the Module, it's OK to use a local checkout of the Module, uploaded from your own\ncomputer.</p>\n","repoName":"terraform-aws-consul","repoRef":"v0.7.4","serviceDescriptor":{"serviceName":"HashiCorp Consul","serviceRepoName":"terraform-aws-consul","serviceRepoOrg":"hashicorp","cloudProviders":["aws"],"description":"Deploy a Consul cluster. Supports automatic bootstrapping, DNS, Consul UI, and auto healing.","imageUrl":"consul.png","licenseType":"open-source","technologies":["Terraform","Bash"],"compliance":[],"tags":[""]},"serviceCategoryName":"Service Mesh","fileName":"README.md","filePath":"/examples/consul-ami","title":"Repo Browser: HashiCorp Consul","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}