Cloud / IaC · Enterprise

ML Data Storage and Orchestration: DVC on Azure Blob and Astronomer Airflow with Terraform

Terraform for versioned ML datasets (DVC remotes on object storage with scoped access) and managed Airflow deployments on Astronomer, so data and ML teams get reproducible storage and orchestration across subscriptions.

  • DVC
  • Azure Blob Storage
  • Astronomer
  • Apache Airflow
  • Terraform
  • Managed Identity
  • GitHub Actions
  • Python

// Why this matters

A dvc remote azure blob setup solves a specific reproducibility problem: models are trained on data that changes, and weeks later nobody can say which version produced which result. DVC records content hashes in small files that go into Git, so a commit identifies both code and data. The data itself needs a home that is durable, cheap and access-controlled, which is an infrastructure problem.

Orchestration is the other half. Data preparation, training and evaluation are pipelines with dependencies, retries and schedules. Airflow is a common answer; running it yourself means upgrades, scaling and a metadata database to look after. A managed service such as Astronomer moves that burden, and the platform team's job becomes provisioning deployments consistently and wiring them to storage and identity.

Both pieces need to be repeatable for many teams across subscriptions. The pattern below treats a team as a record and produces storage, access and an Airflow deployment from it, the same shape used elsewhere in this platform, for instance From Form to Running Cluster: Self-Service Team Onboarding.

// The problem

The default DVC setup points at a storage account with an account key in a local config file. That key is shared by everyone, is rarely rotated and grants access to every dataset in the account. Anyone who clones the repository and runs dvc pull is using a credential whose owner cannot be identified.

Storage cost behaves badly under ML workloads: every experiment can write multi-gigabyte artefacts, nobody deletes them and old versions pile up. Without lifecycle rules, the bill grows monotonically, and without per-team containers it cannot be attributed.

On the orchestration side, teams that self-manage Airflow end up with different versions, different executors and credentials stored in Airflow connections, which turn the scheduler into a credential vault nobody planned to secure.

// The solution

Storage is one account per environment, private and with shared key access disabled, with a container per team. Each container gets a lifecycle policy (move cold data to a cooler tier, expire temporary prefixes) and role assignments for the team's group (data contributor) and for the Airflow workload identity. Blob versioning and soft delete protect against accidental overwrites, which matters because dvc push is content-addressed but humans still delete things.

DVC is configured to use Azure authentication through the default credential chain. The remote URL and account name are committed in .dvc/config; the credentials are never in the repository. Developers authenticate with az login and DVC picks up the token through the Azure SDK; Airflow tasks use a workload identity, so the same remote works in both places with no key.

Astronomer deployments are provisioned through the Astronomer Terraform provider: a workspace per team and a deployment per environment, with explicit executor, worker queue and resource settings. Pinning the runtime version in code means upgrades are reviewed changes. DAG code is delivered by CI using an API token stored as a CI secret, building an image and deploying it to the target deployment.

We rejected a shared container with folder conventions (no isolation, no attribution), account keys in Airflow connections (a credential store in the scheduler) and self-hosted Airflow on Kubernetes for these teams (more control than they needed and a lot more to operate). For teams that do want in-cluster orchestration, the same storage pattern applies. Governance of the models consuming this data is covered in Azure AI Foundry Onboarding: Governed ML Workspaces for Teams with Terraform, and the CI pattern follows One Reusable Plan/Apply Workflow for Cost-Optimised Autoscaling.

How it flows flow1. Request → 2. Storage account → 3. Container per team → 4. DVC remote → 5. Astronomer workspace → 6. Gate: apply approval → 7. Workload identity → 8. DAG deploy → 9. Pipeline run01Request02Storage account03Container per team04DVC remote05Astronomer workspace06 · GATEGate: apply approval07Workload identity08DAG deploy09Pipeline run
How it flows. End-to-end flow. Dashed pink nodes are gates: points where a human or a check must pass before the next stage runs.
  1. Requestteam, environments, storage size class
  2. Storage accountprivate, versioned, no shared keys
  3. Container per teamlifecycle rules and RBAC
  4. DVC remoteconfiguration committed, credentials not
  5. Astronomer workspacedeployments per environment
  6. Gate: apply approval gatereviewer sees capacity and access
  7. Workload identityAirflow tasks reach storage keylessly
  8. DAG deployCI pushes DAG image to the deployment
  9. Pipeline rundvc pull, process, dvc push
Airflow taskGit repoDVCBlob containercheckout commit with .dvc filesdvc pull (workload identity)fetch objects by content hashdvc repro / dvc push after processingupload new objects
Versioned data in a pipeline run. Airflow pulls the data version pinned in Git, processes it and pushes the result.
Code and metadataGit repodvc filesDAGsOrchestrationAstronomer workspaceDeployment per envWorker queuesIdentityTeam groupWorkload identityRBACStorageStorage accountContainer per teamLifecycle rules
Storage and orchestration layers. Everything below the pipeline is provisioned from the team record.

// Before you start

  • An Azure subscription and permission to create storage accounts and role assignments.
  • Terraform 1.5+ with azurerm and the astronomer/astro provider, plus an Astronomer organisation API token.
  • Python 3.10+, DVC with the Azure extra (pip install "dvc[azure]"), and the Astro CLI for local DAG tests.
  • Entra groups for each team and an Azure workload identity (federated) for Airflow tasks.
  • A Git repository per ML project with a CI system that can reach Astronomer.
  • Awareness of how much data teams produce, to size lifecycle rules.

// Step-by-step implementation

  1. 01 Provision the storage account and per-team containers

    The account is private, versioned and keyless. Containers are created from a team map; adding a team is an addition to a variable. Disable shared key access from the start; retrofitting it later breaks every tool that quietly used the key.

    Use zone-redundant replication unless you can recreate the data cheaply from source.

  2. 02 Add lifecycle rules so cost stays bounded

    Experiment output is write-heavy and rarely read twice. Move blobs to a cooler tier after a period of no access and expire clearly temporary prefixes. Keep the DVC cache prefix longer-lived, because deleting an object a .dvc file points to breaks reproduction.

    Make the numbers variables and revisit them with real access data.

  3. 03 Configure DVC to use keyless access

    Initialise DVC in the project and add the Azure remote by account and container. Credentials are not stored: DVC's Azure backend uses the default Azure credential chain, so developers use az login and automated jobs use a workload identity.

    Commit .dvc/config and the .dvc pointer files. Add a local-only config for per-user options if needed; it stays out of Git.

  4. 04 Define a reproducible pipeline

    A dvc.yaml describes stages with inputs, outputs and parameters. DVC hashes everything, so dvc repro only reruns what changed, and dvc push uploads only new objects. The same file is what the Airflow task will run, so there is one definition of the pipeline.

    Keep parameters in params.yaml so experiments differ by a committed file.

  5. 05 Create the Astronomer workspace and deployments

    The Astronomer Terraform provider manages workspaces and deployments. Declare one workspace per team and a deployment per environment, with the runtime version pinned. Worker queue sizing is explicit so cost is a reviewed number.

    Resource names and field names change between provider releases; check the provider documentation for your version.

  6. 06 Give Airflow tasks keyless access to storage

    Airflow tasks should authenticate to Azure with a workload identity rather than a connection holding a key. Create a user-assigned identity with a federated credential for the deployment's workload, give it the blob role on the team container and configure the task environment to use it.

    The same DVC remote definition then works in a task: dvc pull and dvc push use the default credential chain.

  7. 07 Write the DAG and deploy it from CI

    The DAG runs the pipeline rather than reimplementing it: check out the repository, dvc pull, dvc repro, dvc push. Using BashOperator or KubernetesPodOperator keeps the task identical to a developer's laptop run, which is the point of the whole exercise.

    CI builds the project image and deploys it to the right deployment with the Astro CLI, using a deployment-scoped API token held as a CI secret.

// How to verify it works

  • az storage account show -n <account> --query allowSharedKeyAccess returns false, and dvc push still works after az login.
  • dvc status -c reports "Cache and remote are in sync" after a push.
  • A user outside the team group gets an authorisation error on dvc pull for that container.
  • The Astronomer deployment shows the pinned runtime version and the DAG appears after a CI deploy.
  • A DAG run completes all three tasks and the new objects appear in the container; no storage key exists in Airflow connections.

// Design decisions and trade-offs

  • A dedicated storage account per environment with one container per team, rather than one container for everyone.
  • DVC remotes authenticate with Entra identities and short-lived tokens, not account keys.
  • Astronomer deployments are created by Terraform per team and environment with explicit worker sizing.
  • Airflow reaches storage through a workload identity, not a connection holding a stored key.
  • DAGs and DVC metadata live in Git; large artefacts live in object storage. Git stays small.

// Pitfalls and lessons learned

  • Disabling shared keys breaks any tool that defaults to them; test dvc and your SDK versions against a keyless account before rolling out.
  • Lifecycle rules that expire objects referenced by .dvc files break reproducibility; scope deletion to temporary prefixes only.
  • DVC remote over a private endpoint needs DNS that resolves the private address from wherever the job runs, including inside the managed orchestrator network.
  • Large dvc push runs hit throttling; tune jobs and keep one remote per project instead of one giant shared one.
  • Astronomer provider arguments change between versions; pin the provider and read changelogs before upgrading.
  • Federated identity subjects for managed orchestrators are not always documented clearly; confirm the issuer and subject from a failed token exchange log.
  • Committing a .dvc/config.local with credentials is the most common leak; add it to .gitignore and scan for it in CI.

// Frequently asked questions

How do I set up a DVC remote on Azure Blob Storage?

Create a private container, run dvc remote add -d storage azure://<container>/<path>, set the account name and authenticate with az login or a managed identity instead of a key.

Can Terraform manage Astronomer deployments?

Yes, the Astronomer Terraform provider manages workspaces and deployments, including runtime version and worker queues.

Where should DVC credentials live?

Nowhere in the repository; use the Azure credential chain locally and a workload identity in automated jobs.

How do I stop ML storage costs growing forever?

Use lifecycle rules to tier cold data and expire temporary prefixes, with a container per team for attribution.

Why run dvc inside Airflow tasks?

It keeps the pipeline definition in one place so the scheduled run and a developer run execute the same stages.

// The outcome

ML and data teams get versioned datasets and a managed orchestrator from the same declarative request, with access scoped by team and no shared keys. Experiments are reproducible because code, data version and pipeline definition travel together.

// Where to take it next

// Keep reading