FeatureSignals

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:

versions.tfhcl
1
2
3
4
5
6
7
8
9
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.tfhcl
1
2
3
4
5
6
7
8
# 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:

flags.tfhcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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:

segments.tfhcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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:

environments.tfhcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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

api_keys.tfhcl
1
2
3
4
5
6
7
8
9
10
11
12
13
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

webhooks.tfhcl
1
2
3
4
5
6
7
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:

main.tfhcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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 plan to preview changes before applying. The provider computes the diff between your configuration and the live FeatureSignals state.
  • Applyterraform apply provisions resources idempotently.
  • Import — Use terraform import to bring existing flags and segments under Terraform management.
  • Destroyterraform destroy cleans up resources. Production environments are protected by default.

Importing Existing Resources

Already have flags in FeatureSignals? Import them into Terraform state:

Import existing flagBash
1
2
3
4
5
# 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

Learn More