Last active
January 28, 2021 22:52
-
-
Save CariZa/ad3a7f003b0ec64bc3aba601862af929 to your computer and use it in GitHub Desktop.
Simple Terraform Digitalocean Configuration
This file contains 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
# Set the variable value in *.tfvars file | |
# or using -var="do_token=..." CLI option | |
variable "do_token" {} | |
variable "ssh_key_name" {} | |
# Configure the DigitalOcean Provider | |
provider "digitalocean" { | |
token = "${var.do_token}" | |
} | |
# Use existing ssh key stored on Digital Ocean | |
data "digitalocean_ssh_key" "default" { | |
name = "${var.ssh_key_name}" | |
} | |
# Create a web server | |
resource "digitalocean_droplet" "web" { | |
image = "ubuntu-18-04-x64" | |
name = "web-1" | |
region = "ams3" | |
size = "s-1vcpu-1gb" | |
ssh_keys = ["${data.digitalocean_ssh_key.default.fingerprint}"] | |
} | |
output "controller_ip_address" { | |
value = "${digitalocean_droplet.web.ipv4_address}" | |
} | |
# Store the digital ocean token as an environment variable called DOTOKEN | |
# export DOTOKEN="DOTOKEN" | |
# test token by running: $ echo $DOTOKEN | |
# Store the ssh key name as an environment variable called SSHKEYNAME | |
# export SSHKEYNAME="SSHKEYNAME" | |
# test token by running: $ echo $SSHKEYNAME | |
# Run these: | |
# $ terraform init | |
# $ terraform plan -var="do_token=$DOTOKEN" -var="ssh_key_name=$SSHKEYNAME" | |
# - Output will end with: Plan: 1 to add, 0 to change, 0 to destroy. | |
# $ terraform apply -var="do_token=$DOTOKEN" -var="ssh_key_name=$SSHKEYNAME" | |
# To destroy: | |
# $ terraform destroy -var="do_token=$DOTOKEN" -var="ssh_key_name=$SSHKEYNAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment