Skip to main content
Terraform simplifies the duplication of CDN configurations across environments, ensuring consistency and reliability. By managing environment-specific variables and using workspaces, you can maintain identical setups across your staging and production environments.
TipTo proceed with the following steps, you need to have API keys configured.

Step 1: Define variables

One of the key benefits of Terraform is its ability to manage configurations through variables, making it easier to handle environment-specific settings. Create a variables.tf file to define parameters that change between environments, such as API URL, token, or CDN resource names.

Step 2: Configure environment variables

Create .tfvars file for each environment to set the variable values. For example, for preproduction:
And for production:

Step 3: Write configurarion for copying resources

Add the following Terraform configuration to the main.tf :

Step 4: Use Terraform workspaces

Terraform workspaces allow you to manage multiple environments using the same configuration. Initialize Terraform: terraform init Then create workspaces for preproduction and production:

Step 5: Apply the configuration

Switch to the staging workspace and apply the configuration:
Then switch to the production workspace and apply the configuration there as well:
By using Terraform workspaces and variable files, you can apply the same configuration to different environments with a few commands.