Skip to content

Provision instances on DigitalOcean with Terraform or OpenTofu.

Notifications You must be signed in to change notification settings

ciro-mota/terra-DO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terra Linode

License DigitalOcean Terraform OpenTofu Ansible AlmaLinux Rocky Linux CentOS Debian Ubuntu Shell Script

This project aims to provision Droplets on DigitalOcean with the help of Terraform or OpenTofu.

⚠️ Caution!

DigitalOcean charges you for the use of VMs even if they are in a powered off state and this can cause a huge cost issue for some people. So you can never forget to destroy your instances after some testing.

📌 Before executing:

Note

It is necessary to get credentials for Terraform execution.

  1. Create a DigitalOcean Personal Access Token.

  2. Create an ssh key to be used with DigitalOcean and register it in the administration panel.

  3. We need to get your SSH key fingerprint. Run this command:

ssh-keygen -E md5 -lf ~/.ssh/your-keyname.pub | awk '{print $2}'|cut -d ':' -f2-
  1. Add two variables to your .bashrc or .zshrc file:
export TF_VAR_do_token=<your-personal-access-token>
export TF_VAR_ssh_fingerprint=<your-key-fingerprint>

💻 Usage

  • Clone this repo.
  • By default an Droplet with Debian 12 with s-1vcpu-2gb will be provisioned, if you want another OS or machine, modify the variables.tf files if you wish.
  • Run terraform init, terraform plan -out= name-of-the-plan and terraform apply. At the end, terraform destroy

🔧 cloud-init

You can also apply post-installation scripts to your DigitalOcean Droplets through cloud-init. This project counts as example scripts for nginx provisioning provided by Ansible Galaxy.

You can create your own script and insert it into the content field of the cloud_init.yaml file.

To work with these settings, uncomment line 11 in the instance.tf file.

💾 Remote state

By default this block will be commented. Uncomment if you use it.

DigitalOcean Spaces Object Storage supports S3-compatible applications, so the aws cli is supported for file handling with DigitalOcean and remote states.

  • Create a Spaces Object Storage bucket with your unique name.
  • Browse to API » Spaces Keys » Generate New Key. Get your Access Key and Secret.
  • Install aws cli.
  • Run the command aws configure --profile digitalocean for configuration.
  • When prompted, enter your previously obtained Access Key and Secret. The region and output fields can be left blank.
  • Add the variable below to your .bashrc or .zshrc:
export AWS_PROFILE=digitalocean
  • Uncomment and edit lines 11 and 13 of the main.tf file with the information about your bucket in which it was created.

🤝 Referral

Need fast and affordable cloud hosting? Try @digitalocean using my affiliate link and get free credits to get started:

DigitalOcean Referral Badge

🎁 Sponsoring

If you like this work, give me it a star on GitHub, and consider supporting it buying me a coffee:

PayPal