Skip to content

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.

  1. Install Terraform 1.0 or later. The provider uses plugin protocol 6.
  2. 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-Token does not work.
  1. Install Terraform by following the official Install Terraform guide.

  2. Create a new directory for your Terraform configuration:

    Terminal window
    mkdir quant-terraform-project
    cd quant-terraform-project
  3. Create a main.tf file in this directory to define your Terraform configuration.

  1. In your main.tf file, 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"
    }
  2. Replace "your_organization_id_here" with your organisation machine name.

  3. 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 bearer in the provider block from a sensitive variable. Do not write the token in a .tf file.

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.

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"
}
  1. Initialize the Terraform working directory:
Terminal window
terraform init
  1. Review the planned changes:
Terminal window
terraform plan
  1. Apply the configuration:
Terminal window
terraform apply

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
Terminal window
terraform import quant_domain.www "my-project/9555"
  • 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_is and others) and the headers map of quant_header are replaced as a whole. A value added in the dashboard is removed on the next apply.
  • Set name and project on 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-only to see what changed on the platform without changing anything.
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.