Integrations

Terraform Provider

Manage projects, environments, configs, tags, targeting rules, segments, metrics, webhooks, and integrations as code with the ConfigDirector Terraform provider

Introduction

The ConfigDirector Terraform provider allows you to manage projects, environments, configs, tags, targeting rules, segments, metrics, webhooks, and integrations via Terraform and OpenTofu.

To make the same changes from an AI coding assistant instead, see the MCP server.

Refer to the official ConfigDirector Terraform provider documentation for a full guide on all the features available in the provider.

Example

Here is a minimal example on how to use the provider:

main.tf
terraform {
  required_providers {
    configdirector = {
      source  = "ConfigDirector/configdirector"
      version = "~> 0.6"
    }
  }
}

provider "configdirector" {}

resource "configdirector_project" "example" {
  name = "Targeting Rules Example"
  slug = "targeting-rules-example"
}

resource "configdirector_config" "beta_features" {
  project_id    = configdirector_project.example.id
  key           = "beta-features"
  role          = "flag"
  type          = "boolean"
  initial_value = false
}

resource "configdirector_config_targeting_rules" "beta_features_test" {
  project_id       = configdirector_project.example.id
  config_key       = configdirector_config.beta_features.key
  environment_slug = "test"
  default_value    = "false"

  rules = [
    {
      id     = provider::configdirector::rule_id("beta-features-test-named-testers")
      type   = "conditional"
      order  = 0
      target = "value"
      value  = true
      conditions = [
        {
          id           = provider::configdirector::rule_id("beta-features-test-named-testers-identifier")
          attribute    = "identifier"
          operator     = "is one of"
          targetType   = "text"
          targetValues = ["user-101", "user-202"]
        }
      ]
    }
  ]
}

resource "configdirector_config_targeting_rules" "beta_features_production" {
  project_id       = configdirector_project.example.id
  config_key       = configdirector_config.beta_features.key
  environment_slug = "production"
  default_value    = "false"

  rules = [
    {
      id     = provider::configdirector::rule_id("beta-features-production-rollout")
      type   = "percentage"
      order  = 0
      target = "percentage"
      percentages = [
        {
          id         = provider::configdirector::rule_id("beta-features-production-rollout-on")
          percentage = 10
          value      = true
        },
        {
          id         = provider::configdirector::rule_id("beta-features-production-rollout-off")
          percentage = 90
          value      = false
        },
      ]
    }
  ]
}

A condition can also test the context kind: set attribute to "kind", targetType to "text", and operator to "equals", "does NOT equal", "is one of", or "is NOT one of", with context kinds as the target values. A context sent without a context kind is tested as user. For example, this condition matches only devices:

{
  id           = provider::configdirector::rule_id("beta-features-test-devices-kind")
  attribute    = "kind"
  operator     = "equals"
  targetType   = "text"
  targetValues = ["device"]
}

Segments

The configdirector_segment resource manages a segment, and is available from version 0.3.0 of the provider. groups holds the project definition as a list of condition groups, each a list of attribute conditions in the same shape as in targeting rules. overrides maps an environment id to that environment's own groups.

The resource owns every override of the segment: leaving overrides out, or removing an environment from it, removes that override. groups and overrides are sent as written and never read back, the same as the rules of configdirector_config_targeting_rules, so changes made outside Terraform do not show as drift.

A targeting rule uses the segment through a segment condition with kind = "segment", an operator of "in" or "not in", and the segment's id as segmentId. Continuing the example above:

main.tf
resource "configdirector_environment" "staging" {
  project_id = configdirector_project.example.id
  name       = "Staging"
  slug       = "staging"
  color      = "purple"
  live       = false
}

resource "configdirector_segment" "beta_testers" {
  project_id = configdirector_project.example.id
  key        = "beta-testers"
  name       = "Beta testers"

  groups = [
    [
      {
        id           = provider::configdirector::rule_id("beta-testers-acme-email")
        attribute    = "traits"
        trait        = "/email"
        operator     = "ends with any of"
        targetType   = "text"
        targetValues = ["@acme.com"]
      }
    ],
    [
      {
        id           = provider::configdirector::rule_id("beta-testers-opted-in")
        attribute    = "traits"
        trait        = "/betaOptIn"
        operator     = "equals"
        targetType   = "boolean"
        targetValues = ["true"]
      },
      {
        id           = provider::configdirector::rule_id("beta-testers-app-version")
        attribute    = "appVersion"
        operator     = ">="
        targetType   = "semver"
        targetValues = ["2.0.0"]
      }
    ]
  ]

  overrides = {
    (configdirector_environment.staging.id) = [
      [
        {
          id           = provider::configdirector::rule_id("beta-testers-staging-named-users")
          attribute    = "identifier"
          operator     = "is one of"
          targetType   = "text"
          targetValues = ["qa-user-1", "qa-user-2"]
        }
      ]
    ]
  }
}

resource "configdirector_config" "new_checkout_flow" {
  project_id    = configdirector_project.example.id
  key           = "new-checkout-flow"
  role          = "flag"
  type          = "boolean"
  initial_value = false
}

resource "configdirector_config_targeting_rules" "new_checkout_flow_production" {
  project_id       = configdirector_project.example.id
  config_key       = configdirector_config.new_checkout_flow.key
  environment_slug = "production"
  default_value    = "false"

  rules = [
    {
      id     = provider::configdirector::rule_id("new-checkout-flow-production-beta-testers")
      type   = "conditional"
      order  = 0
      target = "value"
      value  = true
      conditions = [
        {
          id        = provider::configdirector::rule_id("new-checkout-flow-production-beta-testers-segment")
          kind      = "segment"
          operator  = "in"
          segmentId = configdirector_segment.beta_testers.id
        }
      ]
    }
  ]
}

An existing segment is imported by the project's id or slug and the segment's key, for example terraform import configdirector_segment.beta_testers targeting-rules-example/beta-testers. The groups and overrides cannot be read back, so the first apply after an import sends whatever the configuration declares.

Metrics

The configdirector_metric resource defines what an experiment measures, and is available from version 0.8.0 of the provider; its filter and value_field are available from version 0.9.0. A metric is the events with one name your application sends with the SDK's track call, all of them or only those whose details match the metric's filter, with whether a higher or a lower number is better and the kinds its results report: conversion, count-per-context, and value-per-context (how each is computed). A project can have several metrics on one event name, told apart by their filter and value field. An experiment attaches metrics with metrics on configdirector_config, and says what the team expects in hypothesis:

main.tf
resource "configdirector_metric" "checkout_completed" {
  project_id  = configdirector_project.example.id
  event_name  = "checkout_completed"
  description = "A customer paid for their order."
  direction   = "higher-is-better"
  kinds       = ["conversion", "value-per-context"]
}

resource "configdirector_metric" "team_checkout_items" {
  project_id = configdirector_project.example.id
  event_name = "checkout_completed"
  filter = [
    { field = "/plan", target_type = "text", operator = "is one of", target_values = ["team", "enterprise"] },
  ]
  value_field = "/items"
  direction   = "higher-is-better"
  kinds       = ["conversion", "value-per-context"]
}

resource "configdirector_metric" "checkout_failed" {
  project_id = configdirector_project.example.id
  event_name = "checkout_failed"
  direction  = "lower-is-better"
  kinds      = ["count-per-context"]
}

resource "configdirector_config" "checkout_button_copy" {
  project_id    = configdirector_project.example.id
  key           = "checkout-button-copy"
  role          = "experiment"
  type          = "string"
  hypothesis    = "Urgent copy gets more customers to check out."
  initial_value = "Buy now"

  variations = [
    { name = "Control", value = "Buy now" },
    { name = "Urgency", value = "Buy now - limited stock" },
  ]

  metrics = [
    { metric_id = configdirector_metric.checkout_completed.id, role = "primary", primary_kind = "conversion" },
    { metric_id = configdirector_metric.team_checkout_items.id, role = "secondary" },
    { metric_id = configdirector_metric.checkout_failed.id, role = "guardrail" },
  ]
}

filter holds 1 to 5 conditions, in any order, all of which an event must match to count; leave it out to count every event with the name. Each condition's field is a JSON pointer into the details your application sends with the event, such as /plan. A text condition takes is one of or is NOT one of, with up to 20 target_values; a number condition takes =, !=, >, >=, < or <=, with one number, such as "2"; and a boolean condition takes equals, with "true" or "false". A condition means what it means in a targeting rule, so a field an event lacks reads as empty text, and is NOT one of and != count an event without it. The Admin API describes the conditions in full. value_field is a JSON pointer to the field of the event's details holding the number that value-per-context sums in place of the event's value, so it needs value-per-context among kinds; an event without a number there still counts as an event and adds nothing to the sum.

A run counts a metric with a filter or a value field only from the moment the metric is attached to the experiment, so events reported before then are not in its numbers. A condition or a value field that ConfigDirector would refuse, such as a sixth condition, an operator of another type, or a value_field without value-per-context, fails the plan. ConfigDirector refuses a metric with the same event name, filter and value field as another of the project when the apply creates it.

Each metric in metrics has a role: one primary metric, with the primary_kind that decides the experiment, and the rest secondary or guardrail, up to 10 in all.

ConfigurationEffect
Omit metricsKeep the metrics attached in the dashboard
metrics = []Detach every metric
A set of metricsAttach exactly those, and undo changes made in the dashboard

Leaving hypothesis out keeps the current hypothesis, and hypothesis = "" removes it. Each run keeps the hypothesis it started with. Only an experiment has metrics or a hypothesis, so a metric or a hypothesis on another role fails the plan.

An apply that creates an experiment with metrics creates it first and attaches the metrics in a second request, so the audit log shows the creation and then a settings change. If attaching fails, for example because the primary kind is one its metric does not report, the apply fails and the next apply replaces the new experiment.

A metric keeps its event name, filter and value field, so changing event_name, adding, changing or removing a condition of filter, or changing value_field replaces the metric, and the experiments that reference it attach the new one in the same apply. Destroying or replacing a metric fails while an experiment it is attached to has an open run, so stop or ship the run first. To remove such a metric, you can also detach it in one apply and remove it in the next: an apply that does both can delete the metric before the experiment lets go of it.

Import a metric with the project's ID or slug and the metric's ID, for example terraform import configdirector_metric.team_checkout_items metric-example/0b9d6c1e-58a4-4c39-9a7e-3f1c2d5e8b01 or the same command with tofu. The metric's ID ends the address of its page in the dashboard. While only one metric has an event name, you can import it with the event name instead, for example terraform import configdirector_metric.checkout_failed metric-example/checkout_failed. Only the first slash separates the project from the event name, so an event name can contain slashes. When several metrics share the event name, the import fails and lists their IDs, each with its filter and value field:

2 metrics in project "metric-example" have the event name "checkout_completed".
Import one by its id, as metric-example/<metric id>:
  4f5a6b7c-8d9e-4f0a-9b1c-3d4e5f6a7b8c  checkout_completed
  0b9d6c1e-58a4-4c39-9a7e-3f1c2d5e8b01  checkout_completed · /plan is one of [team, enterprise] · value from /items

The API token needs metrics:read, metrics:create, metrics:update, and metrics:delete, and changing an experiment's metrics or hypothesis needs config-settings:update.

Config tags

Declare config assignments by name with tags on configdirector_config. A managed tag's .name reference makes Terraform or OpenTofu wait for that tag's creation or rename:

main.tf
resource "configdirector_tag" "payments" {
  project_id = configdirector_project.example.id
  name       = "Payments / EU & US"
}

resource "configdirector_config" "checkout" {
  project_id    = configdirector_project.example.id
  key           = "checkout-enabled"
  role          = "flag"
  type          = "boolean"
  initial_value = false
  tags          = [configdirector_tag.payments.name]
}

You can also assign existing literal names, such as tags = ["Payments / EU & US"]. Names are resolved within the config's project using the API's trimming and case-equivalent matching. Spaces, slashes, and punctuation are literal; do not URL-encode them. An unknown name fails with a diagnostic naming the tag and project. Assignments never create tags implicitly. Unknown .name references stay unknown during planning until the tag is available.

ConfigurationEffect
Omit tags, or use nullObserve names and preserve remote assignments
tags = []Clear every assignment and manage an empty selection
A nonempty set of namesManage that selection and correct assignment drift

Omission preserves assignments after import and during unrelated updates. Removing tags relinquishes ownership without clearing the selection. Import a config with <project_id_or_slug>/<key>, for example terraform import configdirector_config.checkout targeting-rules-example/checkout-enabled or the same command with tofu. After refresh, omit tags to preserve assignments or declare a set to take ownership.

Assignments are unordered and limited to 20 distinct project tags. Equivalent spellings share one stable ID; state retains configured spelling while the assigned tag IDs are unchanged, so casing and order alone do not cause repeated drift. A shared tag deletion detaches its assignments, and a declared name that no longer exists fails on the next write. Tags organize configs without affecting evaluation.

Name resolution requires tags:read. Creating a tagged config needs configs:create, and changing its tags later needs config-settings:update. Provider updates also read the config back, so include configs:read for that step. Omitted and empty selections need no catalog lookup. The tag resource separately needs tags:create, tags:update, and tags:delete for the corresponding catalog operations, plus tags:read for refresh. Missing scopes produce errors instead of silently skipping assignments.

data.configdirector_config.<name>.tags and each config in data.configdirector_configs.<name>.configs expose current assigned names under configs:read alone. No standalone tag lookup data source is required. The resource and data-source configuration is the same in Terraform and OpenTofu.

Assignment support can deploy once the catalog and assignment APIs are available on every API instance. It does not depend on config table filters or dashboard feature flags.

Webhooks

The configdirector_webhook resource manages a webhook, and is available from version 0.5.0 of the provider. Pass its secret to your receiver so it can verify each request:

main.tf
resource "configdirector_webhook" "ci" {
  name        = "CI pipeline"
  url         = "https://example.com/configdirector-webhooks"
  project_ids = [configdirector_project.example.id]
  headers = {
    Authorization = "Bearer ${var.ci_token}"
  }
}

module "ci_receiver" {
  source         = "./ci-receiver"
  signing_secret = configdirector_webhook.ci.secret
}

A webhook receives every change event type unless event_types lists some, and no alert events unless alert_kinds lists some, the same defaults as the dashboard's form. Set event_types = [] for a webhook that receives only alert events. Leave project_ids, environment_ids, and tag_ids empty to let everything through; the filters explain what each one lets through.

secret and headers are sensitive, so no plan shows them. The secret stays the same across updates. After a rotation on the webhook's page, the next refresh picks up the new secret and the next apply passes it on to your receiver. ConfigDirector never shows a header value again once it is saved, so Terraform notices a header added or removed outside Terraform but not a value changed there.

If ConfigDirector disables the webhook after repeated failures, the next apply enables it again while enabled is true, its default.

Import a webhook with its ID, for example terraform import configdirector_webhook.ci 01a18564-96d6-7026-bb0e-aab59053d921 or the same command with tofu. The first apply after an import writes the header values the configuration declares. The API token needs the webhooks:manage permission, which only owners and admins can grant.

Integrations

The configdirector_integration resource manages an integration that marks experiment runs on an analytics tool's charts, and is available from version 0.7.0 of the provider. Set kind to amplitude, mixpanel, datadog, grafana, or posthog, and fill in the settings that kind needs:

main.tf
resource "configdirector_integration" "amplitude" {
  name = "Amplitude"
  kind = "amplitude"
  settings = {
    data_center = "us"
    api_key     = var.amplitude_api_key
    secret_key  = var.amplitude_secret_key
  }
  project_ids = [configdirector_project.example.id]
}
KindSettings
amplitudedata_center, api_key, secret_key
mixpaneldata_residency, project_id, service_account_username, service_account_secret
datadogsite, api_key
grafanaurl, service_account_token
posthoghost, project_id, personal_api_key

Every setting in the table is required for its kind, and a plan that leaves one out, leaves one blank or uses a setting of another kind fails. Any kind can also set endpoint_url to post somewhere other than the address ConfigDirector composes. The tool's page explains where to find each value. Leave project_ids, environment_ids, and tag_ids empty to mark every run.

Keys, tokens, and secrets are sensitive, so no plan shows them. ConfigDirector never returns one once it is saved, so Terraform keeps the value from your configuration: changing one saves all of the integration's credentials on the next apply, and replacing one in the dashboard goes unnoticed. Changing any other setting leaves them as saved. Changing kind replaces the integration, which deletes its delivery log.

If ConfigDirector disables the integration after repeated failures, the next apply enables it again while enabled is true, its default.

Import an integration with its ID, for example terraform import configdirector_integration.amplitude 01a18564-96d6-7026-bb0e-aab59053d921 or the same command with tofu. An import reads everything except the keys, tokens, and secrets, so the first apply after it saves the ones in your configuration. The API token needs the integrations:manage permission, which only owners and admins can grant.

Deletion protection

A project or environment with deletion protection on cannot be deleted, so terraform destroy, or an apply that would remove the resource, fails with a message naming where to turn it off. The provider cannot change the setting. Projects and environments the provider creates start with it off; projects and live environments created in the dashboard start with it on, so turn it off in the dashboard before removing one of those from your configuration.

OpenTofu

The ConfigDirector provider is also available in the OpenTofu registry.