DevOps with Snowflake

Snowflake provides tools and practices for managing your Snowflake environments as code, validating changes before they reach production, and automating deployments through CI/CD pipelines.

What is DevOps with Snowflake?

DevOps with Snowflake brings software engineering best practices to data infrastructure management. The core principles are:

  • Define as code. Declare the desired state of your Snowflake objects in version-controlled files. Snowflake determines and applies the necessary changes (create, alter, or drop) to reach that state.

  • Validate before you deploy. Preview proposed changes in a plan step before applying them to your account. Review creates, alters, and drops, then deploy when you’re confident the changes are correct.

  • Automate with CI/CD. Integrate Snowflake into your existing CI/CD pipelines so that deployments are triggered by pull requests, merges, or scheduled runs rather than manual steps.

The recommended approach is to use DCM Projects (Database Change Management Projects), which unify declarative object management, plan-then-deploy validation, multi-environment targeting, and CI/CD automation into a single workflow.

Define your Snowflake objects as code

dbt Projects on Snowflake

dbt Projects on Snowflake let you deploy and run dbt Core projects as native Snowflake objects. You define SQL transformations in dbt models, deploy them as a versioned DBT PROJECT object, and execute them with Snowflake SQL or the Snowflake CLI. You can schedule runs with Snowflake tasks and integrate deployment into CI/CD pipelines.

For more information, see dbt Projects on Snowflake.

Alternative: CREATE OR ALTER with versioned scripts

For individual object changes outside of a DCM project, you can use the CREATE OR ALTER <object> command, which creates the object or alters it to match the definition specified by the command. By using this command from a versioned file in a remote repository, you can roll back changes to a previous version by executing a previous version of the file.

CREATE OR ALTER TABLE vacation_spots (
  city VARCHAR,
  airport VARCHAR,
  avg_temperature_air_f FLOAT,
  avg_relative_humidity_pct FLOAT,
  avg_cloud_cover_pct FLOAT,
  precipitation_probability_pct FLOAT
) data_retention_time_in_days = 1;

Note

You can also use the Snowflake Python APIs and Snowflake CLI to manage Snowflake resources. If you prefer to do your data engineering work in Python, Snowflake’s first-class Python API enables you to do the same resource management in the language you are most productive in.

Validate and preview changes

Before deploying changes to your Snowflake account, you can preview the proposed modifications to verify they match your intent.

Plan with DCM Projects

DCM Projects use a plan-then-deploy model. The PLAN command compares your definition files against the current state of your account and produces a list of proposed changes without modifying anything.

You can run a plan using the Snowflake CLI:

snow dcm plan --target PROD

Or using SQL:

EXECUTE DCM PROJECT my_db.my_schema.my_project
  PLAN
  USING CONFIGURATION PROD
FROM
  '@my_stage/my_project/';

Review the output to confirm the expected creates, alters, and drops before proceeding to deploy.

Automate deployment with CI/CD

You can integrate Snowflake into your CI/CD pipelines so that deployments are triggered automatically by events such as pull request merges, branch pushes, or scheduled runs. A typical Snowflake pipeline progresses through three stages:

  • Validate on pull request. Compute the proposed changes against the target environment without modifying anything, and post the output for reviewers to confirm intent before merging.

  • Deploy on merge. Apply the validated changes to the target environment. Use a separate service user and target per environment so that promotion from dev to prod is a configuration change, not a code change.

  • Verify after deployment. Refresh derived data and run expectation checks to confirm the deployment produced the results you expect.

Snowflake publishes and maintains first-party integrations for the following CI/CD platforms. Each integration installs Snowflake CLI on the runner and configures authentication, with workload identity federation (OIDC) recommended so that no long-lived secrets are stored in your CI system.

Integration

Status

Reference

GitHub Action

Public preview

Snowflake CLI GitHub Action

GitLab CI/CD Component

Public preview

Snowflake CI/CD Component for GitLab

Azure DevOps Extension

Public preview

Snowflake CLI Azure DevOps Extension

For any CI platform that can run a shell command, you can also install Snowflake CLI directly. For setup instructions and the common Snowflake-side configuration, see Integrating CI/CD with Snowflake CLI.

Manage environments

By maintaining separate environments for development, test, and production, your teams can isolate development activities from the production environment, which reduces the chance of unintended consequences and data corruption.

Connection profiles for environment targeting

With DCM Projects, you can define multiple deployment targets in your manifest.yml file. Each target maps to a specific Snowflake account (or database), project object, owner role, and templating configuration. The same definition files can deploy to all environments with environment-specific settings applied through configuration profiles.

targets:
  DEV:
    account_identifier: MYORG-MYACCOUNT_DEV
    project_name: MY_DB.MY_SCHEMA.MY_PROJECT_DEV
    project_owner: DEV_DEPLOYER
    templating_config: DEV

  PROD:
    account_identifier: MYORG-MYACCOUNT_PROD
    project_name: MY_DB.MY_SCHEMA.MY_PROJECT_PROD
    project_owner: PROD_DEPLOYER
    templating_config: PROD

templating:
  configurations:
    DEV:
      wh_size: "X-SMALL"
    PROD:
      wh_size: "LARGE"

For enterprise patterns such as multi-project setups and team collaboration, see Enterprise use cases for DCM Projects.

Advanced: Jinja parameterization for custom scripts

DCM Projects natively support Jinja2 templating in definition files. You can use template variables, loops, conditions, macros, and dictionaries to make your definitions reusable across environments. Variable values come from configuration profiles in the manifest.yml or from runtime overrides.

For details on DCM templating, see DCM Projects files and templates.

You can also parameterize standalone SQL scripts (outside of DCM Projects) using Jinja2 with EXECUTE IMMEDIATE FROM. The Snowflake CLI allows you to pass environment variables to Python scripts as well.

To change a deployment target, for example, you replace the name of the target database with a Jinja variable such as {{ environment }} in SQL scripts, or an environment variable in Python scripts. This technique is shown in the following SQL and Python code examples:

CREATE OR ALTER TASK {{ environment }}.my_schema.my_task
  WAREHOUSE = my_warehouse
  SCHEDULE = '60 minute'
  AS select pi();

Getting started

To get started with DCM Projects, see Snowflake DCM Projects for a complete overview of the feature, including how to set up your project files, configure environments, and deploy changes.

For sample projects, CI/CD templates, and quickstarts, see the snowflake-labs DCM repository.

To follow a step-by-step tutorial, try the Getting Started with Snowflake DCM Projects quickstart, or the Configure CI/CD Integrations with Snowflake CI/CD quickstart.