Make your changes locally in a docker environment then apply your changes to Cloudflare via Github actions.
This project is currently in alpha state, so expect major changes in the future!
Contributors and early adopters are welcome!
- The Terraform state is managed in terraform cloud (best practice). This lets your team manage infrastructure using HCP Terraform, which also handles state data.
In Terraform Cloud, create an organization and a workspace
https://app.terraform.io/public/signup/account?product_intent=terraform
- You will also need the email you are using in Cloudflare and your Cloudflare api key
https://developers.cloudflare.com/fundamentals/api/get-started/keys/
- The Github Actions requires a Github User Token
- https://developers.cloudflare.com/terraform/advanced-topics/best-practices/
- https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs
- https://github.com/cloudflare/cf-terraforming
-
Cloudflare:
Cloudflare is a service that helps make websites faster, safer, and more reliable. -
Docker:
Docker is a tool that makes it easy to run apps anywhere by putting them in small, ready-to-go packages called containers. The whole code/application is contain in a controlled environment (which can run in most common Operator system E.g: windows, Mac...). -
Terraform:
Terraform is an open-source tool for managing cloud infrastructure. It uses files to define and control resources. -
Github:
GitHub is a web-based platform which allows users to store and manage their source code, track changes, and collaborate on projects with others.
Let's consider a Cloudflare account with 2 ressources (E.g: page rules, firewall rules...)
- When you run the Docker command to initialise the entire environment, a script (/scripts/docker.sh) will clone the Cloudflare resources locally into the ./generated folder. This step is an helper, so as a dev you have all the last changes in your local environment ready to be used.
-
In parallel, the resources already tracked by Terraform will be loaded into Terraform local state.
The ./modules folder contains the resources that have already been added to the system. -
A new resource can be added see comments.
The cloudflare resources are stored in the folder ./modules/
The modules must be referenced in the main.tf file to be detected by Terraform.
Don't forget to add the main.tf to your each module you want to add
Pushing changes to GitHub after adding a new resource will trigger a suite of Terraform commands (refer to terraform.yml in GitHub Actions).
- If the Terraform actions end with a succeful outcome then the change can be found in Cloudflare (if not a related error will be shown in the Github actions summary)
-
First, Fork this project in your environment
-
Set secrets variables in your repo settings
CLOUDFLARE_EMAIL
CLOUDFLARE_API_KEY
TF_WORKSPACE
TF_CLOUD_ORGANIZATION
GH_USER_TOKEN
-
Create your .env file (use the .env.tmp as a base)
-
Build your local Docker environment
git clone git@github.com:<MY_GITHUB_USERNAME>/cloudflare_manager.git- Start your docker environment
# Build the image (if anything has changed)
docker compose down; docker-compose build; docker-compose up -d- Start applying your changes (in the modules folder)
On the related module (you can run any Terraform commands directly from your docker environment)
- Commit your changes
- Check your changes in Cloudflare
You can then enter your working environment (or check the logs of all the commands).
# Drop into a bash session
docker exec -it cloudflare_manager sh
#Run a non interactive command
docker exec -it cloudflare_manager cat logs.txtThe system requires some time to build the working environment. A log file, LOGS.txt, is generated, containing all the commands executed during the entire process.
# List the containers
docker compose ps -a
docker compose rm# Initializes all modules
terraform init
# Generate an execution plan that shows the changes needed to reach the desired state
terraform plan
# Execute the plan to create or update the infrastructure
terraform apply
# Target specific module
terraform plan -target=module.1a2b3c4d
terraform apply -target=module.5e6f7g8hdocker rmi -f cloudflare_manager
docker rmi $(docker images -q)
docker system prune -af && docker image prune -af && docker system prune -af --volumes && docker system df






