Skip to content

ariga/terraform-provider-atlas

Repository files navigation

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
  • PostgreSQL
  • SQLite
  • TiDB
  • SQL Server
  • ClickHouse
  • CockroachDB

Docs

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.