A set of example projects of varying complexity for deploying a Consul cluster with Terraform.
To deploy each of the examples in this project, you will need an SSH key and a set of variables specific to your environment.
The shared/ssh_keys/generate_key_pair.sh
script can assist with creating or
copying an existing key for your environment. In both manners (creating a new
key or copying an existing one), the script will place a private key file
and a public key file in shared/ssh_keys
. This is necessary for Terraform
to be able to create and then provision your Consul cluster.
To create a new key, run the command below where the first argument is your
key name. This will generate a new private key and public key in the
shared/ssh_keys
directory.
$ bash shared/ssh_keys/generate_key_pair.sh atlas-example
No key pair exists and no private key arg was passed, generating new keys.
Generating RSA private key, 1024 bit long modulus
................++++++
..........++++++
e is 65537 (0x10001)
Public key: shared/ssh_keys/atlas-example.pub
Private key: shared/ssh_keys/atlas-example.pem
$
To copy an existing key, run the command below where the first argument
is your key name and the second argument is the path to the existing
private key file. This will copy your private key to the
shared/ssh_keys
directory and generate a new public key in the same
directory.
$ bash shared/ssh_keys/generate_key_pair.sh atlas-example ~/.ssh/atlas-examples
Using private key [/Users/clstokes/.ssh/atlas-examples] for key pair.
Public key: shared/ssh_keys/atlas-example.pub
Private key: shared/ssh_keys/atlas-example.pem
$
Run the commands below from the consul-cluster
directory.
packer push shared/packer/consul_client.json
packer push shared/packer/consul_server.json
terraform remote config -backend="Atlas" -backend-config="name=$ATLAS_USERNAME/consul-cluster"
terraform get -update aws-intermediate-consul-cluster/terraform/
terraform push -vcs=false -name="$ATLAS_USERNAME/consul-cluster" aws-intermediate-consul-cluster/terraform/
terraform apply aws-intermediate-consul-cluster/terraform/
terraform destroy aws-intermediate-consul-cluster/terraform/