Created
September 4, 2022 04:04
-
-
Save amaudy/875ff61ce1c49ee70c87881bf59c4ddb to your computer and use it in GitHub Desktop.
Terraform code for create DigitalOcean Droplet
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
resource "digitalocean_droplet" "devbox" { | |
image = var.image | |
name = var.name | |
region = var.region | |
size = var.size | |
tags = var.tags | |
ssh_keys = [ | |
data.digitalocean_ssh_key.terraform.id | |
] | |
monitoring = true | |
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" { | |
working_dir = "${path.cwd}/ansible" | |
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root -i '${self.ipv4_address},' setup-devbox.yml" | |
} | |
} | |
output "droplet_ip_addresses" { | |
value = { | |
"Your Development machine IP is:" = digitalocean_droplet.devbox.ipv4_address | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment