Logo

Autoschematic

GitHub
Cluster Login

Managing Snowflake with Infrastructure-as-Code

In practice, Snowflake environments experience state-drift frequently. Warehouses get tuned, schemas evolve, and admins still need the Snowsight console from time to time.

Autoschematic's push-pull model is a great fit here: you can import your existing Snowflake resources, manage them as code, and pull remote state back into Git to resolve it.

Add the Snowflake connector

Starting from a blank Git repo, create the main autoschematic.ron config file:

AutoschematicConfig(
    prefixes: {
        "main": Prefix(
            connectors: [
                Connector(
                    shortname: "snowflake",
                    spec: Pip(
                        name: "autoschematic-connector-snowflake",
                        version: "0.14.0"
                    ),
                )
            ]
        )
    }
)
autoschematic install

Since this is a Pip(...) connector, autoschematic install will really do

pip install autoschematic-connector-snowflake~=14.0

...under the hood. Other connectors might be installed with Cargo, for example.

Snowflake authentication

The Snowflake connector will seamlessly work with your existing Snowflake CLI configuration, such as config.toml or connections.toml.

Import existing Snowflake resources

The easiest way to get started is to import your real Snowflake state before you hand-write anything.

autoschematic import

After import, you should see a repo layout along these lines:

main/
└── snowflake/
    ├── warehouses/
    │   └── TRANSFORMING.sql
    ├── databases/
    │   └── ANALYTICS/
    │       ├── database.sql
    │       └── MART/
    │           ├── schema.sql
    │           └── ORDERS/
    │               └── table.sql
    ├── roles/
    │   └── analyst.ron
    └── users/
        └── jane_doe.ron

Make a change locally

Once you edit a file, you'll need to stage it in git with git add before running Autoschematic:

git add main/snowflake/warehouses/TRANSFORMING.sql
autoschematic plan
autoschematic apply

If you delete a staged Snowflake file, the connector will plan a corresponding DROP ... operation for that object, for example.

Create new users and roles

autoschematic create can scaffold these RBAC resources for you:

autoschematic create
Select prefix: main
Select connector: snowflake
Select object: snowflake/roles/[name].ron
name: analyst
Writing main/snowflake/roles/analyst.ron

The Snowflake connector also exposes snowflake/users/[name].ron.