GitXplorerGitXplorer
a

schemachange-in-terraform

public
0 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
19b19224b8b0020da25bc5c6b710293dc55edd2a

re-wording around versioned scripts

aafeld committed 7 months ago
Unverified
37656b8df363d8e038277d317e834c06649dd509

formatting tweaks

aafeld committed 7 months ago
Unverified
926223c80d992a507070480385aebd4787fad3ef

add caveats

aafeld committed 7 months ago
Unverified
6405264177e2506d47c0f1359f92363eb7ea0b84

refactor to do file listing separate from trimming

aafeld committed 7 months ago
Unverified
c19568871db8c8e22a91b304176c0025d618d3f1

flatten the file paths for the resource identifiers

aafeld committed 7 months ago
Unverified
872a538cdba4221a729efd2fb9f39c7ae960aac8

add an introduction

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