Managing Gates With Terraform
Define Statsig feature gates as Terraform resources, including rules, conditions, and rollout percentages, for fully reproducible feature flag setups.
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.
| Field | Type | Description |
|---|---|---|
| type | string | The type of condition. |
| 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, and elements must be strings. Wrap numbers in quotes, for example 31 becomes "31". |
| field | string | Only for the custom_field condition type. The name of the field to pull for evaluation from the "custom" object on a user. |
go
conditions {
type = "custom_field"
target_value = ["31"]
operator = "gt"
field = "age"
}
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?