All Projects β†’ dwmkerr β†’ Terraform Consul Cluster

dwmkerr / Terraform Consul Cluster

Licence: mit
Demonstrates how to create a resilient Consul cluster on AWS, using Terraform. Companion to my article on dwmkerr.com.

Labels

Projects that are alternatives of or similar to Terraform Consul Cluster

Doact
A Terraform module for hosting your own runner for CI/CD on Digital Ocean to run jobs in your GitHub Actions workflows. πŸš€
Stars: ✭ 42 (-19.23%)
Mutual labels:  hcl
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (-7.69%)
Mutual labels:  hcl
No Inet Gke Cluster
Stars: ✭ 50 (-3.85%)
Mutual labels:  hcl
Tb Gcp
Tranquility Base - The cloud landing zone
Stars: ✭ 42 (-19.23%)
Mutual labels:  hcl
Ssh Aliases
A tool for ~/.ssh/config generation
Stars: ✭ 46 (-11.54%)
Mutual labels:  hcl
Terraform Aws Dynamodb
Terraform module that implements AWS DynamoDB with support for AutoScaling
Stars: ✭ 49 (-5.77%)
Mutual labels:  hcl
Hcloud K8s
Hetzner Kubernetes Cluster Installation with Private Networking
Stars: ✭ 40 (-23.08%)
Mutual labels:  hcl
Airflow Toolkit
Any Airflow project day 1, you can spin up a local desktop Kubernetes Airflow environment AND one in Google Cloud Composer with tested data pipelines(DAGs) πŸ–₯ >> [ πŸš€, 🚒 ]
Stars: ✭ 51 (-1.92%)
Mutual labels:  hcl
Live Infrastructure
Live video transcoding infrastructure
Stars: ✭ 48 (-7.69%)
Mutual labels:  hcl
Tf sns email
Terraform Module to create an email backed SNS topic
Stars: ✭ 49 (-5.77%)
Mutual labels:  hcl
Ansible Role Cobalt Strike
An Ansible role for installing Cobalt Strike.
Stars: ✭ 43 (-17.31%)
Mutual labels:  hcl
Infra Personal
Terraform for setting up my personal infrastructure
Stars: ✭ 45 (-13.46%)
Mutual labels:  hcl
Terraform Aws Github Ci
[DEPRECATED] Serverless CI for GitHub using AWS CodeBuild with PR and status support
Stars: ✭ 49 (-5.77%)
Mutual labels:  hcl
Terraform Aws Cloudwatch
Terraform module which creates Cloudwatch resources on AWS
Stars: ✭ 41 (-21.15%)
Mutual labels:  hcl
Docs Examples
Open in Cloud Shell Examples for the Google provider docs
Stars: ✭ 50 (-3.85%)
Mutual labels:  hcl
Terraform Aws Jenkins Ha Agents
A terraform module for a highly available Jenkins deployment.
Stars: ✭ 41 (-21.15%)
Mutual labels:  hcl
Eks rds terraform
Stars: ✭ 49 (-5.77%)
Mutual labels:  hcl
Terraform Elasticache Example
Example Terraform config for creating an Elasticache cluster
Stars: ✭ 52 (+0%)
Mutual labels:  hcl
Hashicorp
Random code for HashiCorp related projects, training, etc.
Stars: ✭ 51 (-1.92%)
Mutual labels:  hcl
Hackathon
γ‚’γ‚€γƒ‰γƒ«γ‚’ζ„›γ§γ‚‹γ€‚γ‚’γ‚€γƒžγ‚Ήγ«Contributeする
Stars: ✭ 49 (-5.77%)
Mutual labels:  hcl

terraform-consul-cluster

This repo demonstrates how to create a resilient Consul cluster running on AWS, using Terraform. It is the companion project to my article 'Creating a Resilient Consul Cluster for Docker Microservice Discovery with Terraform and AWS'.

Prerequisites

Please install the following components:

  1. Docker
  2. Terraform - brew update && brew install terraform.

You must also have an AWS account. If you don't, this cluster will run happily on the AWS Free Tier which only takes ten minutes to sign up with.

You will need to set up your AWS credentials. The preferred way is to install the AWS CLI and quickly run aws configure:

$ aws configure
AWS Access Key ID [None]: <Enter Access Key ID>
AWS Secret Access Key [None]: <Enter Secret Key>
Default region name [None]: ap-southeast-1
Default output format [None]:

This will keep your AWS credentials in the $HOME/.aws/credentials file, which Terraform can use. This and all other options are documented in the Terraform: AWS Provider documentation.

Creating the Cluster

The cluster is implemented as a Terraform Module. To launch, just run:

# Initialize terraform first time using
terraform init

# Create the module.
terraform get

# See what we will create, or do a dry run!
terraform plan

# Create the cluster!
terraform apply

You will be asked for a region to deploy in, use us-east-1 should work fine! You can configure the nuances of how the cluster is created in the main.tf file. Once created, you will see a message like:

$ terraform apply
var.region
  Region to deploy the Consul Cluster into

  Enter a value: ap-southeast-1

...

Apply complete! Resources: 20 added, 0 changed, 0 destroyed.

...

Outputs:

consul-dns = consul-lb-1577031185.ap-southeast-1.elb.amazonaws.com

Navigate to port 8500 at address provided (e.g. http://consul-lb-1577031185.ap-southeast-1.elb.amazonaws.com:8500) and you will see the Consul interface.

Destroying the Cluster

Bring everything down with:

terraform destroy

Project Structure

The module has the following structure:

main.tf                   # Cluster definition.
variables.tf              # Basic config.
modules/consul/main.tf    # Main cluster setup.
modules/consul/variables.tf    # Inputs for the module.
modules/consul/outputs.tf # Outputs for the module.
modules/consul/01-vpc.tf  # Network configuration. Defines the VPC, subnets, access etc.
modules/consul/02-consul-node-role.tf  # Defines policies and a role for cluster nodes.
modules/consul/files/consul-node.sh # Setup script for the cluster nodes.
example-service/          # A goofy example microservice used to test the project.
article/                  # The text and images for the article on dwmkerr.com

More info

A detailed write up of how this code works is available at:

http://www.dwmkerr.com/creating-a-resilient-consul-cluster-for-docker-microservice-discovery-with-terraform-and-aws/

Troubleshooting

Trying to plan or apply gives the error No valid credential sources found for AWS Provider.

This means you've not set up your AWS credentials - check the Prerequisites section of this guide and try again, or check here: https://www.terraform.io/docs/providers/aws/index.html.

EntityAlreadyExists: Role with name consul-instance-role already exists.

'Already exists' errors are not uncommon with Terraform, due to the fact that some AWS resource creation can have timing or synchronisation issues. In this case, just try to create again with terraform apply.

Contributors

arehmandev - Felt inspired by this project and ended up modularising it!

Tested 11/01/17, terraform 0.8.3

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].