Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anant/example-cassandra-terraform-astra-provider
https://github.com/anant/example-cassandra-terraform-astra-provider
cassandra datastax datastax-astra gitpod terraform
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/anant/example-cassandra-terraform-astra-provider
- Owner: Anant
- Created: 2022-02-08T20:17:52.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-17T15:15:30.000Z (over 2 years ago)
- Last Synced: 2024-11-18T14:46:03.843Z (3 months ago)
- Topics: cassandra, datastax, datastax-astra, gitpod, terraform
- Language: Shell
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Anant/example-cassandra-terraform-astra-provider)
## 1. [Generate an Astra Token](https://docs.datastax.com/en/astra/docs/manage-application-tokens.html)
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 = ""
}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
```bash
terraform graph | dot -Tsvg > graph.svg
```## 6. Destroy newly created Astra DB instance
```bash
terraform destroy
```