Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide for setting environment variables in Dagster+ UI #24012

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,115 @@
sidebar_label: "Set with Dagster+ UI"
---

# Set environment variables with the Dagster+ UI
Environment variable are key-value pairs that are set outside of your source code. Using environment variables lets you dynamically change the behavior of your application without modifying source code and securely set up secrets.

Dagster supports several approaches for [accessing environment variable in your code](/todo). You can also set environment variables in several ways. This guide will cover how to set environment variables in the Dagster+ UI.

## What you'll learn

- How to add, edit, and delete environment variables in the Dagster+ UI
- How to modify the value of environment variables based on the deployment environment
- How to export environment variables for local use

<details>
<summary>Prerequisites</summary>

To follow the steps in this guide, you'll need:

- **Organization Admin**, **Admin**, or **Editor** permissions for your Dagster+ account
- To be using Dagster version 1.0.17 or later

</details>

## How to find the environment variables page
1. Sign in to your Dagster+ account
2. Use the deployment switcher in the top right corner to select the deployment where you want to view or manage environment variables
3. Navigate to the **Deployment** -> **Environment variables** page
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved

## How to add an environment variable
To create a new environment variable:
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved

1. [Navigate to the environment variables page](#how-to-find-the-environment-variables-page)
2. Click the **+ Add environment variable** button
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved
3. A modal will open, fill out the following information
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved
- **Name** - Enter a name for the environment variable. This is how the variable will be referenced in your code.
- **Value** - Enter a value for the environment variable.
- **Deployment Scope** - select the deployment(s) where the variable should be accessible:
- **Full deployment** - The variable will be available to selected code locations in the full deployment
- **Branch deployments** - The variable will be available to selected code locations in Branch Deployments
- **Local** - If selected, the variable will be included when [exporting environment variables to a local `.env` file](#how-to-export-environment-variables-locally)
- **Code Location Scope** - select the code location(s) where the variable should be accessible. At least one code location is required.

<!-- TODO SCREENSHOT -->

4. Click **Save**

## How to edit an environment variable
To edit an existing environment variable:

1. [Navigate to the environment variables page](#how-to-find-the-environment-variables-page)
2. Click the **Edit** button on the right of the environment variable you want to edit
3. A modal will open where you can edit the attributes of the environment variable
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved
4. Click **Save**

## How to delete an environment variable
To delete an environment variable:

1. [Navigate to the environment variables page](#how-to-find-the-environment-variables-page)
2. Click the **Trash icon** on the right of the environment variable you want to delete
3. A modal will open to confirm that you want to delete the environment variable. Click **Yes, delete** to delete the environment variable, or **Cancel** to close the modal and not delete the environment variable.
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved

## How to view the value an environment variable
To view the value of an environment variable:

1. [Navigate to the environment variables page](#how-to-find-the-environment-variables-page)
2. Click the **eye icon** in the **Value** column of the environment variable you want to view
3. Click the **eye icon** again to hide the value.
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved

:::note
Viewing an environment variable only reveals the value to you. It doesn't show the value in plaintext to all users. If you navigate away from the environment variables page or reload the page, the value will be hidden again.

Check failure on line 74 in docs/docs-beta/docs/dagster-plus/deployment/environment-variables/dagster-ui.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Dagster.spelling] Is 'plaintext' spelled correctly? Raw Output: {"message": "[Dagster.spelling] Is 'plaintext' spelled correctly?", "location": {"path": "docs/docs-beta/docs/dagster-plus/deployment/environment-variables/dagster-ui.md", "range": {"start": {"line": 74, "column": 93}}}, "severity": "ERROR"}

Check failure on line 74 in docs/docs-beta/docs/dagster-plus/deployment/environment-variables/dagster-ui.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'plaintext'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'plaintext'?", "location": {"path": "docs/docs-beta/docs/dagster-plus/deployment/environment-variables/dagster-ui.md", "range": {"start": {"line": 74, "column": 93}}}, "severity": "ERROR"}
:::



## How to add an environment variable for a Branch Deployment
erinkcochran87 marked this conversation as resolved.
Show resolved Hide resolved
If you want to give branch deployments access to an existing environment variable:

1. [Navigate to the environment variables page](#how-to-find-the-environment-variables-page)
2. Click the **Edit** button on the right of the environment variable you want to edit
3. A modal will open. Click the **Branch deployments** check-box to allow branch deployments to access the environment variable
4. Click **Save**

If you want to provide branch deployments a different value for the same environment variable key, see [How to set different values for environment variables in different deployment environments](#how-to-set-different-values-for-environment-variables-in-different-deployment-environments)



## How to export environment variables locally
You can export environment variables that have the **Local** scope selected into a `.env` file to use locally.

To download the file:
1. [Navigate to the environment variables page](#how-to-find-the-environment-variables-page)
2. Click the **arrow menu** to the right of the **+ Add environment variable** button
3. Click **Download local environment variables**. A file named `env.txt` will be downloaded
jamiedemaria marked this conversation as resolved.
Show resolved Hide resolved

To use the downloaded environment variables for local Dagster development:
1. Rename the downloaded `env.txt` file to `.env`
2. Move the file to the directory where you run `dagster dev` or `dagster-webserver`
3. Run `dagster dev` or `dagster-webserver`
4. Confirm that the environment variables have been loaded by locating a log message that begins with `Loaded environment variables from .env file`


## How to set different values for environment variables in different deployment environments
You can create multiple instances of the same environment variable key with different values. This allows you to provide different values to different deployment environments. For example, you may want to use different Snowflake credentials for your production deployment than in branch deployments.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this section feels a bit wordy to me. i'm going to revisit it in an hour or so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It honestly doesn't seem to bad to me


When you [add an environment variable](#how-to-add-an-environment-variable) you can select the deployment scope and code location scope for the environment variable. You can create multiple environment variables with different values and different scopes to customize the values in different deployment environments.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be just repeating the previous paragraph though


For example, if you wanted to provide different Snowflake password for your production deployment than in branch deployments, you would make two environment variables with the same key. For the production environment variable, you set the value for the production password and ensure the **Full deployment** box is checked and the **Branch deployments** box isn't checked. For the branch deployment environment variable, you set the value for the branch deployment password and ensure the **Branch deployments** box is checked and the **FullDeployment** box isn't checked.

<!-- TODO SCREENSHOT -->


## Next steps

- Learn how to [access environment variables in Dagster code](/todo)
- See the [built-in environment variables](https://docs.dagster.io/dagster-plus/managing-deployments/environment-variables-and-secrets#built-in-environment-variables) provided by Dagster
Loading