Setup for Digital Ocean + Nginx + Certbot + Cloudflare using Terraform.
This will use Terraform to:
- Create a Digital Ocean Droplet
- Install Nginx & Certbot
- Create a firewall on Digital Ocean
- Setup an A record on Cloudflare to point to the droplet's IP
- Provision an SSL certificate for the domain using Certbot
Written for Terraform v0.12.24
- Clone the repository
git clone https://github.com/MarkNjunge/terraform-nginx-cloudflare.git
cd terraform-nginx-cloudflare
- Create a
terraform.tfvars
file and modify the contents.
cp terraform.tfvars.sample terraform.tfvars
-
Modify nginx/default.conf. Change
server_name
to your domain. -
Create an ssh key named
terraform
.
It should be saved in~/.ssh
(C:\Users\username\.ssh
on Windows)
ssh-keygen -t rsa
- Install Terraform providers and apply
terraform init
terraform apply
Create a personal access token on Digital Ocean: LINK
Create an API Token on Cloudflare: Managing API Tokens and Keys. The token needs to have permission to edit DNS in a zone.