In Cassandra Lunch #86, we discuss the DataStax Astra Terraform Provider and discuss how it can be used to manage DataStax Astra infrastructure! The live recording of Cassandra Lunch, which includes a more in-depth discussion and a demo, is embedded below in case you were not able to attend live. Subscribe to our YouTube Channel to keep up to date; as well as, watch Cassandra Lunches live at 12 PM EST on Thursdays!
In Cassandra Lunch #86, we discuss the DataStax Astra Terraform Provider and discuss how it can be used to manage DataStax Astra infrastructure! If you are not famaliar with DataStax Astra, check out any of our blogs related to DataStax Astra here and here
Additionally, you can checkout our Cassandra.Realtime workshop series that we did in partnership with DataStax Astra, for which the repository can be found here: https://github.com/Anant/cassandra.realtime
If you are not familiar with Terraform, it is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform allows users to codify cloud APIs into declarative configuration file to manage the full lifecycle (create, manage, and delete resources).
Terraform is written in HashiCorp Configuration Language (HCL), which allows for concise descriptions of resources using blocks, arguments, and expressions. Terraform can also allow users to manage low-level components like compute, storage, and networking resources, as well as high-level components like DNS entries and SaaS features.
Additionally, Terraform allows users to keep track of their real infrastructure in a state file, which acts as a source of truth for their environment, which also uses the state file to determine the changes to make to their infrastructure so that it will match their configuration.
The DataStax Astra Terraform Provider allows DataStax Astra users to manage their full database lifecycle for Astra Serverless databases. In order to use the provider, an Astra token is required with sufficient permissions. Something to note: currently Astra Streaming is not supported.
More information can be found at:
- https://registry.terraform.io/providers/datastax/astra/latest/docs
- https://github.com/datastax/terraform-provider-astra
- Examples
In the video embedded below, we have a walkthrough that will use Gitpod such that this entire demo can be replicated without having to download anything to your local machine and is browser-based. Using the DataStax Astra Terraform Provider, we will create a new database, create a new keyspace in the newly created atabase, download a dependency graph, destory the newly created keyspace, and then destroy the newly created databse.
The written instructions are included below, but you can also follow along here: https://github.com/Anant/example-cassandra-terraform-astra-provider/blob/main/README.md
Generate an admin level token and copy your token value as we will need it for when we run terraform.
2. When prompted in the terminal, type yes
3. Create a new Astra DB instance
3.1 Copy code into astra.tf
terraform {
required_providers {
astra = {
source = "datastax/astra"
}
}
}
variable "token" {}
provider "astra" {
// This can also be set via ASTRA_API_TOKEN environment variable.
token = var.token
}
resource "astra_database" "example" {
name = "terraform"
keyspace = "test"
cloud_provider = "gcp"
regions = ["us-east1"]
}
3.2 Run terraform init
3.3 Run terraform plan
Paste in token when prompted and visualize the upcoming infrastructure changes.
3.4 Run terraform apply
Paste in token when prompoted. Additionally, type yes
when prompted to apply changes. Once the deploy has completed, you can check your Astra dashboard and see the newly created database!
4. Create a new keyspace in newly deployed database
4.1 Add the following in astra.tf
to visualize the databases and get id’s of active databases
data "astra_databases" "databaselist" {
status = "ACTIVE"
}
output "existing_dbs" {
value = [for db in data.astra_databases.databaselist.results : db.id]
}
4.2 Run terraform plan
to visualize changes and then terraform apply
4.3 Add the following in astra.tf
to create a new keyspace to the new Astra database
resource "astra_keyspace" "databaselist" {
name = "example"
database_id = data.astra_databases.databaselist.results[0].id
}
4.4 Run terraform plan
to visualize changes and then terraform apply
to create the new keyspace
5. Create a dependency graph
terraform graph | dot -Tsvg > graph.svg
6. Destroy newly created Astra DB instance
terraform destroy
Cassandra.Link
Cassandra.Link is a knowledge base that we created for all things Apache Cassandra. Our goal with Cassandra.Link was to not only fill the gap of Planet Cassandra but to bring the Cassandra community together. Feel free to reach out if you wish to collaborate with us on this project in any capacity.
We are a technology company that specializes in building business platforms. If you have any questions about the tools discussed in this post or about any of our services, feel free to send us an email!