Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from hashicorp/t12-update
Browse files Browse the repository at this point in the history
Terraform 0.12 update
  • Loading branch information
Etiene authored Jun 26, 2019
2 parents 9adcb5f + 762e746 commit 8f09a3c
Show file tree
Hide file tree
Showing 11 changed files with 643 additions and 290 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ workspace_root: &workspace_root
defaults: &defaults
working_directory: *workspace_root
docker:
- image: gruntwork/circle-ci-test-image-base:latest
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.11

version: 2
jobs:
Expand Down Expand Up @@ -45,4 +45,4 @@ workflows:
- build
- test:
requires:
- build
- build
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_gcp_consul)
![Terraform Version](https://img.shields.io/badge/tf-%3E%3D0.12.0-blue.svg)
# Consul for Google Cloud Platform (GCP)

This repo contains a Terraform Module for how to deploy a [Consul](https://www.consul.io/) cluster on
[GCP](https://cloud.google.com/) using [Terraform](https://www.terraform.io/). Consul is a distributed, highly-available
This repo contains a Terraform Module for how to deploy a [Consul](https://www.consul.io/) cluster on
[GCP](https://cloud.google.com/) using [Terraform](https://www.terraform.io/). 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](https://www.consul.io/docs/internals/consensus.html), and a larger number of client nodes, which you typically
of server nodes, which are responsible for being part of the [consensus
quorum](https://www.consul.io/docs/internals/consensus.html), and a larger number of client nodes, which you typically
run alongside your apps:

![Consul architecture](https://github.com/hashicorp/terraform-google-consul/blob/master/_docs/architecture.png?raw=true)
Expand All @@ -28,36 +29,36 @@ To deploy Consul servers using this Module:
1. Create a Consul Image using a Packer template that references the [install-consul module](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/install-consul).
Here is an [example Packer template](https://github.com/hashicorp/terraform-google-consul/tree/master/examples/consul-image#quick-start). Note that Google Cloud does not support custom
public Images so you must build this Packer template on your own to proceed.
1. Deploy that Image across a Compute Instance Group using the Terraform [consul-cluster module](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/consul-cluster)
and execute the [run-consul script](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/run-consul) with the `--server` flag during boot on each
Instance in the Compute Instance Group to form the Consul cluster. Here is [an example Terraform

1. Deploy that Image across a Compute Instance Group using the Terraform [consul-cluster module](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/consul-cluster)
and execute the [run-consul script](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/run-consul) 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](https://github.com/hashicorp/terraform-google-consul/tree/master/examples/root-example#quick-start) to provision a Consul cluster.

To deploy Consul clients using this Module:

1. Use the [install-consul module](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/install-consul) to install Consul alongside your application code.
1. Before booting your app, execute the [run-consul script](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/run-consul) with `--client` flag.
1. Your app can now usr the local Consul agent for service discovery and key/value storage.
1. Your app can now usr the local Consul agent for service discovery and key/value storage.
1. Optionally, you can use the [install-dnsmasq module](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/install-dnsmasq) to configure Consul as the DNS for a
specific domain (e.g. `.consul`) so that URLs such as `foo.service.consul` resolve automatically to the IP
specific domain (e.g. `.consul`) so that URLs such as `foo.service.consul` resolve automatically to the IP
address(es) for a service `foo` 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](http://www.gruntwork.io/). If you're looking for help or commercial
support, send an email to [modules@gruntwork.io](mailto:modules@gruntwork.io?Subject=Consul%20Terraform%20Module).
This Terraform Module is maintained by [Gruntwork](http://www.gruntwork.io/). If you're looking for help or commercial
support, send an email to [modules@gruntwork.io](mailto:modules@gruntwork.io?Subject=Consul%20Terraform%20Module).
Gruntwork can help with:

* Setup, customization, and support for this Terraform Module.
Expand All @@ -73,10 +74,10 @@ Gruntwork can help with:
template to create a Consul [Custom Image](https://cloud.google.com/compute/docs/images).

* [consul-cluster](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/consul-cluster): The module includes Terraform code to deploy a Consul Image across a [Managed
Compute Instance Group](https://cloud.google.com/compute/docs/instance-groups/).
Compute Instance Group](https://cloud.google.com/compute/docs/instance-groups/).

* [run-consul](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/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
by the above Packer module at build-time to set configurations, and by the Terraform module at runtime
with the Instance's [Startup Script](https://cloud.google.com/compute/docs/startupscript) to create the cluster.

* [install-dnsmasq module](https://github.com/hashicorp/terraform-google-consul/tree/master/modules/install-dnsmasq): Install [Dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html)
Expand All @@ -91,19 +92,18 @@ Contributions are very welcome! Check out the [Contribution Guidelines](https://

## How is this Terraform Module versioned?

This Terraform Module follows the principles of [Semantic Versioning](http://semver.org/). You can find each new release,
This Terraform Module follows the principles of [Semantic Versioning](http://semver.org/). You can find each new release,
along with the changelog, in the [Releases Page](https://github.com/hashicorp/terraform-google-consul/releases).

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.
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](https://github.com/hashicorp/terraform-google-consul/tree/master/LICENSE) and [NOTICE](https://github.com/hashicorp/terraform-google-consul/tree/master/NOTICE) for more
This code is released under the Apache 2.0 License. Please see [LICENSE](https://github.com/hashicorp/terraform-google-consul/tree/master/LICENSE) and [NOTICE](https://github.com/hashicorp/terraform-google-consul/tree/master/NOTICE) for more
details.

Copyright © 2017 Gruntwork, Inc.

70 changes: 38 additions & 32 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
# ---------------------------------------------------------------------------------------------------------------------

provider "google" {
region = "${var.gcp_region}"
region = var.gcp_region
}

terraform {
required_version = ">= 0.10.0"
# The modules used in this example have been updated with 0.12 syntax, which means the example is no longer
# compatible with any versions below 0.12.
required_version = ">= 0.12"
}

# ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -24,20 +26,20 @@ module "consul_servers" {
# source = "git::git@github.com:gruntwork-io/consul-gcp-module.git//modules/consul-cluster?ref=v0.0.1"
source = "./modules/consul-cluster"

gcp_project_id = "${var.gcp_project_id}"
gcp_region = "${var.gcp_region}"
cluster_name = "${var.consul_server_cluster_name}"
gcp_project_id = var.gcp_project_id
gcp_region = var.gcp_region
cluster_name = var.consul_server_cluster_name
cluster_description = "Consul Server cluster"
cluster_size = "${var.consul_server_cluster_size}"
cluster_tag_name = "${var.consul_server_cluster_tag_name}"
startup_script = "${data.template_file.startup_script_server.rendered}"
cluster_size = var.consul_server_cluster_size
cluster_tag_name = var.consul_server_cluster_tag_name
startup_script = data.template_file.startup_script_server.rendered

# Grant API and DNS access to requests originating from the the Consul client cluster we create below.
allowed_inbound_tags_http_api = ["${var.consul_server_cluster_tag_name}"]
allowed_inbound_cidr_blocks_http_api = "${var.consul_server_allowed_inbound_cidr_blocks_http_api}"
allowed_inbound_tags_http_api = [var.consul_server_cluster_tag_name]
allowed_inbound_cidr_blocks_http_api = var.consul_server_allowed_inbound_cidr_blocks_http_api

allowed_inbound_tags_dns = ["${var.consul_server_cluster_tag_name }"]
allowed_inbound_cidr_blocks_dns = "${var.consul_server_allowed_inbound_cidr_blocks_dns}"
allowed_inbound_tags_dns = [var.consul_server_cluster_tag_name]
allowed_inbound_cidr_blocks_dns = var.consul_server_allowed_inbound_cidr_blocks_dns

# WARNING! These configuration values are suitable for testing, but for production, see https://www.consul.io/docs/guides/performance.html
# Production recommendations:
Expand All @@ -53,9 +55,9 @@ module "consul_servers" {
# WARNING! By specifying just the "family" name of the Image, Google will automatically use the latest Consul image.
# In production, you should specify the exact image name to make it clear which image the current Consul servers are
# deployed with.
source_image = "${var.consul_server_source_image}"
source_image = var.consul_server_source_image

image_project_id = "${var.image_project_id}"
image_project_id = var.image_project_id

# WARNING! This makes the Consul cluster accessible from the public Internet, which is convenient for testing, but
# NOT for production usage. In production, set this to false.
Expand All @@ -70,10 +72,12 @@ module "consul_servers" {
# Render the Startup Script that will run on each Consul Server Instance on boot.
# This script will configure and start Consul.
data "template_file" "startup_script_server" {
template = "${file("${path.module}/examples/root-example/startup-script-server.sh")}"
template = file(
"${path.module}/examples/root-example/startup-script-server.sh",
)

vars {
cluster_tag_name = "${var.consul_server_cluster_tag_name}"
vars = {
cluster_tag_name = var.consul_server_cluster_tag_name
}
}

Expand All @@ -90,28 +94,28 @@ module "consul_clients" {
# source = "git::git@github.com:gruntwork-io/consul-gcp-module.git//modules/consul-cluster?ref=v0.0.1"
source = "./modules/consul-cluster"

gcp_project_id = "${var.gcp_project_id}"
gcp_region = "${var.gcp_region}"
cluster_name = "${var.consul_client_cluster_name}"
gcp_project_id = var.gcp_project_id
gcp_region = var.gcp_region
cluster_name = var.consul_client_cluster_name
cluster_description = "Consul Clients cluster"
cluster_size = "${var.consul_client_cluster_size}"
cluster_tag_name = "${var.consul_client_cluster_tag_name}"
startup_script = "${data.template_file.startup_script_client.rendered}"
cluster_size = var.consul_client_cluster_size
cluster_tag_name = var.consul_client_cluster_tag_name
startup_script = data.template_file.startup_script_client.rendered

allowed_inbound_tags_http_api = ["${var.consul_client_cluster_tag_name}"]
allowed_inbound_cidr_blocks_http_api = "${var.consul_client_allowed_inbound_cidr_blocks_http_api}"
allowed_inbound_tags_http_api = [var.consul_client_cluster_tag_name]
allowed_inbound_cidr_blocks_http_api = var.consul_client_allowed_inbound_cidr_blocks_http_api

allowed_inbound_tags_dns = ["${var.consul_client_cluster_tag_name }"]
allowed_inbound_cidr_blocks_dns = "${var.consul_client_allowed_inbound_cidr_blocks_dns}"
allowed_inbound_tags_dns = [var.consul_client_cluster_tag_name]
allowed_inbound_cidr_blocks_dns = var.consul_client_allowed_inbound_cidr_blocks_dns

machine_type = "g1-small"
root_volume_disk_type = "pd-standard"
root_volume_disk_size_gb = "15"

assign_public_ip_addresses = true

source_image = "${var.consul_client_source_image}"
image_project_id = "${var.image_project_id}"
source_image = var.consul_client_source_image
image_project_id = var.image_project_id

# Our Consul Clients are completely stateless, so we are free to destroy and re-create them as needed.
# Todo: Research this further
Expand All @@ -121,9 +125,11 @@ module "consul_clients" {
# Render the Startup Script that will run on each Consul Server Instance on boot.
# This script will configure and start Consul.
data "template_file" "startup_script_client" {
template = "${file("${path.module}/examples/root-example/startup-script-client.sh")}"
template = file(
"${path.module}/examples/root-example/startup-script-client.sh",
)

vars {
cluster_tag_name = "${var.consul_server_cluster_tag_name}"
vars = {
cluster_tag_name = var.consul_server_cluster_tag_name
}
}
Loading

0 comments on commit 8f09a3c

Please sign in to comment.