Use flag sets

This guide shows you how to group flags, create releases from sets, and configure flags to subscribe to flag sets.

Flag sets are logical containers for managing groups of related feature flags. As your applications grow and the number of individual flags increases, managing them in a flat list can become cumbersome and error-prone.

Flag sets allow you to organize flags based on functional area, application component, or any other logical criteria, providing a higher-level abstraction for flag operations.

Prerequisites

Before you begin, ensure you have:

  1. A gcloud environment configured to manage App Lifecycle Manager resources.
  2. Completed the Deploy feature flags quickstart.

Group feature flags

To group flags, you associate them with a flag_set identifier during creation, or update an existing flag. This identifier creates a clear boundary of ownership and lets you use the flags set as a single resource.

Create a flag in a flag set

gcloud beta app-lifecycle-manager flags create "auth-flag" \
    --key="auth-flag" \
    --flag-value-type=BOOL \
    --location=global \
    --flag-set="auth-module-flags" \
    --description="Flag for the core authentication service."

Update an existing flag to add to a flag set

gcloud beta app-lifecycle-manager flags update "auth-flag" \
    --location="global"
    --flag-set="auth-module-flags"

Create a release from a flag set

Instead of manually creating point-in-time snapshots (FlagRevisions) for every flag, you can create a FlagRelease that references one or more sets. App Lifecycle Manager automatically handles the creation of all necessary immutable snapshots.

gcloud beta app-lifecycle-manager flags releases create "auth-release-v1.2" \
    --location=global \
    --flag-sets='["auth-module-flags"]' \
    --unit-kind="UNIT_KIND_NAME"

Replace UNIT_KIND_NAME with your unit kind.

Create a release for all flags

You can set the all_flags boolean to true to fetch all flags linked to the rollout's unit kind:

gcloud beta app-lifecycle-manager flags releases create "all-flags-release" \
    --location=global \
    --all-flags \
    --unit-kind="UNIT_KIND_NAME"

Consuming a flag set

To subscribe to a flag set, use a selector when you initialize the OpenFeature provider.

Go example:

The selector tells the flag source to filter for this specific set:

provider := flagd.NewProvider(
    // The selector tells the flag source to filter for this specific set
    flagd.WithSelector("flagSetId=auth-module-flags"),
    // ... other options
)

Selector Behavior:

  • Empty selector: Selects only flags that have no flag set ID.
  • flagSetId=*: Selects all flags associated with the unit.
  • flagSetId=X: Selects only flags where the set is exactly X.

What's next