How to connect to Azure blob storage
Liquibase can connect to Azure blob storage to access files using the Liquibase Azure extension. This allows you to use Azure for your pipeline and store configuration files for Policy Checks and Flows in Azure.
Prerequisites
Azure
Liquibase Azure extension
1. Set up environment variables.
Environment variables are key-value pairs used to securely pass configuration data such as credentials and connection details to applications. Before running Liquibase with Azure support, you must set a few environment variables so Liquibase can authenticate to your Azure storage account. Liquibase uses these variables during runtime to authenticate with Azure.
Before you run the example code, be sure to:
- Update your_storage_account with your storage account name.
- Update your_tenant_id with your tenant ID.
- Update your_client_id with your client ID.
- Update your_client_secret with your client secret.
Example Code
Note: This sets the environment variables temporarily for the duration of the current terminal session. Once you close the terminal, this setting will be lost and you will need to reset the environment variables for your new terminal session. These variables include sensitive information like client secrets, so we do not recommend persisting them to avoid long-term storage in configuration files.
Windows
set LIQUIBASE_AZURE_STORAGE_ACCOUNT="your_storage_account"
set AZURE_TENANT_ID="your_tenant_id"
set AZURE_CLIENT_ID="your_client_id"
set AZURE_CLIENT_SECRET="your_client_secret"
Linux/MacOS
export LIQUIBASE_AZURE_STORAGE_ACCOUNT="your_storage_account"
export AZURE_TENANT_ID="your_tenant_id"
export AZURE_CLIENT_ID="your_client_id"
export AZURE_CLIENT_SECRET="your_client_secret"
2. Run liquibase flow
3. Select option 3: Just create sample flow file in the CWD, do not use, and exit command
A Flow File will be created in the $LIQUIBASE_HOME directory.
Tip: $LIQUIBASE_HOME is an environment variable that points to the location of the directory where Liquibase is installed on your machine. The location of $LIQUIBASE_HOME will depend on where Liquibase was installed on your machine.
4. Open the created liquibase.flowfile.yaml
file.
5. Add the following code to your flow file:
globalVariables:
ENV: DEV
stages:
Snapshot:
actions:
- type: liquibase
command: snapshot
cmdArgs:
{ snapshot-format: json }
globalArgs:
{ output-file: 'az://snapshots/${ENV}-azure-snapshot.json' }
Note: ${ENV}
will be replaced with the value from your environment. In this case, the environment was set to DEV in the flow file.
Note: The output-file
is stored in the Azure blob storage.
6. Run liquibase flow --flowfile=<YOUR_FLOWFILE_PATH>
where YOUR_FLOWFILE_PATH
is the file path to your flow file.
For example, liquibase flow --flowfile= liquibase-pro-4.32.0/liquibase.flowfile.yaml