Terraform Provider
Use the FeatureSignals Terraform provider to manage your feature flags, segments, environments, API keys, and webhooks as Terraform resources. Declarative, version-controlled, and integrated with your existing Terraform workflows.
Installation
Declare the FeatureSignals provider in your Terraform configuration. The provider is available in the Terraform Registry:
terraform {
required_version = ">= 1.0"
required_providers {
featuresignals = {
source = "featuresignals/featuresignals"
version = "~> 1.0"
}
}
}
Provider Configuration
Configure the provider with your API token. Use environment variables or Terraform variables to keep secrets out of your configuration files:
# Provider configuration
provider "featuresignals" {
# Prefer environment variable: export FEATURESIGNALS_API_TOKEN="fs_api_..."
# api_token = var.featuresignals_api_token
# Optional: custom API endpoint for self-hosted deployments
# api_url = "https://featuresignals.yourcompany.com"
}
Set the FEATURESIGNALS_API_TOKEN environment variable instead of hardcoding tokens in your Terraform files. Terraform automatically reads this variable when api_token is not set.
Resource: Feature Flag
Create and manage feature flags with full lifecycle support:
# A simple boolean feature flag
resource "featuresignals_flag" "dark_mode" {
project_key = featuresignals_project.webapp.key
key = "dark-mode"
name = "Dark Mode"
description = "Enable the new dark mode UI"
type = "boolean"
default_value = jsonencode(false)
}
# A multi-variant flag with targeting rules
resource "featuresignals_flag" "checkout_v2" {
project_key = featuresignals_project.webapp.key
key = "checkout-v2"
name = "Checkout v2"
description = "New checkout experience with saved payment methods"
type = "boolean"
default_value = jsonencode(false)
# Gradual rollout targeting
targeting {
rule {
attribute = "email"
operator = "ends_with"
values = ["@beta.featuresignals.com"]
serve_value = true
}
}
# Percentage rollout for remaining traffic
rollout {
percentage = 10
serve_value = true
}
}
Resource: Segment
Define reusable targeting segments that can be shared across multiple flags:
resource "featuresignals_segment" "beta_users" {
project_key = featuresignals_project.webapp.key
key = "beta-users"
name = "Beta Users"
description = "Users enrolled in the beta program"
rule {
attribute = "email"
operator = "ends_with"
values = ["@beta.featuresignals.com", "@testers.featuresignals.com"]
}
rule {
attribute = "beta_access"
operator = "is"
values = ["true"]
}
}
Resource: Environment
Create environments and manage environment-specific flag overrides:
resource "featuresignals_environment" "staging" {
project_key = featuresignals_project.webapp.key
key = "staging"
name = "Staging"
description = "Pre-production staging environment"
}
resource "featuresignals_environment" "production" {
project_key = featuresignals_project.webapp.key
key = "production"
name = "Production"
description = "Production environment"
# Require change requests for flags in production
require_change_request = true
}
Resource: API Key
resource "featuresignals_api_key" "server_sdk" {
project_key = featuresignals_project.webapp.key
name = "Production Server SDK"
type = "server"
environment_keys = [featuresignals_environment.production.key]
}
resource "featuresignals_api_key" "client_sdk" {
project_key = featuresignals_project.webapp.key
name = "Production Client SDK"
type = "client"
environment_keys = [featuresignals_environment.production.key]
}
Resource: Webhook
resource "featuresignals_webhook" "slack_changes" {
project_key = featuresignals_project.webapp.key
name = "Slack Flag Changes"
url = "https://hooks.slack.com/services/T.../B.../..."
events = ["flag.created", "flag.updated", "flag.toggled"]
secret = var.webhook_signing_secret
}
Complete Example
Here's a complete Terraform configuration that provisions a project with environments, flags, segments, and API keys:
resource "featuresignals_project" "webapp" {
key = "webapp"
name = "Web Application"
description = "Main customer-facing web application"
}
resource "featuresignals_environment" "staging" {
project_key = featuresignals_project.webapp.key
key = "staging"
name = "Staging"
}
resource "featuresignals_environment" "production" {
project_key = featuresignals_project.webapp.key
key = "production"
name = "Production"
}
resource "featuresignals_segment" "internal" {
project_key = featuresignals_project.webapp.key
key = "internal-users"
name = "Internal Users"
rule {
attribute = "email"
operator = "ends_with"
values = ["@featuresignals.com"]
}
}
resource "featuresignals_flag" "new_dashboard" {
project_key = featuresignals_project.webapp.key
key = "new-dashboard"
name = "New Dashboard"
type = "boolean"
default_value = jsonencode(false)
targeting {
rule {
segment_key = featuresignals_segment.internal.key
serve_value = true
}
}
}
resource "featuresignals_api_key" "prod_sdk" {
project_key = featuresignals_project.webapp.key
name = "Production SDK Key"
type = "server"
environment_keys = [featuresignals_environment.production.key]
}
State Management
The provider supports full Terraform state management:
- Plan — Run
terraform planto preview changes before applying. The provider computes the diff between your configuration and the live FeatureSignals state. - Apply —
terraform applyprovisions resources idempotently. - Import — Use
terraform importto bring existing flags and segments under Terraform management. - Destroy —
terraform destroycleans up resources. Production environments are protected by default.
Importing Existing Resources
Already have flags in FeatureSignals? Import them into Terraform state:
# Import a flag by project key and flag key
terraform import featuresignals_flag.dark_mode webapp/dark-mode
# Import a segment
terraform import featuresignals_segment.beta_users webapp/beta-users