ariga / terraform-provider-atlas

Terraform Provider for Atlas
https://atlasgo.io
Apache License 2.0
55 stars 8 forks source link

Atlas Terraform Provider

Twitter Discord

image

Atlas is a language-agnostic tool for managing and migrating database schemas using modern DevOps principles. It offers two workflows:

Installation

terraform {
  required_providers {
    atlas = {
      source  = "ariga/atlas"
      version = "~> 0.6.1"
    }
  }
}
provider "atlas" {
  # Use MySQL 8 docker image as the dev database.
  dev_url = "docker://mysql/8"
}

Quick Start

1. To create a schema for your database, first install atlas

2. Then, inspect the schema of the database:

atlas schema inspect -u "mysql://root:pass@localhost:3306/example" > schema.hcl

3. Finally, configure the terraform resource to apply the state to your database:

data "atlas_schema" "my_schema" {
  src     = "file://${abspath("./schema.hcl")}"
  dev_url = "mysql://root:pass@localhost:3307/example"
}

resource "atlas_schema" "example_db" {
  hcl     = data.atlas_schema.my_schema.hcl
  url     = "mysql://root:pass@localhost:3306/example"
  dev_url = "mysql://root:pass@localhost:3307/example"
}

For more advanced examples, check out the examples folder.

Docs

Supported databases:

MySQL, MariaDB, PostgresSQL, SQLite, TiDB, CockroachDB, SQL Server, ClickHouse, Redshift.