Step 1. Define variables
Create avariables.tf file to declare the parameters that differ between environments. The following variables are common across all products:
- CDN
- Cloud
- DNS
Step 2. Configure environment variables
Create a separate.tfvars file for each environment. The common fields are identical across products:
- CDN
- Cloud
- DNS
Step 3. Write the resource configuration
Add the following tomain.tf. The provider block is identical for all products:
- CDN
- Cloud
- DNS
Step 4. Initialize Terraform
From the project directory, run:Step 5. Use Terraform workspaces
Terraform workspaces manage multiple environments from the same configuration — each workspace maintains an independent state file, so changes inpreprod do not affect production.
Create workspaces for preproduction and production: