GitXplorerGitXplorer
a

schemachange-in-terraform

public
0 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
9aebb09a9b23d91edc303c2150e4dd15baca9301

add license

aafeld committed 7 months ago
Unverified
9c0be908d82daf4d9b3c285618b3c1f85ead2646

support always scripts

aafeld committed 7 months ago
Unverified
44524f070237dd3c2d4a835b85af677882166e7b

support versioned scripts

aafeld committed 7 months ago
Unverified
86bc87e4e8c31fcbba04f0e44475da6de506d10f

simplify configuration

aafeld committed 7 months ago
Unverified
167a6d9977939e502ab9a9cdd5d8492bef697788

document some advantages of this approach

aafeld committed 7 months ago
Unverified
ac3ef8971313e19f6a4ddf37a52f03d770f57336

load all repeatable scripts

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