This is a proof of concept implementing schemachange in Terraform. Having managed Snowflake using both, I thought it would be an interesting exercise to try and bring the two together.
The meat of the implementation is in terraform/sql.tf
. The schemachange-esque change scripts can be found under sql/
.
Not looking to spend a lot of time to match the functionality exactly. Do not use this in production.
-
Set up the Snowflake CLI.
-
Create a virtual environment.
python -m venv .venv
-
Activate the virtual environment.
source ./.venv/bin/activate
-
Configure the Snowflake CLI. Call the connection
default
.
-
-
Run Terraform. (
-parallelism=1
is set to match schemachange's behavior of only running a single script at a time.)cd terraform terraform init terraform apply -parallelism=1
- When files change, it shows a diff in the plan.
- You see the result of each query.
- It can be integrated with other Terraform resources.
- You could add dependencies between scripts/resources through
depends_on
.
- At time of writing, the Snowflake CLI doesn't support MFA caching.
There's definitely more that should be in this list.
- [x] Support versioned scripts
- [ ] Ignore changes to the filenames after the version number
- [ ] Limit to scripts with a
V
followed by digit(s) — currently considers any file with aV
followed by anything as a versioned script - [ ] Run in numeric order
- [x] Support repeatable scripts
- [x] Support always scripts
- [x] Match the order between script types
- [x] Ignore script folders