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. All features of console/v1/gates are supported. The layout is very 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.

  • type | string | The type of condition it is.
  • operator | string | The form of evaluation to run against the target_value.
  • target_value | [string] | The value or values to evaluate. Must be an array; elements must be strings. (Wrap numbers in quotes: 31 -> "31")
  • field | string | Only for custom_field condition type. The name of the field you wish to pull for evaluation from the "custom" object on a user.
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?