Skip to content

Terraform Digital Ocean Script v2

Setup Terraform in Windows (AMD64)
Download Terraform for Windows (AMD64) from
Unzip the file to a directory
Add the Terraform binary to your system's PATH:
Right-click This PCSettingsAdvanced system settingsEnvironment Variables.
Under User variables for Unity_0116, find the Path variable, and click Edit.
Click New, and add the path to the directory where you unzipped Terraform.
Press OK to save the changes.
terraform —version (Terraform version command)
Screenshot 2024-09-18 181914.png

Create API Tokens in Digital Ocean
Go to and log in to your account.
Generate a New Token
Name the Token
Expiration :- 30/60/90 days and No Expir
Set Permissions :- full access
Screenshot 2024-09-18 171244.png
Create API Tokens in GitHub
Access Personal Access Tokens:
Click on your profile icon in the top-right corner.
Select Settings from the dropdown menu.
In the left sidebar, click on Developer settings.
Click on Personal access tokens.
Create a New Token
Click on Personal access tokens (classic).
Enter a Token name to describe its purpose.
Choose an Expiration date or set it to No expiration if you prefer.
Set Permissions:
Ensure that your token has both admin:public_key and write:public_key permissions. You can regenerate the token if needed, ensuring those scopes are checked.
Screenshot 2024-09-20 163801.png
Screenshot 2024-09-20 163833.png
Generate and Copy the Token

Create API Tokens for Cloudflare
Create a new API token:
Click "Create Token
Select the "Edit zone DNS" template or create a custom token with permissions for "Zone DNS"
Zone DNS" read and edit
Define the token's permissions:
Permissions: Select "Zone DNS" and set to "Read" and "Edit."
Zone Resources: Set to "Include All Zones" or specify the zones as needed.
Click "Continue to summary" and then "Create Token."

Screenshot 2024-09-18 173739.png

How to Retrieve the Cloudflare Zone ID

Log in to the .
Select your account and choose the domain for which you need the Zone ID.
On the Overview page (this is the default landing page when you select a domain), scroll down to find the API section.
In this section, you will find both the Zone ID and the Account ID.
Copy the Zone ID to use in your Terraform configuration or API calls.

Screenshot 2024-09-18 191053.png



ssh-keygen -t rsa
And Save Terraform File
file name :- id_rsa.pub
Terraform File
create a new Terraform file
create the .tf file

file (Terraform Provider Configuration for Digital Ocean and Cloudflare)
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 3.0" # Use the latest version within the 3.x range
}
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0" # Example: Use the latest version within the 2.x range
}
}
}

# Configure the DigitalOcean Provider
provider "digitalocean" {
token = var.do_token
}

# Configure the Cloudflare Provider
provider "cloudflare" {
api_token = var.cloudflare_api_token
}

terraform.tfvars
# DigitalOcean API Token
do_token = "dop_v1_cd61e7b627830e2212033ceb47b6400e1f1ed981c896b88a3ca6fe5f541da5c4"

# Cloudflare API Token
cloudflare_api_token = "z2ah0j36vxc-nJ11_4qEbDCDLNJtGK8HE8rJ4wQj"

# Cloudflare Zone ID
cloudflare_zone_id = "3dd054264c1a06c8794306590a4205e2"

Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.