Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ vault-credentials.json

# SSH keys
id_rsa
id_rsa.pub
id_rsa.pub

backend.hcl
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ cd cluster
# Create SSH key to access droplets
ssh-keygen -q -t rsa -N '' -f ./id_rsa

# Create a space to hold your terraform state remotely
./create-backend.sh

# Init terraform
terraform init
terraform init -backend-config=./backend.hcl

# Deploy droplets
terraform apply
Expand Down
54 changes: 54 additions & 0 deletions cluster/create-backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

echo ""
echo "Open https://cloud.digitalocean.com/spaces"
echo "Click on 'Create a Space'"
echo -n "Configure this space in the same region you want to deploy to and "
echo -n "write down the name you used. You will need it in the next step"
echo ""
echo ""

# https://<bucket-name>.<region>.digitaloceanspaces.com
read -p 'Endpoint URL: ' ENDPOINT_URL
echo

IFS='//'
read -ra ADDR <<< "$ENDPOINT_URL"
BUCKET_URL="${ADDR[2]}"

# https://www.tutorialkart.com/bash-shell-scripting/bash-split-string/
IFS='.'
read -ra ADDR <<< "$BUCKET_URL"
BUCKET_NAME="${ADDR[0]}"
REGION="${ADDR[1]}"
IFS=' '

echo "Bucket Name: ${BUCKET_NAME}"
echo "Bucket Region: ${REGION}"

echo ""
echo "Next you'll need to generate some credentials. Head to this URL:"
echo ""
echo "https://cloud.digitalocean.com/settings/api/tokens"
echo ""
echo "Under 'Spaces access keys' click 'Generate New Key'"
echo ""


read -sp "Access Key: " ACCESS_KEY
echo ""
read -sp "Secret Key: " SECRET_KEY
echo ""


echo "skip_credentials_validation = true" >> ./backend.hcl
echo "skip_metadata_api_check = true" >> ./backend.hcl
echo "" >> ./backend.hcl
echo "bucket = \"${BUCKET_NAME}\"" >> ./backend.hcl
echo "region = \"${REGION}\"" >> ./backend.hcl
echo "skip_region_validation = true" >> ./backend.hcl
echo "endpoint = \"https://$REGION.digitaloceanspaces.com\"" >> ./backend.hcl
echo "" >> ./backend.hcl
echo "access_key = \"$ACCESS_KEY\"" >> ./backend.hcl
echo "secret_key = \"$SECRET_KEY\"" >> ./backend.hcl

3 changes: 3 additions & 0 deletions cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ terraform {
version = "~> 2.0"
}
}
backend "s3" {
key = "production/terraform.tfstate"
}
}


Expand Down
2 changes: 1 addition & 1 deletion cluster/setup-tunnels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ echo "Nomad can be accessed at http://localhost:4646"

# Traefik tunnel
ssh -4 -f -N -g -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i ./id_rsa -L 8081:$INGRESS_IP:8081 root@$INGRESS_IP
echo "Traefik can be accessed at http://localhost:0881 (When it is enabled)"
echo "Traefik can be accessed at http://localhost:8081 (When it is enabled)"