### Terraform EKS Deployment Example Source: https://context7.com/castai/terraform-castai-dbo/llms.txt A complete Terraform example for deploying CAST AI DBO on an existing EKS cluster. It includes variable definitions, cache group creation, cache configuration, and the DBO module deployment. ```hcl # terraform.tfvars cluster_name = "my-eks-cluster" cluster_region = "us-east-1" castai_api_token = "your-cast-ai-api-token" # dbo.tf # Create a cache group for the PostgreSQL instance resource "castai_cache_group" "this" { name = "my-cache-group" protocol_type = "PostgreSQL" endpoints { hostname = "my-rds-instance.abcdefghijkl.us-east-1.rds.amazonaws.com" port = 5432 name = "primary" } endpoints { hostname = "my-rds-instance-ro.abcdefghijkl.eu-north-1.rds.amazonaws.com" port = 5432 name = "ro" } } # Create cache configuration for a specific database resource "castai_cache_configuration" "this" { cache_group_id = castai_cache_group.this.id database_name = "mydb" mode = "Auto" } # Deploy CAST AI DBO module "castai_dbo" { source = "github.com/castai/terraform-castai-dbo" castai_api_token = var.castai_api_token castai_api_url = trimsuffix(trimprefix(var.castai_api_url, "https://"), "/") cache_group_id = castai_cache_group.this.id # Pin to specific version (optional) # dbo_version = "0.53.0" depends_on = [castai_cache_group.this] } # Deployment commands: # terraform init # terraform plan # terraform apply ``` -------------------------------- ### Terraform Variables for GKE Provider Setup Source: https://context7.com/castai/terraform-castai-dbo/llms.txt Defines input variables specific to the Google Kubernetes Engine provider configuration, including cluster name, region, project ID, and CAST AI credentials. ```hcl # variables.tf variable "cluster_name" { type = string description = "GKE cluster name in GCP project." } variable "cluster_region" { type = string description = "The region to create the cluster." } variable "project_id" { type = string description = "GCP project ID in which GKE cluster would be created." } variable "castai_api_token" { type = string description = "CAST AI API token created in console.cast.ai API Access keys section." sensitive = true } variable "castai_api_url" { type = string description = "CAST AI API URL." default = "https://api.cast.ai" } ``` -------------------------------- ### Initialize and Apply Terraform Configuration (Bash) Source: https://github.com/castai/terraform-castai-dbo/blob/main/examples/gke/README.md This bash script demonstrates the standard Terraform workflow for initializing the project and applying the infrastructure changes. It ensures all necessary providers are downloaded and the DBO module is deployed to your GKE cluster. ```bash terraform init terraform apply ``` -------------------------------- ### Deploy CAST AI Database Optimizer Helm Chart (Terraform) Source: https://context7.com/castai/terraform-castai-dbo/llms.txt Deploys the CAST AI Database Optimizer Helm chart to a Kubernetes cluster using the `castai_dbo` module. It requires the CAST AI API token and a cache group ID. Optional variables allow customization of the API URL, DBO version, namespace, Helm release name, and advanced Helm values. ```hcl module "castai_dbo" { source = "github.com/castai/terraform-castai-dbo" # Required variables castai_api_token = var.castai_api_token # CAST AI API token for authentication cache_group_id = castai_cache_group.this.id # ID of the cache group # Optional variables castai_api_url = "api.cast.ai" # CAST AI API URL (default) dbo_version = "0.50.0" # Helm chart version dbo_namespace = "castai-db-optimizer" # Kubernetes namespace helm_release_name = "" # Custom Helm release name (auto-generated if empty) # Custom Helm values for advanced configuration dbo_values = [ yamlencode({ replicas = 2 resources = { proxy = { cpu = "500m" memoryRequest = "1Gi" memoryLimit = "1Gi" } queryProcessor = { cpu = "300m" memory = "512Mi" } } }) ] depends_on = [castai_cache_group.this] } ``` -------------------------------- ### Configure AWS EKS Provider for CAST AI DBO Deployment (Terraform) Source: https://context7.com/castai/terraform-castai-dbo/llms.txt Sets up the Terraform configuration for deploying the CAST AI DBO on an AWS EKS cluster. It defines required Terraform versions, providers (castai, aws, helm), and configures the AWS and CAST AI providers. It also retrieves EKS cluster details and authentication for the Helm provider. ```hcl # versions.tf terraform { required_version = ">= 1.3.2" required_providers { castai = { source = "castai/castai" version = ">= 8.4.0" } aws = { source = "hashicorp/aws" } helm = { source = "hashicorp/helm" } } } # providers.tf provider "aws" { region = var.cluster_region } provider "castai" { api_token = var.castai_api_token api_url = var.castai_api_url } data "aws_eks_cluster" "my_cluster" { name = var.cluster_name } data "aws_eks_cluster_auth" "my_cluster" { name = var.cluster_name } provider "helm" { kubernetes = { host = data.aws_eks_cluster.my_cluster.endpoint token = data.aws_eks_cluster_auth.my_cluster.token cluster_ca_certificate = base64decode(data.aws_eks_cluster.my_cluster.certificate_authority[0].data) } } ``` -------------------------------- ### Terraform Provider Configuration for GKE Source: https://context7.com/castai/terraform-castai-dbo/llms.txt Configures the necessary Terraform providers (castai, google, helm) for deploying DBO on Google Kubernetes Engine. It sets up authentication and endpoint details for each provider. ```hcl # versions.tf terraform { required_version = ">= 1.3.2" required_providers { castai = { source = "castai/castai" version = ">= 8.4.0" } google = { source = "hashicorp/google" } helm = { source = "hashicorp/helm" } } } # providers.tf provider "google" { project = var.project_id region = var.cluster_region } provider "castai" { api_token = var.castai_api_token api_url = var.castai_api_url } data "google_container_cluster" "my_cluster" { name = var.cluster_name location = var.cluster_region } data "google_client_config" "default" {} provider "helm" { kubernetes = { host = "https://${data.google_container_cluster.my_cluster.endpoint}" token = data.google_client_config.default.access_token cluster_ca_certificate = base64decode(data.google_container_cluster.my_cluster.master_auth[0].cluster_ca_certificate) } } ``` -------------------------------- ### Deploy CAST AI Database Optimizer with Terraform Source: https://github.com/castai/terraform-castai-dbo/blob/main/README.md This snippet demonstrates how to deploy the CAST AI Database Optimizer using the provided Terraform module. It includes creating a cache group, a cache configuration, and then deploying the DBO Helm chart with optional custom values. The module requires a CAST AI API token and a cache group ID. ```hcl resource "castai_cache_group" "this" { name = "my-postgres-cache" protocol_type = "PostgreSQL" endpoints { hostname = "my-database.example.com" port = 5432 name = "primary" } } resource "castai_cache_configuration" "this" { cache_group_id = castai_cache_group.this.id database_name = "myapp" mode = "Auto" } module "castai_dbo" { source = "github.com/castai/terraform-castai-dbo" castai_api_token = var.castai_api_token cache_group_id = castai_cache_group.this.id dbo_values = [ yamlencode({ replicas = 1 resources = { proxy = { cpu = "200m" memoryRequest = "500Mi" memoryLimit = "500Mi" } queryProcessor = { cpu = "200m" memory = "400Mi" } } }) ] } ``` -------------------------------- ### Terraform Variables for CAST AI DBO Source: https://context7.com/castai/terraform-castai-dbo/llms.txt Defines input variables for the CAST AI DBO Terraform module, including cluster details and API credentials. Sensitive variables like the API token are marked. ```hcl variable "cluster_name" { type = string description = "Name of the EKS cluster." } variable "cluster_region" { type = string description = "AWS region where the EKS cluster is deployed." } variable "castai_api_token" { type = string description = "CAST AI API token created in console.cast.ai API Access keys section." sensitive = true } variable "castai_api_url" { type = string description = "CAST AI API URL" default = "https://api.cast.ai" } ``` -------------------------------- ### Destroy Terraform Resources (Bash) Source: https://github.com/castai/terraform-castai-dbo/blob/main/examples/gke/README.md This bash command initiates the cleanup process for the deployed CAST AI DBO resources. It safely removes the cache group, configuration, and Helm chart deployment, reverting your GKE cluster to its previous state. ```bash terraform destroy ``` -------------------------------- ### Define CAST AI Cache Group for PostgreSQL or MySQL (Terraform) Source: https://context7.com/castai/terraform-castai-dbo/llms.txt Defines a cache group resource for CAST AI DBO, representing a database instance. It supports PostgreSQL and MySQL protocols and allows specifying multiple endpoints, including primary and read-replica for PostgreSQL. This resource is essential for configuring caching policies. ```hcl # Create a cache group for PostgreSQL with primary and read-replica endpoints resource "castai_cache_group" "postgres" { name = "production-postgres" protocol_type = "PostgreSQL" # Supported: "PostgreSQL" or "MySQL" # Primary database endpoint endpoints { hostname = "my-rds-instance.abcdefghijkl.us-east-1.rds.amazonaws.com" port = 5432 name = "primary" } # Read replica endpoint endpoints { hostname = "my-rds-instance-ro.abcdefghijkl.us-east-1.rds.amazonaws.com" port = 5432 name = "read-replica" } } # MySQL example resource "castai_cache_group" "mysql" { name = "production-mysql" protocol_type = "MySQL" endpoints { hostname = "mysql.example.com" port = 3306 name = "primary" } } ``` -------------------------------- ### Configure CAST AI Cache Behavior for a Database (Terraform) Source: https://context7.com/castai/terraform-castai-dbo/llms.txt Configures the caching behavior for a specific database within a CAST AI cache group. It supports 'Auto' mode for automatic caching of eligible queries and 'DontCache' mode for passthrough (no caching). This resource links a cache group to a database and defines its caching strategy. ```hcl # Enable automatic caching for a specific database resource "castai_cache_configuration" "auto_cache" { cache_group_id = castai_cache_group.postgres.id database_name = "production_db" mode = "Auto" # Automatically cache eligible queries } # Passthrough mode (no caching) for a database resource "castai_cache_configuration" "passthrough" { cache_group_id = castai_cache_group.postgres.id database_name = "analytics_db" mode = "DontCache" # All queries pass through without caching } ``` -------------------------------- ### Configure CAST AI DBO Cache Group (HCL) Source: https://github.com/castai/terraform-castai-dbo/blob/main/examples/gke/README.md This HCL code defines a CAST AI cache group resource, specifying the database protocol type and connection endpoints. It's a prerequisite for deploying DBO and enables intelligent caching for database queries. ```hcl resource "castai_cache_group" "this" { name = "my-cache-group" protocol_type = "PostgreSQL" # or "MySQL" endpoints { hostname = "your-db.example.com" port = 5432 name = "primary" } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.