GitXplorerGitXplorer
a

schemachange-in-terraform

public
0 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
3885add44f1fba03f17c159d6e22b08efedf303f

elaborate on compatibility

aafeld committed 7 months ago
Unverified
3bbcd6dcf1fc2ab9858685626a584e2affc0870b

call out the change scripts

aafeld committed 7 months ago
Unverified
dc7f64deb0ede69f3ce10b863d05116fe6fd9c13

emphasize it's experimental

aafeld committed 7 months ago
Unverified
ea944b1b0e1bdf3f035f67049c8a238d68912908

simplify title

aafeld committed 7 months ago
Unverified
e965c41b53778f3f999cb6874523f00408aedb91

condense the usage instructions

aafeld committed 7 months ago
Unverified
4d6360085556f33a53b23ae6210ac627a5d69307

simplify installation instructions

aafeld committed 7 months ago

README

The README file for this repository.

Schemachange in Terraform

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.

Usage

  1. Set up the Snowflake CLI.

    1. Create a virtual environment.

      python -m venv .venv
    2. Activate the virtual environment.

      source ./.venv/bin/activate
    3. Install the Snowflake CLI.

    4. Configure the Snowflake CLI. Call the connection default.

  2. 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

Advantages over schemachange

  • 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.

Disadvantages

Compatability

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 a V 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