Skip to content

Instantly share code, notes, and snippets.

@amaudy
Created September 3, 2022 05:34
Show Gist options
  • Save amaudy/f1f572c431070aa357b6938174564aec to your computer and use it in GitHub Desktop.
Save amaudy/f1f572c431070aa357b6938174564aec to your computer and use it in GitHub Desktop.
resource "digitalocean_droplet" "web" {
image = "ubuntu-22-04-x64"
name = "devbox"
region = "sgp1"
size = "s-2vcpu-4gb"
tags = ["devbox"]
lifecycle {
prevent_destroy = false
}
ssh_keys = [
data.digitalocean_ssh_key.terraform.id
]
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Ready to continue"]
connection {
host = self.ipv4_address
type = "ssh"
user = "root"
agent = "true"
}
}
provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root -i '${self.ipv4_address},' setup-devbox.yml"
}
}
data "http" "myip" {
url = "http://ipv4.icanhazip.com"
}
output "droplet_ip_addresses" {
value = {
"Your Development machine IP is:" = digitalocean_droplet.web.ipv4_address
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment