Em 15 de setembro de 2026, todos os ambientes do Cloud Composer 1 e da versão 2.0.x do Cloud Composer 2 vão atingir o fim da vida útil planejado e não poderão mais ser usados. Recomendamos planejar a migração para o Cloud Composer 3.
Esta página explica como definir variáveis de ambiente no seu ambiente do Cloud Composer.
É possível usar variáveis de ambiente como uma alternativa às
variáveis do Airflow ao fornecer a configuração do ambiente de execução
para seus DAGs. As variáveis do Airflow são definidas no banco de dados do Airflow, e as variáveis de ambiente são definidas no contêiner do worker do Airflow.
Por exemplo, é possível usar o nome de uma variável de ambiente como está em um comando
que é executado por um BashOperator, ou extrair esse valor do objeto os.environ
no DAG ou usar uma variável do Airflow.
As variáveis de ambiente são persistentes. Depois que você especificar uma variável de ambiente,
o Airflow continuará usando essa variável até que você a remova do ambiente.
O Cloud Composer define as próprias variáveis de ambiente reservadas para controlar
ambientes.
Formato de nome
As variáveis de ambiente precisam corresponder à expressão regular
[a-zA-Z_][a-zA-Z0-9_]*.
Opções de configuração do Airflow
Não é possível especificar variáveis que mudam as opções de configuração do Apache Airflow.
As variáveis não podem usar o formato AIRFLOW__{SECTION}__{KEY} nem corresponder à
expressão regular AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+. Por exemplo, não é
possível definir AIRFLOW__WEBSERVER__DAG_DEFAULT_VIEW.
No parâmetro updateMask, especifique a
máscara config.softwareConfig.envVariables para substituir todas as variáveis
existentes pelas variáveis especificadas. As variáveis que você não especificar
são excluídas.
No corpo da solicitação, especifique as variáveis e os valores delas:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-29 UTC."],[[["\u003cp\u003eEnvironment variables in Cloud Composer provide runtime configuration for DAGs, distinct from Airflow variables stored in the Airflow database.\u003c/p\u003e\n"],["\u003cp\u003eThese environment variables are persistent, remaining in effect until they are explicitly removed from the environment.\u003c/p\u003e\n"],["\u003cp\u003eCertain environment variable names are reserved by Cloud Composer and cannot be used for custom variables, and variables that configure Airflow itself are not allowed.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment variables can be set for both new and existing environments using the Google Cloud console, gcloud command-line tool, API requests, or Terraform.\u003c/p\u003e\n"],["\u003cp\u003eWhen updating variables for existing environments via API, it is done through the \u003ccode\u003eenvironments.patch\u003c/code\u003e method, replacing all existing variables with the new variables specified in the request body.\u003c/p\u003e\n"]]],[],null,["\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n[Cloud Composer 3](/composer/docs/composer-3/set-environment-variables \"View this page for Cloud Composer 3\") \\| [Cloud Composer 2](/composer/docs/composer-2/set-environment-variables \"View this page for Cloud Composer 2\") \\| **Cloud Composer 1**\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page explains how to set environment variables in your\nCloud Composer environment.\n\nYou can use environment variables as an alternative to\n[Airflow variables](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/variables.html) when providing runtime configuration\nfor your DAGs. Airflow variables are set in the Airflow database, while\nenvironment variables are set in the Airflow worker's container.\n\nAs an example, you can use an environment variable's name as is in a command\nthat is run by a BashOperator, or get this value from the `os.environ` object\nin the DAG, or use an Airflow variable instead.\n\nEnvironment variables are persistent. Once you specify an environment variable,\nAirflow keeps using it until you remove the variable from your environment.\n| **Important:** It's not possible to use environment variables to configure Airflow. [Override Airflow configuration options](/composer/docs/composer-1/override-airflow-configurations) instead.\n\nCloud Composer sets its own reserved environment variables for controlling\nenvironments.\n\nName format\n\nEnvironment variables must match the regular expression\n`[a-zA-Z_][a-zA-Z0-9_]*`.\n\nAirflow configuration options\n\nIt is not possible to specify variables that change Apache Airflow\nconfiguration options.\n\nThe variables cannot use the `AIRFLOW__{SECTION}__{KEY}` format or match the\nregular expression `AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+`. For example, it is not\npossible to set `AIRFLOW__WEBSERVER__DAG_DEFAULT_VIEW`.\n\nInstead, you can [override Airflow configuration options](/composer/docs/composer-1/override-airflow-configurations).\n\nReserved variables\n\nThe following variable names are reserved by Cloud Composer. It is\nnot possible to create variables with these names.\n\n- `AIRFLOW_DATABASE_VERSION`\n- `AIRFLOW_HOME`\n- `AIRFLOW_SRC_DIR`\n- `AIRFLOW_WEBSERVER`\n- `AUTO_GKE`\n- `CLOUDSDK_METRICS_ENVIRONMENT`\n- `CLOUD_LOGGING_ONLY`\n- `COMPOSER_AGENT_BUILD_SERVICE_ACCOUNT`\n- `COMPOSER_ENVIRONMENT`\n- `COMPOSER_GKE_LOCATION`\n- `COMPOSER_GKE_NAME`\n- `COMPOSER_GKE_ZONE`\n- `COMPOSER_LOCATION`\n- `COMPOSER_OPERATION_UUID`\n- `COMPOSER_PYTHON_VERSION`\n- `COMPOSER_VERSION`\n- `CONTAINER_NAME`\n- `C_FORCE_ROOT`\n- `DAGS_FOLDER`\n- `GCE_METADATA_TIMEOUT`\n- `GCP_PROJECT`\n- `GCP_TENANT_PROJECT`\n- `GCSFUSE_EXTRACTED`\n- `GCS_BUCKET`\n- `GKE_CLUSTER_NAME`\n- `GKE_IN_TENANT`\n- `GOOGLE_APPLICATION_CREDENTIALS`\n\n- `MAJOR_VERSION`\n\n- `MINOR_VERSION`\n\n- `PATH`\n\n- `PIP_DISABLE_PIP_VERSION_CHECK`\n\n- `PORT`\n\n- `PROJECT_ID`\n\n- `PYTHONPYCACHEPREFIX`\n\n- `PYTHONWARNINGS`\n\n- `REDIS_PASSWORD`\n\n- `REDIS_PORT`\n\n- `REDIS_USER`\n\n- `SQL_DATABASE`\n\n- `SQL_HOST`\n\n- `SQL_INSTANCE`\n\n- `SQL_PASSWORD`\n\n- `SQL_PROJECT`\n\n- `SQL_REGION`\n\n- `SQL_USER`\n\n| **Caution:** Cloud Composer uses these reserved names for variables that are used by its processes. Don't refer to reserved names in your DAGs. Values of these variables can change without notice.\n\nSet environment variables for new environments\n\nYou can specify environment variables when you create an environment. For more\ninformation, see [Create environments](/composer/docs/composer-1/create-environments#overrides-env-vars).\n\nSet environment variables for existing environments \n\nConsole\n\nTo set environment variables for an existing environment:\n\n1. In Google Cloud console, go to the **Environments** page.\n\n [Go to Environments](https://console.cloud.google.com/composer/environments)\n2. In the list of environments, click the name of your environment.\n The **Environment details** page opens.\n\n3. Go to the **Environment variables** tab and click **Edit**.\n\n4. Add, change, or delete environment variables for your environment:\n\n - In the **Name** field, specify the variable name.\n - In the **Value** field, specify the variable value.\n - To add an extra variable, click **Add environment variable**.\n - To delete a variable, hold the pointer over a variable, then click **Delete item**.\n\ngcloud\n\nFollowing arguments control environment variables:\n\n- `--update-env-variables` specifies a comma-separated list of environment\n variables to create or update.\n\n- `--remove-env-variables` specifies a comma-separated list of environment\n variables to delete.\n\n- `--clear-env-variables` deletes all existing environment variables.\n\n gcloud composer environments update \\\n \u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e \\\n --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --update-env-variables=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nv\"\u003eNAME\u003c/span\u003e\u003c/var\u003e=\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e\n\nReplace:\n\n- `ENVIRONMENT_NAME` with the name of the environment.\n- `LOCATION` with the region where the environment is located.\n- `NAME` with the name of the variable that you want to create or update.\n- `VALUE` with the value for the variable.\n- To add more than one variable, separate the definitions with commas: `NAME=VALUE,NAME=VALUE,...`.\n\nExample: \n\n gcloud composer environments update \\\n example-environment \\\n --location us-central1 \\\n --update-env-variables=EXAMPLE_VARIABLE=True,ANOTHER_VARIABLE=test\n\nAPI\n\nConstruct an [`environments.patch`](/composer/docs/reference/rest/v1/projects.locations.environments/patch) API request.\n\nIn this request:\n\n1. In the `updateMask` parameter, specify the\n `config.softwareConfig.envVariables` mask to replace all existing\n variables with the specified variables. Variables that you don't specify\n are deleted.\n\n2. In the request body, specify variables and their values:\n\n {\n \"config\": {\n \"softwareConfig\": {\n \"envVariables\": {\n \"\u003cvar translate=\"no\"\u003eVAR_NAME\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eVAR_VALUE\u003c/var\u003e\"\n }\n }\n }\n }\n\n Replace:\n - `VAR_NAME` with the name of the environment variable.\n - `VAR_VALUE` with the value of the environment variable.\n - To add more than one variable, add extra entries for variables to `envVariables`.\n\nExample: \n\n // PATCH https://composer.googleapis.com/v1/projects/example-project/\n // locations/us-central1/environments/example-environment?updateMask=\n // config.softwareConfig.envVariables\n {\n \"config\": {\n \"softwareConfig\": {\n \"envVariables\": {\n \"EXAMPLE_VARIABLE\": \"True\",\n \"ANOTHER_VARIABLE\": \"test\"\n }\n }\n }\n }\n\nTerraform\n\nThe `env_variables` block in the `software_config` block specifies\nenvironment variables. \n\n resource \"google_composer_environment\" \"example\" {\n name = \"\u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e\"\n region = \"\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e\"\n\n config {\n\n software_config {\n\n env_variables = {\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-na\"\u003eVAR_NAME\u003c/span\u003e\u003c/var\u003e = \"\u003cvar translate=\"no\"\u003eVAR_VALUE\u003c/var\u003e\"\n }\n\n }\n }\n }\n\nReplace:\n\n- `ENVIRONMENT_NAME` with the name of the environment.\n- `LOCATION` with the region where the environment is located.\n- `VAR_NAME` with the name of the environment variable.\n- `VAR_VALUE` with the value of the environment variable.\n- To add more than one variable, add extra entries for variables to `env_variables`.\n\nExample: \n\n resource \"google_composer_environment\" \"example\" {\n name = \"example-environment\"\n region = \"us-central1\"\n\n config {\n\n software_config {\n\n env_variables = {\n EXAMPLE_VARIABLE = \"True\"\n ANOTHER_VARIABLE = \"test\"\n }\n }\n }\n }\n\nWhat's next\n\n- [Override Airflow configuration options](/composer/docs/composer-1/override-airflow-configurations)\n- [Update environments](/composer/docs/composer-1/update-environments)"]]