TechnologyDecember 8, 2021

Automate Database Infrastructure with Astra DB Terraform Provider

Use Infrastructure as Code to easily create and manage databases
Sebastian Estevez
Sebastian EstevezDataStax
Automate Database Infrastructure with Astra DB Terraform Provider

DevOps teams love automation because it eliminates manual software processes and boosts productivity. Infrastructure-as-code (IaC) supports this approach because it enables the management and provisioning of infrastructure through code and avoids manual processes.

Now you can use the DataStax Astra DB Terraform provider to declaratively configure and manage databases on DataStax Astra DB. This provider makes it easy to script the creation of a database, roles, security tokens, access lists, and more. A great use case for this is to create identical database environments, such as test, staging, and production. This reduces the risk of errors resulting from configuration drift. Duplicate environments can be costly, as users are charged for these instances even when they are inactive. Astra DB, however, is serverless; its pay-as-you-go pricing model allows you to pay only for actual reads, writes, and storage used. 

What are the benefits?

With the Astra DB Terraform provider, you can codify infrastructure specifications, making it easier to document, edit, version, and audit configurations. This helps to avoid undocumented, ad-hoc configuration changes, but also enables development teams to take advantage of Astra DB’s serverless capabilities to cost effectively spin up their own databases with multiple database environments.

The Astra Terraform provider is free, supported and maintained by DataStax, and can be used with any cloud provider. Users can create databases, keyspaces, access lists, private endpoints, roles, and tokens on Astra DB Serverless. Don’t take our word for it — see it in action in the tutorial video below.

How it’s built

Terraform - How It's Built diagram

The Astra DB Terraform provider is open source and the project source code can be found on Github. Like most Terraform providers, the Astra provider is governed by the Mozilla public license 2.0. The project heavily leverages another DataStax open source project called astra-client-go, which is a generated golang API for the Astra DevOps API. If you prefer to manage your infrastructure imperatively or would like to build an Astra DB DevOps API wrapper for another system (cloud formation, for example) using golang, you can leverage astra-client-go directly. Feel free to report issues here on Github and the team will promptly respond. 


Get started with Astra DB Terraform provider

  1. Download Terraform 
  2. Log into Astra and create an authorization token (in your organization settings). The provider will prompt you for the token,  apply it if it does not detect it in your environment variable ASTRA_API_TOKEN.

    variable "token" {}

    provider "astra" { 

    // This can also be set via ASTRA_API_TOKEN environment variable. token = var.token 


  3. Add additional resources as described in the docs
  4. Always remember to run `terraform plan` before `terraform apply!

If you’re not using Astra DB, a multi-cloud DBaaS built on Apache Cassandra®, get started without a credit card by registering for a free account. Use your Google or GitHub account to sign in (you can also sign up using your email address) and receive $300 worth of free usage to create a proof of concept or use in a production environment.

Discover more
DataStax Astra DB

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.