mixpanel_cohort (Resource)¶
Manages a Mixpanel cohort (mixpanel_cohort) — a saved user segment defined by behavioral and property filters, used to analyze and target specific user groups.
Example Usage¶
resource "mixpanel_cohort" "power_users" {
name = "Power Users"
project_id = 1234567
groups = jsonencode([
{
event = {
resourceType = "cohort"
value = "$all_users"
label = "All Users"
}
filters = []
filtersOperator = "and"
behavioralFilters = []
behavioralFiltersOperator = "or"
}
])
}
Schema¶
Optional¶
behaviors(Attributes) (see below for nested schema)cohort_id(Number)data_group_id(String)description(String)groups(String)is_locked(Boolean)is_visible(Boolean)name(String)project_id(Number)selector(Attributes) (see below for nested schema)share_with_project(Boolean) Whether to share this entity with the whole project after creation. Entities created by a service account are otherwise visible only to that service account. Defaults totrue. See the Entity sharing guide.
Read-Only¶
id(Number) The ID of this resource.
Nested Schema for behaviors¶
Nested Schema for selector¶
Plan-time validation of groups¶
A malformed cohort groups definition can be accepted by the API with a 200
and then crash the Mixpanel webapp query builder for the whole project. The
provider validates the decoded groups JSON at terraform plan time and
rejects the known-corrupting shapes before anything is sent:
- every filter group must carry an
eventclause withresourceTypeandvalue(e.g.event = {resourceType = "cohort", value = "$all_users", label = "All Users"}) — a group missing theeventclause is rejected with HTTP 400 "Missing or invalid 'resourceType'"; - every filter group must carry a
filtersarray (use[]for none) — a missing ornullfilterssaves but renders the cohort builder unusable; filtersOperatorandbehavioralFiltersOperatorare required on every group;groupingOperatoris required on every group except the last and must be"and"or"or";- filter entries with
filterOperator"is set"/"is not set"must not carry afilterValue; - boolean property filters compare against the strings
"true"/"false", never JSON booleans; - property filters name their property via
propertyName, notvalue.
Duplicate names, delete, and re-create¶
Cohort names are unique among active cohorts of a project. Deleting a
cohort is a soft delete, and a soft-deleted cohort does not block
re-creating one with the same name — terraform destroy followed by
terraform apply of the same-named cohort works.
A 409 Cohort with name "X" already exists on create therefore always means a
live cohort with that name exists (created in the webapp, from another
Terraform state, or left behind by an interrupted apply). The provider will
not silently adopt it; the error names the conflicting cohort id so you can
either terraform import it or pick a different name. (A soft-deleted cohort
can be restored out-of-band with PATCH /api/app/projects/{project_id}/cohorts/{id}
and body {"deleted": false}, but the restore also 409s while a live
duplicate name exists.)
Import¶
Cohorts can be imported using the composite PROJECT_ID:ID format: