Deploy feature flags with the Google Cloud console
Before you begin
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the App Lifecycle Manager, SaaS Config, App Design Center, Artifact Registry, Cloud Storage, and Infrastructure Manager APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the App Lifecycle Manager, SaaS Config, App Design Center, Artifact Registry, Cloud Storage, and Infrastructure Manager APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
Ensure that your user account has the following Identity and Access Management roles on your
Google Cloud project:
- App Lifecycle Manager Admin (
roles/saasservicemgmt.admin) - App Design Center Admin (
roles/designcenter.admin) - SaaS Config Viewer (
roles/saasconfig.viewer) - Service Account Admin (
roles/iam.serviceAccountAdmin) and Project IAM Admin (roles/resourcemanager.projectIamAdmin)
- App Lifecycle Manager Admin (
-
Ensure that an App Design Center space and the
App Lifecycle Manager service accounts
are configured, including a user-managed
actuation service account
granted the Service Account Token Creator
(
roles/iam.serviceAccountTokenCreator), Infra Manager Admin (roles/config.admin), and Storage Admin (roles/storage.admin) roles on your project. For more information about App Lifecycle Manager service accounts, see Service accounts. -
Install Python 3.10 or later and
pipon your local machine, and then authenticate Google Cloud CLI for Application Default Credentials (ADC):gcloud auth application-default login
Create a SaaS offering in the console
Create a SaaS offering resource as the top-level container for your service model and feature flags:
In Google Cloud console, go to App Lifecycle Manager > SaaS offerings.
Click Create.
In the SaaS offering name field, enter
flags-quickstart-offering.In the Region list, select
us-central1, and then click OK.Click Create. When creation completes, the SaaS offering details page opens.
Model your service in App Design Center
In the App-Centric workflow, you define unit kinds by authoring an application template in App Design Center. When you want to use feature flags without provisioning cloud infrastructure through App Lifecycle Manager, you create a composite template containing an empty standard application template for each kind of service in your architecture (for example, a backend app, frontend app, or gateway service). An empty standard template declares a service type without deploying cloud resources. When you're ready to manage infrastructure deployments through App Lifecycle Manager, you can add Terraform components to the standard template.
To create an empty standard template inside a composite template and generate a unit kind, complete these steps:
- On the SaaS offering details page for
flags-quickstart-offering, click Create new template. - In the Template ID field, enter
flags-composite-template, and then click Create template. - In the Connected application template section, click the Manage template menu, and then click Configure in canvas to open App Design Center.
- In the Components area on the design canvas, click Embed template, and then click Create a new template.
- In the Template ID field, enter
backend-service-template, and then click Create template to open the standard template canvas. - Leave the
backend-service-templatecanvas empty without adding components, and then click Add to Catalog to publish the standard template to your space's catalog. - Return to the
flags-composite-templatedesign canvas, click Embed template, selectbackend-service-templatefrom Templates, and then click Select. - Click Add to Catalog to publish the composite template revision, and then click Continue > Deploy at scale with App Lifecycle Manager.
- In the Connected application template section of the SaaS offering
details page, click Update template revision, select the latest
revision of
flags-composite-template, and then click Update (or click Connect existing template if connecting a template created directly in App Design Center). - Open the Unit kinds tab on the SaaS offering details page and verify
that App Lifecycle Manager created the unit kind for
backend-service-template.
Create and provision a unit
Create and provision a unit to represent a regional instance of your service
that receives feature flag configurations. Because your standard template in
App Design Center is empty, provisioning runs a no-operation
infrastructure actuation without deploying cloud resources and transitions the
unit to the Ready state so saasconfig.googleapis.com can serve its
feature flag configuration:
In Google Cloud console, go to App Lifecycle Manager > Units.
Click Create.
In the Unit name field, enter
backend-service-unit.In the SaaS offering list, select
flags-quickstart-offering.In the Region list, select
us-central1.In the Unit kind list, select your
backend-service-template-unit kind generated in the preceding section.Click Create. When creation completes, the Unit details page opens.
On the Unit details page, click Provision to open the Provision unit panel.
In the Release list, select the generated release for your
backend-service-template-unit kind.In the Service account list, select your actuation service account, and then select Grant App Lifecycle Manager permission to act on behalf of the actuation service account.
Click Add tenant project variables, and then select your project to populate
tenant_project_idandtenant_project_number.Click Provision, and then wait for the unit State on the Unit details page to reach Ready.
Create and deploy a feature flag in the console
Define a boolean feature flag and run a rollout to deliver the flag release to your unit:
- In Google Cloud console, open App Lifecycle Manager > Feature flags, and then click Create feature flag.
- In the Unit kind field, select your
backend-service-template-unit kind. - In the Flag key field, enter
enable-new-feature(Flag id autofills automatically after you enter the flag key). - Set Flag value to
enabled, and then click Create. - Go to App Lifecycle Manager > Flag releases, and then click Create.
- Enter
enable-new-feature-rel-1in the Flag release name field, select yourbackend-service-template-unit kind in the Unit kind list, select Feature flag in the Release type list, select yourenable-new-featureflag in the Select feature flags list, and then click Create. App Lifecycle Manager creates the underlying flag revision automatically. - Go to App Lifecycle Manager > Rollout kinds, and then click Create.
- In the Rollout kind name field, enter
flags-quickstart-rollout-kind. - In the Unit Kind list, select your
backend-service-template-unit kind. - In the Rollout Strategy list, select All locations at once.
- Click Create.
- Go to App Lifecycle Manager > Rollouts, and then click Create.
- Select Feature flags rollout.
- In the Rollout name field, enter
flags-quickstart-rollout. - In the Unit Kind list, select your
backend-service-template-unit kind. - In the Feature flags release list, select
enable-new-feature-rel-1, and then click Next. - Select Select existing rollout kind, and then select
flags-quickstart-rollout-kindin the Rollout Kind list. - Click Create to start the rollout and deliver the configuration to
backend-service-unit. - Wait for the rollout status to reach Succeeded.
Evaluate the feature flag
Evaluate the enable-new-feature flag locally using the OpenFeature SDK and the
flagd provider connected to saasconfig.googleapis.com:443:
Install the required Python packages:
pip install --upgrade google-auth grpcio requests "openfeature-sdk>=0.8.2" "openfeature-provider-flagd>=0.6.1"Create a file named
evaluate_flag.pywith the following code:import os import time import google.auth import google.auth.transport.grpc import google.auth.transport.requests import grpc from openfeature import api from openfeature.contrib.provider.flagd import FlagdProvider from openfeature.contrib.provider.flagd.config import ResolverType provider_id = os.environ["FLAGD_SOURCE_PROVIDER_ID"] credentials, _ = google.auth.default( scopes=["https://www.googleapis.com/auth/cloud-platform"] ) channel_creds = grpc.composite_channel_credentials( grpc.ssl_channel_credentials(), grpc.metadata_call_credentials( google.auth.transport.grpc.AuthMetadataPlugin( credentials, google.auth.transport.requests.Request() ) ), grpc.metadata_call_credentials( lambda ctx, cb: cb( [("x-goog-request-params", f"name={provider_id}")], None ) ), ) api.set_provider( FlagdProvider( resolver_type=ResolverType.IN_PROCESS, host="saasconfig.googleapis.com", port=443, sync_metadata_disabled=True, provider_id=provider_id, channel_credentials=channel_creds, ) ) time.sleep(5) value = api.get_client().get_boolean_value("enable-new-feature", False) print(f"Flag 'enable-new-feature' evaluated to: {value}")Set the
FLAGD_SOURCE_PROVIDER_IDenvironment variable to your unit's feature flag configuration resource path and run the script:export FLAGD_SOURCE_PROVIDER_ID="projects/PROJECT_ID/locations/us-central1/featureFlagsConfigs/backend-service-unit" python evaluate_flag.pyReplace
PROJECT_IDwith your Google Cloud project ID.The script outputs
Flag 'enable-new-feature' evaluated to: True.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
To avoid ongoing charges, either delete your test project in
Manage resources,
or remove the resources that you created in reverse dependency order. Marking a
feature flag for cleanup (CLEANUP state) to unlink it from a unit kind
requires the gcloud CLI or the App Lifecycle Manager API:
Set the flag state to
cleanup, create a cleanup flag release, and run a cleanup rollout to unlink the flag from your unit kind:gcloud beta app-lifecycle-manager flags update FLAG_ID \ --project=PROJECT_ID \ --location=global \ --state=cleanup gcloud beta app-lifecycle-manager flags releases create enable-new-feature-cleanup-rel \ --project=PROJECT_ID \ --unit-kind=UNIT_KIND_ID \ --flags=FLAG_ID \ --location=global gcloud beta app-lifecycle-manager rollouts create enable-new-feature-cleanup-rollout \ --project=PROJECT_ID \ --flag-release=enable-new-feature-cleanup-rel \ --rollout-kind=flags-quickstart-rollout-kind \ --location=globalReplace the following:
FLAG_ID: the ID of your feature flag (autofilled asUNIT_KIND_ID-enable-new-feature).PROJECT_ID: your Google Cloud project ID.UNIT_KIND_ID: the ID of yourbackend-service-template-unit kind.
After the cleanup rollout reaches Succeeded, delete the rollouts, rollout kind (
flags-quickstart-rollout-kind), and flag releases (enable-new-feature-rel-1andenable-new-feature-cleanup-rel) in Google Cloud console.Look up and delete the auto-generated flag revisions, and then delete your feature flag:
gcloud beta app-lifecycle-manager flags revisions list \ --project=PROJECT_ID \ --location=global \ --filter="flag:FLAG_ID" gcloud beta app-lifecycle-manager flags revisions delete REVISION_ID \ --project=PROJECT_ID \ --location=globalReplace
REVISION_IDwith each revision ID returned by thelistcommand, and then delete the feature flag in Google Cloud console.Deprovision
backend-service-uniton its Unit details page (click Deprovision, confirm in the dialog, and wait for the state to reach Not provisioned), and then delete the remaining resources in reverse dependency order: unit (backend-service-unit), the unit kind's default release association and generated blueprint release (clear the default release on the unit kind before deleting the blueprint release), unit kind, and SaaS offering (flags-quickstart-offering). For App Lifecycle Manager deletion rules, see Delete resources.Delete
flags-composite-templateandbackend-service-templatein App Design Center.
What's next
- Read the App Lifecycle Manager feature flags overview.
- Try the Deploy feature flags quickstart for infrastructure-managed deployments.
- Configure percentage-based traffic splits in Use gradual feature rollouts.
- Diagnose flag evaluation or rollout issues in Troubleshoot feature flags.