Set environment variables Stay organized with collections Save and categorize content based on your preferences.
Cloud Composer 3 | Cloud Composer 2 | Cloud Composer 1
This page explains how to set environment variables in yourCloud Composer environment.
You can use environment variables as an alternative toAirflow variables when providing runtime configurationfor your DAGs. Airflow variables are set in the Airflow database, whileenvironment variables are set in the Airflow worker's container.
As an example, you can use an environment variable's name as is in a commandthat is run by a BashOperator, or get this value from theos.environ objectin the DAG, or use an Airflow variable instead.
Environment variables are persistent. Once you specify an environment variable,Airflow keeps using it until you remove the variable from your environment.
Important: It's not possible to use environment variables to configure Airflow.Override Airflow configuration options instead.Cloud Composer sets its own reserved environment variables for controllingenvironments.
Name format
Environment variables must match the regular expression[a-zA-Z_][a-zA-Z0-9_]*.
Airflow configuration options
It is not possible to specify variables that change Apache Airflowconfiguration options.
The variables cannot use theAIRFLOW__{SECTION}__{KEY} format or match theregular expressionAIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+. For example, it is notpossible to setAIRFLOW__WEBSERVER__DAG_DEFAULT_VIEW.
Instead, you canoverride Airflow configuration options.
Reserved variables
The following variable names are reserved by Cloud Composer. It isnot possible to create variables with these names.
AIRFLOW_DATABASE_VERSIONAIRFLOW_HOMEAIRFLOW_SRC_DIRAIRFLOW_WEBSERVERAUTO_GKECLOUDSDK_METRICS_ENVIRONMENTCLOUD_LOGGING_ONLYCOMPOSER_AGENT_BUILD_SERVICE_ACCOUNTCOMPOSER_ENVIRONMENTCOMPOSER_ENVIRONMENT_SIZECOMPOSER_GKE_LOCATIONCOMPOSER_GKE_NAMECOMPOSER_GKE_ZONECOMPOSER_LOCATIONCOMPOSER_OPERATION_UUIDCOMPOSER_PYTHON_VERSIONCOMPOSER_VERSIONCONTAINER_NAMEC_FORCE_ROOTDAGS_FOLDERGCE_METADATA_TIMEOUTGCP_PROJECTGCP_TENANT_PROJECTGCSFUSE_EXTRACTEDGCS_BUCKETGKE_CLUSTER_NAMEGKE_IN_TENANTGOOGLE_APPLICATION_CREDENTIALSMAJOR_VERSIONMINOR_VERSIONPATHPIP_DISABLE_PIP_VERSION_CHECKPORTPROJECT_IDPYTHONPYCACHEPREFIXPYTHONWARNINGSREDIS_PASSWORDREDIS_PORTREDIS_USERSQL_DATABASESQL_HOSTSQL_INSTANCESQL_PASSWORDSQL_PROJECTSQL_REGIONSQL_USER
Set environment variables for new environments
You can specify environment variables when you create an environment. For moreinformation, seeCreate environments.
Set environment variables for existing environments
Console
To set environment variables for an existing environment:
In Google Cloud console, go to theEnvironments page.
In the list of environments, click the name of your environment.TheEnvironment details page opens.
Go to theEnvironment variables tab and clickEdit.
Add, change, or delete environment variables for your environment:
- In theName field, specify the variable name.
- In theValue field, specify the variable value.
- To add an extra variable, clickAdd environment variable.
- To delete a variable, hold the pointer over a variable, then clickDelete item.
gcloud
Following arguments control environment variables:
--update-env-variablesspecifies a comma-separated list of environmentvariables to create or update.--remove-env-variablesspecifies a comma-separated list of environmentvariables to delete.--clear-env-variablesdeletes all existing environment variables.
gcloudcomposerenvironmentsupdate\ENVIRONMENT_NAME\--locationLOCATION\--update-env-variables=NAME=VALUEReplace:
ENVIRONMENT_NAMEwith the name of the environment.LOCATIONwith the region where the environment is located.NAMEwith the name of the variable that you want to create or update.VALUEwith the value for the variable.- To add more than one variable, separate the definitions with commas:
NAME=VALUE,NAME=VALUE,....
Example:
gcloudcomposerenvironmentsupdate\example-environment\--locationus-central1\--update-env-variables=EXAMPLE_VARIABLE=True,ANOTHER_VARIABLE=testAPI
Construct anenvironments.patch API request.
In this request:
In the
updateMaskparameter, specify theconfig.softwareConfig.envVariablesmask to replace all existingvariables with the specified variables. Variables that you don't specifyare deleted.In the request body, specify variables and their values:
{"config":{"softwareConfig":{"envVariables":{"VAR_NAME":"VAR_VALUE"}}}}Replace:
VAR_NAMEwith the name of the environment variable.VAR_VALUEwith the value of the environment variable.- To add more than one variable, add extra entries for variablesto
envVariables.
Example:
// PATCH https://composer.googleapis.com/v1/projects/example-project/// locations/us-central1/environments/example-environment?updateMask=// config.softwareConfig.envVariables{"config":{"softwareConfig":{"envVariables":{"EXAMPLE_VARIABLE":"True","ANOTHER_VARIABLE":"test"}}}}Terraform
Theenv_variables block in thesoftware_config block specifiesenvironment variables.
resource"google_composer_environment""example"{name="ENVIRONMENT_NAME"region="LOCATION"config{software_config{env_variables={VAR_NAME="VAR_VALUE"}}}}Replace:
ENVIRONMENT_NAMEwith the name of the environment.LOCATIONwith the region where the environment is located.VAR_NAMEwith the name of the environment variable.VAR_VALUEwith the value of the environment variable.- To add more than one variable, add extra entries for variablesto
env_variables.
Example:
resource"google_composer_environment""example"{name="example-environment"region="us-central1"config{software_config{env_variables={EXAMPLE_VARIABLE="True"ANOTHER_VARIABLE="test"}}}}What's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.