Learn how to manage your DataStax Astra infrastructure with terraform! This tutorial can be done with Gitpod so you don't have to worry about any OS inconsistencies with your local machine! Hit the button below to get started!
Generate an admin level token and copy your token value as we will need it for when we run terraform.
terraform {
required_providers {
astra = {
source = "datastax/astra"
}
}
}
variable "token" {
type = string
default = "<your-token-here>"
}
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"]
}
Paste in token when prompted and visualize the upcoming infrastructure changes.
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!
data "astra_databases" "databaselist" {
status = "ACTIVE"
}
output "existing_dbs" {
value = [for db in data.astra_databases.databaselist.results : db.id]
}
resource "astra_keyspace" "databaselist" {
name = "example"
database_id = data.astra_databases.databaselist.results[0].id
}
terraform graph | dot -Tsvg > graph.svg
terraform destroy