Skip to content

ariga/terraform-provider-atlas

This branch is 1 commit ahead of, 2 commits behind master.

Folders and files

NameName
Last commit message
Last commit date
Sep 18, 2024
Sep 15, 2024
Nov 20, 2023
Aug 28, 2024
Sep 23, 2024
Jan 24, 2024
Oct 12, 2022
Nov 2, 2022
Jun 10, 2022
Jul 29, 2024
Oct 12, 2022
Apr 27, 2022
Sep 5, 2024
Oct 14, 2024
Oct 14, 2024
Nov 8, 2022
Oct 12, 2022

Repository files navigation

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:

  • Declarative: Similar to Terraform, Atlas compares the current state of the database to the desired state, as defined in an HCL, SQL, or ORM schema. Based on this comparison, it generates and executes a migration plan to transition the database to its desired state.

  • Versioned: Unlike other tools, Atlas automatically plans schema migrations for you. Users can describe their desired database schema in HCL, SQL, or their chosen ORM, and by utilizing Atlas, they can plan, lint, and apply the necessary migrations to the database.

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.