On this page

Managing Gates With Terraform

Define Statsig feature gates as Terraform resources, including rules, conditions, and rollout percentages, for fully reproducible feature flag setups.

You can create a .tf file (Terraform File) to configure your Statsig feature gates. The file supports all features of console/v1/gates. The layout is similar to the JSON body of a /gates request.

Require the Statsig provider and update the version to match your installed release:

go
terraform {
  required_providers {
    statsig = {
      version = "x.x.x"
      source  = "statsig-io/statsig"
    }
  }
}

Basic example

The following creates a basic gate resource:

go
resource "statsig_gate" "my_gate" {
  name        = "my_gate"
  description = "A short description of what this Gate is used for."
  is_enabled  = true
  id_type     = "userID"
  rules {
    name            = "Public"
    pass_percentage = 100
    conditions {
      type = "public"
    }
  }
}

Conditions

The provider supports all Console API conditions, but the syntax requires minor adjustments.

go
conditions {
  type         = "custom_field"
  target_value = ["31"]
  operator     = "gt"
  field        = "age"
}
Refer to the full list of conditions.

You can find a full gate example in the open source Github repo https://github.com/statsig-io/terraform-provider-statsig/blob/main/examples/resources/statsig_gate/resource.tf

Was this helpful?