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.

The provider authenticates with an API token. Use an organization API token, so your applies keep working when the member who generated it changes role or leaves. The audit log then shows the changes as made by the token. A token with selected projects cannot create projects or manage webhooks or integrations, so a configuration that does any of those needs a token with all projects.

From version 0.12.0 of the provider, when ConfigDirector refuses a request because a request rate limit was reached, the provider waits the seconds ConfigDirector names and sends the request again, up to three times, so a large plan or apply pauses instead of stopping partway.

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, and its ratio, funnel and retention from version 0.10.0. A metric of one event name is the events with that 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. A metric can also be a ratio, a funnel or a retention in place of an event name. 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.

Ratio, funnel and retention metrics

A ratio divides one total by another, such as revenue per order; a funnel gives the share of exposed contexts that reached the last of its steps, such as getting from the cart to a purchase; and a retention metric gives the share of contexts that sent an event between a first and a last day after their first exposure, such as coming back in the second week, among the contexts whose last day has ended. Each takes the place of event_name:

main.tf
resource "configdirector_metric" "revenue_per_order" {
  project_id = configdirector_project.example.id
  ratio = {
    numerator   = { event_name = "checkout_completed", adds = "value" }
    denominator = { event_name = "checkout_completed", adds = "events" }
  }
  direction = "higher-is-better"
}

resource "configdirector_metric" "cart_to_purchase" {
  project_id = configdirector_project.example.id
  funnel = {
    steps = [
      { event_name = "cart_viewed" },
      { event_name = "checkout_started" },
      { event_name = "checkout_completed" },
    ]
  }
  direction = "higher-is-better"
}

resource "configdirector_metric" "second_week_return" {
  project_id = configdirector_project.example.id
  retention = {
    event_name = "app_opened"
    first_day  = 7
    last_day   = 13
  }
  direction = "higher-is-better"
}

A ratio's numerator and denominator each name an event and what it adds up: events, where each event adds 1, or value, where each event adds its value. A side that adds value can sum a value_field of the event's details instead, and a side that adds events takes none. A funnel has 2 to 5 steps, in the order a context reaches them, and two steps can name the same event when their filters differ. A retention's first_day and last_day are whole numbers from 1 to 90, the last no earlier than the first, where a day is 24 hours counted from a context's own first exposure, so days 7 to 13 are the second week. Every side, step and retention takes its own filter, written as a metric's filter is.

These metrics leave kinds out, and the plan and state show the one kind each reports, ratio, funnel or retention, which is also the primary_kind of an experiment that decides on one of them. A run counts them only from the moment they are attached to the experiment. A definition that ConfigDirector would refuse fails the plan, such as two definitions on one metric, a definition beside event_name, filter, value_field or kinds, a funnel with fewer than 2 or more than 5 steps or with a step that repeats an earlier one, a retention day outside 1 to 90 or a last day before the first, or a value_field on a side that adds events. ConfigDirector refuses a metric with the same definition as another of the project when the apply creates it.

Attaching metrics to an experiment

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.

Replacing, removing and importing a metric

A metric keeps its event name, filter and value field, and a ratio, a funnel or a retention metric keeps its definition, so changing event_name, adding, changing or removing a condition of filter, changing value_field, or changing anything in ratio, funnel or retention, the order of a funnel's steps included, 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. A ratio, a funnel or a retention metric has no event name of its own, so you import it by its ID. 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 permissions 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 by their identifiers, 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, and only to a token with all projects.

Integrations

The configdirector_integration resource manages an integration, and is available from version 0.7.0 of the provider. An analytics integration marks experiment runs on the tool's charts, and a Slack integration, from version 0.11.0, posts the changes and alerts you choose to one Slack channel.

Analytics tools

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 analytics 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.

Slack

Set kind to slack and settings.webhook_url to the incoming webhook URL Slack created for the channel, as the Slack page shows. One integration posts to one channel, so give each channel its own. Acme's #incidents channel gets the alerts that reach Critical, opened with @here so everyone in the channel is notified, and no changes:

main.tf
variable "slack_incidents_webhook_url" {
  type      = string
  sensitive = true
}

resource "configdirector_integration" "incidents" {
  name = "#incidents"
  kind = "slack"
  settings = {
    webhook_url    = var.slack_incidents_webhook_url
    message_prefix = "@here"
  }
  event_types = []
  alert_kinds = [
    "default-value-served-too-often",
    "experiment-guardrail-worse",
    "integration-disabled",
    "webhook-disabled",
  ]
  minimum_priority = "critical"
}

event_types lists the changes the integration posts, as webhook event types. alert_kinds lists the alert kinds it posts by their identifiers, such as config-not-found, and minimum_priority, one of low, medium, high, or critical, is the priority an alert of those kinds must reach to be posted. An alert raised at a lower priority is posted when its priority rises to the minimum. Set event_types = [] to post only alerts, or alert_kinds = [] to post only changes. Left out, the three take what a new Slack integration starts with: config and targeting rule changes, and the application request alerts at High and above. Removing one from the configuration returns it to that.

settings.message_prefix opens each message, in up to 200 characters, to notify people: @here, @channel, @everyone, or a user group in Slack's own form, such as <!subteam^S0123ABC>; the Slack page says who each one notifies. Leave it out for messages without one. settings.post_resolved_alerts says whether an alert that resolves gets one line, without the prefix, in the channel it was posted to; it is true when left out.

Leave project_ids, environment_ids, and tag_ids empty to post the changes and alerts of every project, environment, and tag; the filters explain what each one lets through. An organization can have up to 20 Slack integrations, besides its 10 analytics integrations.

Credentials, disabling, and importing

Keys, tokens, secrets, and Slack webhook URLs 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. ConfigDirector also disables a Slack integration as soon as Slack refuses a message for good, for example because the channel was archived or the webhook URL was removed, and the Integration disabled alert says why. The next apply enables that one again too, so fix the cause first, for example with a new webhook URL in settings.webhook_url, or the next message disables it again.

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, secrets, and Slack webhook URLs, 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, and only to a token with all projects.

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.