Infra & Cloud terraform Beginner

DigitalOcean Droplet Terraform

Provision a DigitalOcean Droplet with SSH key and firewall via Terraform.

terraform
resource "digitalocean_droplet" "web" {
  name   = "web-01"
  region = "nyc3"
  size   = "s-1vcpu-1gb"
  image  = "ubuntu-24-04-x64"
  ssh_keys = [data.digitalocean_ssh_key.default.id]
}
resource "digitalocean_firewall" "web" {
  name = "web-fw"
  droplet_ids = [digitalocean_droplet.web.id]
  inbound_rule  { protocol = "tcp"; port_range = "443"; source_addresses = ["0.0.0.0/0"] }
  outbound_rule { protocol = "tcp"; port_range = "all"; destination_addresses = ["0.0.0.0/0"] }
}

Prerequisites

  • terraform >= 1.0
  • digitalocean provider

Pro Tips

  • → Use user_data to run cloud-init setup on first boot.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
terraform
Level
Beginner
Read time
4 min
Published
Dec 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.