Anant example-cassandra-terraform-astra-provider
License: No License Provided
Language: Shell
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.
yes
astra.tf
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"]
}
terraform init
terraform plan
Paste in token when prompted and visualize the upcoming infrastructure changes.
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!
astra.tf
to visualize the databases and get id's of active databasesdata "astra_databases" "databaselist" {
status = "ACTIVE"
}
output "existing_dbs" {
value = [for db in data.astra_databases.databaselist.results : db.id]
}
terraform plan
to visualize changes and then terraform apply
astra.tf
to create a new keyspace to the new Astra databaseresource "astra_keyspace" "databaselist" {
name = "example"
database_id = data.astra_databases.databaselist.results[0].id
}
terraform plan
to visualize changes and then terraform apply
to create the new keyspaceterraform graph | dot -Tsvg > graph.svg
terraform destroy
Join Our Newsletter!
Sign up below to receive email updates and see what's going on with our company.