Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save richardsonlima/a2553da976c0f94d9c287d4a1a8a06bc to your computer and use it in GitHub Desktop.
Save richardsonlima/a2553da976c0f94d9c287d4a1a8a06bc to your computer and use it in GitHub Desktop.
terraform init
export TF_LOG=1
export SSH_FP=$(ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub | awk '{print $2}'| cut -c5-)
export DO_PAT={YOUR_PERSONAL_ACCESS_TOKEN}
terraform plan \
-var "do_token=${DO_PAT}" \
-var "pub_key=$HOME/.ssh/id_rsa.pub" \
-var "pvt_key=$HOME/.ssh/id_rsa" \
-var "ssh_fingerprint=${SSH_FP}"
terraform apply \
-var "do_token=${DO_PAT}" \
-var "pub_key=$HOME/.ssh/id_rsa.pub" \
-var "pvt_key=$HOME/.ssh/id_rsa" \
-var "ssh_fingerprint=${SSH_FP}"
resource "digitalocean_droplet" "k8s-master-01" {
image = "ubuntu-16-04-x64"
name = "k8s-master-01"
region = "nyc3"
size = "1gb"
private_networking = true
ssh_keys = [
"${var.ssh_fingerprint}"
]
connection {
user = "root"
type = "ssh"
private_key = "${file(var.pvt_key)}"
timeout = "2m"
}
provisioner "remote-exec" {
inline = [
"export PATH=$PATH:/usr/bin",
# install nginx
"sudo apt-get update",
"sudo apt-get -y install htop glances"
]
}
}
variable "do_token" {}
variable "pub_key" {}
variable "pvt_key" {}
variable "ssh_fingerprint" {}
provider "digitalocean" {
token = "${var.do_token}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment