Created
July 24, 2020 13:30
-
-
Save demiters/acf08ae68ebb4bf235a69cc83faa51b5 to your computer and use it in GitHub Desktop.
Terraform setup for automated install of microk8s on a Ubuntu 20.04 DigitalOcean VPS. Edits required, see comments for more info.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Edit name (example.com), region and size as you wish | |
resource "digitalocean_droplet" "example.com" { | |
image = "ubuntu-20-04-x64" | |
name = "example.com" | |
region = "fra1" | |
size = "s-2vcpu-4gb" | |
private_networking = true | |
ssh_keys = [ | |
var.ssh_fingerprint | |
] | |
connection { | |
host = self.ipv4_address | |
user = "root" | |
type = "ssh" | |
private_key = file(var.pvt_key) | |
timeout = "2m" | |
} | |
provisioner "remote-exec" { | |
# Local scripts that are going to be executed on the new server, edit as necessary | |
scripts = [ | |
./swap.sh, # https://gist.github.com/demiters/ba1c66c382cd2870764bf58066116a7a | |
./user.sh, # https://gist.github.com/demiters/f51a0094eee3e56ea55b0e31095d9fbb | |
./firewall.sh, # https://gist.github.com/demiters/00794411f9144b9f684c8ea7acd74743 | |
./aliases.sh, # https://gist.github.com/demiters/c322d99db658e37ba30c8f13ba8b434b | |
./microk8s.sh # https://gist.github.com/demiters/e8a7a7dda40037f52115849a7e7680b5 | |
] | |
inline = [ | |
"export PATH=$PATH:/usr/bin" | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Assumes your ssh public and private keys are located at .ssh/id_rsa[.pub] | |
terraform init | |
terraform plan \ | |
-var "do_token=${DO_TOKEN}" \ | |
-var "pub_key=$HOME/.ssh/id_rsa.pub" \ | |
-var "pvt_key=$HOME/.ssh/id_rsa" \ | |
-var "ssh_fingerprint=${DO_SSH_FINGERPRINT}" | |
terraform apply \ | |
-var "do_token=${DO_TOKEN}" \ | |
-var "pub_key=$HOME/.ssh/id_rsa.pub" \ | |
-var "pvt_key=$HOME/.ssh/id_rsa" \ | |
-var "ssh_fingerprint=${DO_SSH_FINGERPRINT}" | |
terraform show terraform.tfstate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Installs Terraform (Linux 64bit) for local use | |
mkdir -p $TF_PATH | |
filename="terraform.zip" | |
path_append='[[ ":$PATH:" != *":$TF_PATH/bin:"* ]] && PATH=$PATH:$TF_PATH/bin' | |
if curl --silent -o "${PWD}/${filename}" -L "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip"; then | |
unzip "${filename}" -d "${TF_PATH}/bin" | |
if [[ -f "${PWD}/${filename}" ]]; then | |
echo "Removing the file.." | |
rm -f "${PWD}/${filename}" | |
echo "$path_append" >> $SH_RC" | |
. $SH_RC | |
fi | |
else | |
echo "Something went wrong" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "do_token" {} | |
variable "pub_key" {} | |
variable "pvt_key" {} | |
variable "ssh_fingerprint" {} | |
provider "digitalocean" { | |
token = var.do_token | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Edit these and run this script first | |
# DigitalOcean personal access token | |
export DO_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
# MD5 fingerprint of your public key: | |
# ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub | awk '{print $2}' | |
export DO_SSH_FINGERFRINT="xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | |
# Terraform version to install | |
export TF_VERSION="0.12.24" | |
# Path to install Terraform in | |
export TF_PATH="/home/arturs/opt/terraform" | |
# Enable Terraform logging | |
export TF_LOG=1 | |
# Shell config to write into | |
export SH_RC="/home/arturs/.zshrc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment