Get Started
Terraform is an open-source infrastructure as code tool that allows you to define and manage your infrastructure resources in a declarative way. This guide will help you get started with using the Quant Terraform provider to manage your QuantCDN resources.
Prerequisites
Section titled “Prerequisites”- Install Terraform 1.0 or later. The provider uses plugin protocol 6.
- Have a Quant account and a dashboard API token. Tokens are per platform: create the token on the dashboard of the platform you use. A project
Quant-Tokendoes not work.
Installation
Section titled “Installation”-
Install Terraform by following the official Install Terraform guide.
-
Create a new directory for your Terraform configuration:
Terminal window mkdir quant-terraform-projectcd quant-terraform-project -
Create a
main.tffile in this directory to define your Terraform configuration.
Configuration
Section titled “Configuration”-
In your
main.tffile, add the Quant provider block:terraform {required_providers {quant = {source = "quantcdn/quant"version = "~> 5.14" # Allows 5.14 and later 5.x releases}}}provider "quant" {organization = "your_organization_id_here"# QuantGov only: the bare dashboard host, with no path.# base_url = "https://dash.quantgov.cloud"} -
Replace
"your_organization_id_here"with your organisation machine name. -
Set the API token in the environment instead of the configuration file:
Terminal window export QUANTCDN_API_TOKEN="<your-dashboard-api-token>"You can also set
bearerin the provider block from asensitivevariable. Do not write the token in a.tffile.
Platform and base_url
Section titled “Platform and base_url”base_url is the bare dashboard host of your platform. The provider adds the API path (/api/v2 or /api/v3) itself, so a value that ends in /api/v2 doubles the path and every request fails.
| Platform | base_url |
|---|---|
| QuantCDN (default) | https://dashboard.quantcdn.io |
| QuantGov | https://dash.quantgov.cloud |
Each setting also has an environment variable: QUANTCDN_API_TOKEN (bearer), QUANTCDN_ORGANIZATION (organization), QUANTCDN_BASE_URL (base_url) and QUANTCDN_TIMEOUT_SECONDS (timeout_seconds, default 120). Terraform state holds secrets such as project write tokens and KV values, so use an encrypted remote backend.
Define Resources
Section titled “Define Resources”Now you can start defining QuantCDN resources in your main.tf file. For example, to create a new project:
resource "quant_project" "example" { name = "example" description = "An example project"}Initialize and Apply
Section titled “Initialize and Apply”- Initialize the Terraform working directory:
terraform init- Review the planned changes:
terraform plan- Apply the configuration:
terraform applyImport existing resources
Section titled “Import existing resources”To manage a resource that you created in the dashboard, write the resource block, import it, then run terraform plan until it shows no changes. Do not delete and re-create the resource.
| Resource | Import ID |
|---|---|
quant_project |
Project machine name |
quant_domain |
project/domain_id (numeric ID) |
quant_header |
Project machine name |
quant_rule_* (all rule types) |
project/rule_uuid |
quant_crawler |
project:crawler_uuid (bare uuid = project default) |
quant_crawler_schedule |
project:crawler_uuid:schedule_id |
quant_kv_store |
project/store_id |
quant_kv_item |
project/store_id/key |
quant_application |
Application name |
quant_environment |
application/env_name |
quant_volume |
application/environment/volume_id |
quant_cron_job |
application/environment/cron_name |
terraform import quant_domain.www "my-project/9555"Drift and one tool per resource
Section titled “Drift and one tool per resource”- Apply overwrites any difference from your configuration. A rule that Terraform manages should not be edited in the dashboard.
- Lists on a rule (
url,domain,ip_isand others) and theheadersmap ofquant_headerare replaced as a whole. A value added in the dashboard is removed on the next apply. - Set
nameandprojecton every rule. They are optional in the schema and filled in from the API when omitted. - Traffic source and user agent conditions on a bot challenge rule can be set only in the dashboard. Keep those rules in the dashboard, not in Terraform.
- Run
terraform plan -refresh-onlyto see what changed on the platform without changing anything.
Troubleshooting
Section titled “Troubleshooting”| Error | Cause and fix |
|---|---|
| Every request fails with 404 or an HTML page | base_url ends in /api/v2 or /api/v3. Use the bare dashboard host. |
Provider returned invalid result object after apply |
A provider bug: a computed attribute stayed unknown after the API call. It is not a configuration error. Run terraform plan before applying again (the object may already exist), upgrade with terraform init -upgrade, and report it at the provider issue tracker if it persists on the latest release. |
does not support resource type |
The version constraint is too old. Use ~> 5.14. |
Invalid import ID |
Use the formats in the import table. Rule IDs need a valid UUID. |
Next Steps
Section titled “Next Steps”- Explore the Quant Terraform Provider Documentation for more resources and data sources.
- Learn about Terraform state management to collaborate with team members.
- Set up remote state storage for better team collaboration and security.
