The v5 Terraform provider support in cf-terraforming is still a work-in-progress, but this is a preview of how the tool could be used to Terraform an existing set of configured Cloudflare resources, and extend it by adding a new resource via Terraform.
The main application of cf-terraforming is for creating a new Terraform project using existing configurations that aren't currently managed by Terraform.
The following resources are included in this demo:
Account-scoped:
✔️ Zones
✔️ Load Balancer Pools
✔️ R2 Buckets (new in v5)
Zone-scoped
✔️ Browser Cache TTL Zone Setting
✔️ IP Geolocation Zone Setting
✔️ Caching Level Zone Setting
✔️ Load Balancers
✔️ DNS Records
✔️ Workers KV Namespace
- Git, Go, and Terraform are installed locally
- You've cloned this repo
- You've populated the required environment variables in
env.sh
env.sh: Contains all of the required environment variables.configs/*: Terraform files that are used by the script.run-demo.sh: Script that buildscf-terraformingbinary, initializes the Terraform project, and generates and imports resources.create-r2-bucket.sh: Script that adds a new R2 Bucket config to the Terraform project and applies the change.clean-demo.sh: Cleans up the files and resources created by the demo so it can be cleanly re-ran if needed.
-
Move into the cloned project directory
-
Source your environment variables
source env.sh -
Generate and import resources from existing Cloudflare configurations
./run-demo.sh
This will go through each configured resource and create the Terraform project with the generated HCL. Once the HCL generation finishes, it will then import each resource into the project's Terraform state.
-
You can explore the generated Terraform in the
tf-projectdirectory. Each resource type will have its own file. -
Apply the Terraform to your account/zone
cd tf-project terraform fmt && terraform validate && terraform apply
There can be diffs on some resources because there are computed values that won't be in our HCL or state file.
-
Create a new resource (R2 Bucket)
cd .. ./create-r2-bucket.shThis script copies the bucket config from
configs/into the project, then applies the change. -
Verify that the R2 bucket is now in your CLoudflare account
curl https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/r2/buckets/demo-example-bucket \ -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
-
Once you're done exploring, clean up the demo artifacts
./clean-demo.sh
Note: The change that should get applied here is the deletion of the R2 bucket. If you see anything else getting destroyed, decline the Terraform apply.