Anant example-cassandra-terraform-astra-provider

License: No License Provided

Language: Shell

example-cassandra-terraform-astra-provider

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!

Open in Gitpod

1. Generate an Astra Token

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" {
    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"]
}

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

Related Tools

Spark

License : Apache License 2.0

Language : Scala

36094

261

27118

Example Cassandra Spark Sql

License : No License

Language : No Language

1

N/A

N/A

Example Cassandra Etl With Airflow And Spark

License : No License

Language : Python

Cassandra.Toolkit

License : Apache License 2.0

Language : Jinja

Need Cassandra Training?

WE GOT YOU COVERED.

Anant US provides online training for Apache Cassandra that covers all the important skills you need to know in order to work with this high performance, open source NoSQL database.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company.