Atlas Terraform Provider

Discord

Atlas tools help developers manage their database schemas by applying modern DevOps principles. Contrary to existing tools, Atlas intelligently plans schema migrations for you, based on your desired state.

Supported databases:

  • MySQL
  • MariaDB
  • PostgresSQL
  • SQLite
  • TiDB

Docs

Installation

terraform {
  required_providers {
    atlas = {
      source  = "ariga/atlas"
      version = "~> 0.1.0"
    }
  }
}
provider "atlas" {}

Quick Start

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

MacOS:

brew install ariga/tap/atlas

Linux

Download:

curl -LO https://release.ariga.io/atlas/atlas-linux-amd64-latest

Install:

sudo install -o root -g root -m 0755 ./atlas-linux-amd64-latest /usr/local/bin/atlas

Windows

Download the latest release and move the atlas binary to a file location on your system PATH.

2. Then, inspect the schema of the database:

atlas schema inspect -d "mysql://root:[email protected]:3306/example" > schema.hcl

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

data "atlas_schema" "my_schema" {
 src = file("${path.module}/schema.hcl")
 dev_db_url = "mysql://root:[email protected]:3307/example"
}

resource "atlas_schema" "example_db" {
 hcl = data.atlas_schema.my_schema.hcl
 url = "mysql://root:[email protected]:3306/example"
 dev_db_url = "mysql://root:[email protected]:3307/example"
}

For more advanced examples, check out the examples folder.

GitHub

View Github