Consul for Google Cloud Platform (GCP)
This repo contains a Terraform Module for how to deploy a Consul cluster on GCP using Terraform. Consul is a distributed, highly-available tool that you can use for service discovery and key/value storage. A Consul cluster typically includes a small number of server nodes, which are responsible for being part of the consensus quorum, and a larger number of client nodes, which you typically run alongside your apps:
How to use this Module
Each Module has the following folder structure:
- modules: This folder contains the reusable code for this Module, broken down into one or more submodules.
- examples: This folder contains examples of how to use the submodules.
- test: Automated tests for the submodules and examples.
To deploy Consul servers using this Module:
-
Create a Consul Image using a Packer template that references the install-consul module. Here is an example Packer template. Note that Google Cloud does not support custom public Images so you must build this Packer template on your own to proceed.
-
Deploy that Image across a Compute Instance Group using the Terraform consul-cluster module and execute the run-consul script with the
--server
flag during boot on each Instance in the Compute Instance Group to form the Consul cluster. Here is an example Terraform configuration to provision a Consul cluster.
To deploy Consul clients using this Module:
- Use the install-consul module to install Consul alongside your application code.
- Before booting your app, execute the run-consul script with
--client
flag. - Your app can now usr the local Consul agent for service discovery and key/value storage.
- Optionally, you can use the install-dnsmasq module to configure Consul as the DNS for a
specific domain (e.g.
.consul
) so that URLs such asfoo.service.consul
resolve automatically to the IP address(es) for a servicefoo
registered in Consul (all other domain names will be continue to resolve using the default resolver on the OS).
What's a Terraform Module?
A Terraform Module refers to a self-contained packages of Terraform configurations that are managed as a group. This repo is a Terraform Module and contains many "submodules" which can be composed together to create useful infrastructure patterns.
Who maintains this Terraform Module?
This Terraform Module is maintained by Gruntwork. If you're looking for help or commercial support, send an email to modules@gruntwork.io. Gruntwork can help with:
- Setup, customization, and support for this Terraform Module.
- Terraform Module for other types of Google Cloud infrastructure.
- Terraform Modules that meet compliance requirements, such as HIPAA.
- Consulting & Training on Google Cloud, AWS, Terraform, and DevOps.
Code included in this Terraform Module:
-
install-consul: This module installs Consul using a Packer template to create a Consul Custom Image.
-
consul-cluster: The module includes Terraform code to deploy a Consul Image across a Managed Compute Instance Group.
-
run-consul: This module includes the scripts to configure and run Consul. It is used by the above Packer module at build-time to set configurations, and by the Terraform module at runtime with the Instance's Startup Script to create the cluster.
-
install-dnsmasq module: Install Dnsmasq and configure it to forward requests for a specific domain to Consul. This allows you to use Consul as a DNS server for URLs such as
foo.service.consul
.
How do I contribute to this Terraform Module?
Contributions are very welcome! Check out the Contribution Guidelines for instructions.
How is this Terraform Module versioned?
This Terraform Module follows the principles of Semantic Versioning. You can find each new release, along with the changelog, in the Releases Page.
During initial development, the major version will be 0 (e.g., 0.x.y
), which indicates the code does not yet have a
stable API. Once we hit 1.0.0
, we will make every effort to maintain a backwards compatible API and use the MAJOR,
MINOR, and PATCH versions on each release to indicate any incompatibilities.
License
This code is released under the Apache 2.0 License. Please see LICENSE and NOTICE for more details.
Copyright © 2017 Gruntwork, Inc.