This folder shows an example of Terraform code to deploy a Nomad cluster co-located
with a Consul cluster in AWS (if you want to run Nomad and Consul
on separate clusters, see the nomad-consul-separate-cluster example
instead). The cluster consists of two Auto Scaling Groups (ASGs): one with a small number of Nomad and Consul server
nodes, which are responsible for being part of the consensus
protocol, and one with a larger number of Nomad and Consul
client nodes, which are used to run jobs:
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. If you built a custom AMI, put the AMI ID into the ami_id variable. Otherwise, one of our
public example AMIs will be used by default. These AMIs are great for learning/experimenting, but are NOT
recommended for production use.
Run terraform init.
Run terraform apply.
Run the nomad-examples-helper.sh script to print out
the IP addresses of the Nomad servers and some example commands you can run to interact with the cluster:
../nomad-examples-helper/nomad-examples-helper.sh.
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":"20968ed882b09a03245770f84b523b73cd64df78"}]},{"name":".gitignore","path":".gitignore","sha":"6c4ebe4426586b7febbaba178294ef59b8272c05"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"4be01a6334d39aa5bf6abe6baae701f5e2a8c5ac"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","sha":"4c6520097a38c2b63e7a91e20a4c06f8005e6fe4"},{"name":"LICENSE","path":"LICENSE","sha":"7a4a3ea2424c09fbe48d455aed1eaa94d9124835"},{"name":"NOTICE","path":"NOTICE","sha":"4653ef2dace926e046f74ab82c82647558c7e94f"},{"name":"README.md","path":"README.md","sha":"48583f19e9257d330a8d9e6f041b101932490d56"},{"name":"_ci","children":[{"name":"publish-amis-in-new-account.md","path":"_ci/publish-amis-in-new-account.md","sha":"3182a0a90775f7bb9622c037196ac2a1f15e455d"},{"name":"publish-amis.sh","path":"_ci/publish-amis.sh","sha":"6902cb1e3d7624ecc91096bcd48c5c91e248c653"}]},{"name":"_docs","children":[{"name":"amazon-linux-ami-list.md","path":"_docs/amazon-linux-ami-list.md","sha":"6607a70497e27d57222552281825053783ad7bb2"},{"name":"architecture-nomad-consul-colocated.png","path":"_docs/architecture-nomad-consul-colocated.png","sha":"438a8b71d1afdc7f91065b910e9de2d6d7d9517c"},{"name":"architecture-nomad-consul-separate.png","path":"_docs/architecture-nomad-consul-separate.png","sha":"df28d183fb8090fabc457ee56f3fb43ded6a5b13"},{"name":"architecture.png","path":"_docs/architecture.png","sha":"e539a77e88af6849d0893be35a8c5b5270edb195"},{"name":"nomad-icon.png","path":"_docs/nomad-icon.png","sha":"193298e1f719d6fb51513d0d9631dafaa17cfaf3"},{"name":"ubuntu16-ami-list.md","path":"_docs/ubuntu16-ami-list.md","sha":"4c1af1d6d863e0e6120520b65d823ee2ae2e2079"}]},{"name":"core-concepts.md","path":"core-concepts.md","sha":"314e6e4769a0316adbce0ff39196f1821544c9ce"},{"name":"examples","children":[{"name":"nomad-consul-ami","children":[{"name":"README.md","path":"examples/nomad-consul-ami/README.md","sha":"11e1163c9c96fb01ebc0578d49f6a58a5d6f5887"},{"name":"nomad-consul-docker.json","path":"examples/nomad-consul-ami/nomad-consul-docker.json","sha":"65223c3b4c561006a0623901eb8c25ea87918590"},{"name":"nomad-consul.json","path":"examples/nomad-consul-ami/nomad-consul.json","sha":"7b2049a6be8a560056543c3e95aa340157f56f92"},{"name":"setup_amazon-linux-2.sh","path":"examples/nomad-consul-ami/setup_amazon-linux-2.sh","sha":"afa4e86365348ab91616f08d3fae0a28c64e158f"},{"name":"setup_nomad_consul.sh","path":"examples/nomad-consul-ami/setup_nomad_consul.sh","sha":"c4e68a5affa34caab8e4197028dfc1970c33da6e"},{"name":"setup_ubuntu.sh","path":"examples/nomad-consul-ami/setup_ubuntu.sh","sha":"81268f86b1ccf5a567ec913dd1dbbe3b3868ad93"}]},{"name":"nomad-consul-separate-cluster","children":[{"name":"README.md","path":"examples/nomad-consul-separate-cluster/README.md","sha":"4f8ee73c20f575cb86ed28fb05840d093e6f2f15"},{"name":"main.tf","path":"examples/nomad-consul-separate-cluster/main.tf","sha":"c29c23f9c54e171826309ed3f00a13552b3c6147"},{"name":"outputs.tf","path":"examples/nomad-consul-separate-cluster/outputs.tf","sha":"fab958b55d52594d98df8391c4282e5c4c1f008a"},{"name":"user-data-consul-server.sh","path":"examples/nomad-consul-separate-cluster/user-data-consul-server.sh","sha":"659e77d66aa4140f776cfbeb9e71f1a874b00682"},{"name":"user-data-nomad-client.sh","path":"examples/nomad-consul-separate-cluster/user-data-nomad-client.sh","sha":"c52069299ee4fe73fbd9cd5d4f48be8ef6a35b3d"},{"name":"user-data-nomad-server.sh","path":"examples/nomad-consul-separate-cluster/user-data-nomad-server.sh","sha":"1b99ff7d6b56999da42c04d5405e81c738214af1"},{"name":"variables.tf","path":"examples/nomad-consul-separate-cluster/variables.tf","sha":"78d0882b72b80b9b8eea67d4950e15b826647e1d"}]},{"name":"nomad-examples-helper","children":[{"name":"README.md","path":"examples/nomad-examples-helper/README.md","sha":"4b42111e7abf289798df0c62847edc722bcd6256"},{"name":"example.nomad","path":"examples/nomad-examples-helper/example.nomad","sha":"63958e3d491757da48a72255ec3b8882302ba33e"},{"name":"nomad-examples-helper.sh","path":"examples/nomad-examples-helper/nomad-examples-helper.sh","sha":"7f5f10afb2331d88268d53fe7e7d8deb0585a8db"}]},{"name":"root-example","children":[{"name":"README.md","path":"examples/root-example/README.md","sha":"9c2e4ffd4e0ffcf6e4d4a6d31583205251a6c67d","toggled":true},{"name":"user-data-client.sh","path":"examples/root-example/user-data-client.sh","sha":"d6bac10fb2bb654d3255052d863ab19c9cdd41bc"},{"name":"user-data-server.sh","path":"examples/root-example/user-data-server.sh","sha":"109bdeb1f8df56b35d6bf1a6e5346cae4aca61f5"}],"toggled":true}],"toggled":true},{"name":"main.tf","path":"main.tf","sha":"5b21e3855375c578f5946961181efd25ad8426bc"},{"name":"modules","children":[{"name":"install-nomad","children":[{"name":"README.md","path":"modules/install-nomad/README.md","sha":"dd57dafd1f1e74403d957ed18a3e4166c36b64b6"},{"name":"install-nomad","path":"modules/install-nomad/install-nomad","sha":"71bb18f1e4d9bd57885feaafcc76a15032d3c1bb"}]},{"name":"nomad-cluster","children":[{"name":"README.md","path":"modules/nomad-cluster/README.md","sha":"c14efc5da8641e203d3704a998591da9e99511d6"},{"name":"main.tf","path":"modules/nomad-cluster/main.tf","sha":"e46194c1170b25016dd4ed1dfb068af1583d47a6"},{"name":"outputs.tf","path":"modules/nomad-cluster/outputs.tf","sha":"341778300126873e11e2cf9d964bccd927c2644e"},{"name":"variables.tf","path":"modules/nomad-cluster/variables.tf","sha":"b0293a8dc30f988ca63af42e06e7a7cefaabde91"}]},{"name":"nomad-security-group-rules","children":[{"name":"README.md","path":"modules/nomad-security-group-rules/README.md","sha":"c35eab862bdd870569408a9ad55e8abb6894e4fe"},{"name":"main.tf","path":"modules/nomad-security-group-rules/main.tf","sha":"50e1045b13b51852e1a410ea5d9cd3150eff1a48"},{"name":"variables.tf","path":"modules/nomad-security-group-rules/variables.tf","sha":"a3d9d4b0b2abcce058d41b61b099fa115a7babd3"}]},{"name":"run-nomad","children":[{"name":"README.md","path":"modules/run-nomad/README.md","sha":"e93d111550cf5b488ba783aa01679fb5bee6c5e3"},{"name":"run-nomad","path":"modules/run-nomad/run-nomad","sha":"b490d5ade01fd497409de0dad7a653f0b830235c"}]}]},{"name":"outputs.tf","path":"outputs.tf","sha":"f3efe59a6784255e79e0a7a77cf4b4ce2461278f"},{"name":"test","children":[{"name":"Gopkg.lock","path":"test/Gopkg.lock","sha":"fc3214f34d7c2f6d5d1c1ab6f9ecf1a85bfb06f8"},{"name":"Gopkg.toml","path":"test/Gopkg.toml","sha":"a84c6ed7e5bfce6f72e9e08666f1665af01a3f84"},{"name":"README.md","path":"test/README.md","sha":"874818e6da7a9c0c9338edde0c27fa3f8a3b3d05"},{"name":"aws_helpers.go","path":"test/aws_helpers.go","sha":"c7b6601bf58485e5deddbb1e17f433b0c12c9dae"},{"name":"nomad_consul_cluster_colocated_test.go","path":"test/nomad_consul_cluster_colocated_test.go","sha":"b346dfaa3bbdf8bccd910e8fe6423a83efc16be0"},{"name":"nomad_consul_cluster_separate_test.go","path":"test/nomad_consul_cluster_separate_test.go","sha":"3de7c5e989f2989cf7d1e3cbeec94d99871a75fa"},{"name":"nomad_helpers.go","path":"test/nomad_helpers.go","sha":"1750e3d729d429c9062fde804f4a66a0d514d22d"},{"name":"terratest_helpers.go","path":"test/terratest_helpers.go","sha":"f6e176e37bc9ce4c5322834a0325bc9ff1b836b4"}]},{"name":"variables.tf","path":"variables.tf","sha":"0941f7c8577a1db5d7fdafbd274deb87813c0ca9"}]},"detailsContent":"<h1 class=\"preview__body--title\" id=\"nomad-and-consul-co-located-cluster-example\">Nomad and Consul Co-located Cluster Example</h1><div class=\"preview__body--border\"></div><p>This folder shows an example of Terraform code to deploy a <a href=\"https://www.nomadproject.io/\" class=\"preview__body--description--blue\" target=\"_blank\">Nomad</a> cluster co-located\nwith a <a href=\"https://www.consul.io/\" class=\"preview__body--description--blue\" target=\"_blank\">Consul</a> cluster in <a href=\"https://aws.amazon.com/\" class=\"preview__body--description--blue\" target=\"_blank\">AWS</a> (if you want to run Nomad and Consul\non separate clusters, see the <a href=\"/repos/v0.10.0/terraform-aws-nomad/examples/nomad-consul-separate-cluster\" class=\"preview__body--description--blue\">nomad-consul-separate-cluster example</a>\ninstead). The cluster consists of two Auto Scaling Groups (ASGs): one with a small number of Nomad and Consul server\nnodes, which are responsible for being part of the <a href=\"https://www.nomadproject.io/docs/internals/consensus.html\" class=\"preview__body--description--blue\" target=\"_blank\">consensus\nprotocol</a>, and one with a larger number of Nomad and Consul\nclient nodes, which are used to run jobs:</p>\n<p><img src=\"/repos/images/v0.10.0/terraform-aws-nomad/_docs/architecture-nomad-consul-colocated.png\" alt=\"Nomad architecture\" class=\"preview__body--diagram\"></p>\n<p>You will need to create an <a href=\"http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html\" class=\"preview__body--description--blue\" target=\"_blank\">Amazon Machine Image (AMI)</a>\nthat has Nomad and Consul installed, which you can do using the <a href=\"/repos/v0.10.0/terraform-aws-nomad/examples/nomad-consul-ami\" class=\"preview__body--description--blue\">nomad-consul-ami example</a>).</p>\n<p>For more info on how the Nomad cluster works, check out the <a href=\"/repos/v0.10.0/terraform-aws-nomad/modules/nomad-cluster\" class=\"preview__body--description--blue\">nomad-cluster</a> documentation.</p>\n<h2 class=\"preview__body--subtitle\" id=\"quick-start\">Quick start</h2>\n<p>To deploy a Nomad Cluster:</p>\n<ol>\n<li><code>git clone</code> this repo to your computer.</li>\n<li>Optional: build a Nomad and Consul AMI. See the <a href=\"/repos/v0.10.0/terraform-aws-nomad/examples/nomad-consul-ami\" class=\"preview__body--description--blue\">nomad-consul-ami\nexample</a> documentation for\ninstructions. Make sure to note down the ID of the AMI.</li>\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. If you built a custom AMI, put the AMI ID into the <code>ami_id</code> variable. Otherwise, one of our\npublic example AMIs will be used by default. These AMIs are great for learning/experimenting, but are NOT\nrecommended for production use.</li>\n<li>Run <code>terraform init</code>.</li>\n<li>Run <code>terraform apply</code>.</li>\n<li>Run the <a href=\"/repos/v0.10.0/terraform-aws-nomad/examples/nomad-examples-helper/nomad-examples-helper.sh\" class=\"preview__body--description--blue\">nomad-examples-helper.sh script</a> to print out\nthe IP addresses of the Nomad servers and some example commands you can run to interact with the cluster:\n<code>../nomad-examples-helper/nomad-examples-helper.sh</code>.</li>\n</ol>\n","repoName":"terraform-aws-nomad","repoRef":"v0.6.0","serviceDescriptor":{"serviceName":"HashiCorp Nomad","serviceRepoName":"terraform-aws-nomad","serviceRepoOrg":"hashicorp","cloudProviders":["aws"],"description":"Deploy a Nomad cluster. Supports automatic bootstrapping, discovery of Consul servers, automatic recovery of failed servers.","imageUrl":"nomad.png","licenseType":"open-source","technologies":["Terraform","Bash"],"compliance":[],"tags":[""]},"serviceCategoryName":"Docker orchestration","fileName":"README.md","filePath":"/examples/root-example","title":"Repo Browser: HashiCorp Nomad","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}