### Initialize Terraform
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/gke/gke_live_migration/README.MD
Initialize the Terraform CLI in the example root folder. Ensure Terraform is installed and configured.
```bash
tofu init
```
--------------------------------
### Start Minikube Cluster
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/anywhere/README.md
Starts a Minikube cluster with 3 nodes. Ensure Docker Desktop is running.
```sh
minikube start --nodes=3
```
--------------------------------
### Copy Example Terraform Variables
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/gke/gke_clusters_with_workspaces/README.md
Before running the example, rename the provided variable files to their active counterparts.
```bash
cp tf.vars.example tf.vars
cp tf_clusterA.vars.example tf_clusterA.vars
cp tf_clusterB.vars.example tf_clusterB.vars
```
--------------------------------
### Initialize Terraform
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/aks/aks_cluster/README.MD
Run this command in the example root folder to initialize Terraform and download necessary providers.
```bash
terraform init
```
--------------------------------
### Review generated configuration
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/workload_scaling_policy.md
Example of the configuration structure generated by the import process.
```hcl
cpu {
look_back_period_seconds = 0
}
```
--------------------------------
### Example Usage of castai_workload_scaling_policy_order
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/workload_scaling_policy_order.md
This example demonstrates how to configure the order of workload scaling policies for a cluster. It fetches existing policy IDs, defines a custom order for specific policies, and then concatenates them with the remaining policies sorted alphabetically.
```terraform
data "castai_workload_scaling_policy_order" "cluster" {
cluster_id = castai_gke_cluster.cluster.id
}
locals {
ordered_policy_ids = [
"be61e44b-0f7c-44da-b60e-0594d6fd3634",
"f60b79f0-d21e-4eda-a59f-f5daa846d289",
]
unordered_policy_ids = tolist(setsubtract(data.castai_workload_scaling_policy_order.cluster.policy_ids, local.ordered_policy_ids))
}
resource "castai_workload_scaling_policy_order" "custom" {
cluster_id = castai_gke_cluster.cluster.id
policy_ids = concat(local.ordered_policy_ids, sort(local.unordered_policy_ids))
}
```
--------------------------------
### Deploy Private Hosted Model
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/ai_optimizer_hosted_model.md
This example shows how to deploy a private hosted model. No vLLM configuration is needed for private models.
```terraform
resource "castai_ai_optimizer_hosted_model" "private_example" {
cluster_id = castai_eks_cluster.example.id
model_specs_id = castai_ai_optimizer_model_specs.private_example.id
service = "custom-model"
port = 8080
}
```
--------------------------------
### Build and Clone CastAI Terraform Provider
Source: https://github.com/castai/terraform-provider-castai/blob/master/README.md
Clone the repository and build the provider locally. Ensure Go is installed and meets the requirements.
```bash
git clone https://github.com/CastAI/terraform-provider-castai.git
cd terraform-provider-castai
make build
```
--------------------------------
### Import castai_node_template resource example
Source: https://github.com/castai/terraform-provider-castai/blob/master/README.md
This command demonstrates how to import an existing `default-by-castai` node template into Terraform state. This is an optional step if following the migration guide.
```sh
terraform import castai_node_template.default_by_castai 105e6fa3-20b1-424e-v589-9a64d1eeabea/default-by-castai
```
--------------------------------
### EKS Cluster Authentication Configuration Example
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_existing/README.MD
This snippet shows an example entry for the aws-auth ConfigMap, which might be necessary if your EKS cluster uses CONFIGMAP authentication mode. It ensures the instance profile used by CAST AI is present.
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aws-auth
namespace: kube-system
data:
mapRoles:
- rolearn: arn:aws:iam::ACCOUNT_ID:role/CAST_AI_NODE_INSTANCE_ROLE
username: castai-node-role
groups:
- system:bootstrappers
- system:nodes
```
--------------------------------
### Example Reservations CSV Structure
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/reservations.md
Defines the expected structure for the reservations CSV file, including headers and example data for AWS reservations.
```csv
name,provider,region,instance_type,price,count,start_date,end_date,zone_id,zone_name
reservation1,aws,us-east-1,c5n.large,,1,2020-01-01T00:00:00Z,2050-01-01T00:00:00Z,,
reservation2,aws,us-east-1,c5n.large,,2,2020-01-01T00:00:00Z,2050-01-01T00:00:01Z,,
```
--------------------------------
### castai_gke_cluster Resource Example
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/gke_cluster.md
Example usage of the castai_gke_cluster resource to connect a GKE cluster to CAST AI.
```APIDOC
## castai_gke_cluster Resource
### Description
Connects an existing GKE cluster to CAST AI.
### Schema
#### Required
- `location` (String) GCP cluster zone in case of zonal or region in case of regional cluster
- `name` (String) GKE cluster name
- `project_id` (String) GCP project id
#### Optional
- `credentials_json` (String, Sensitive) GCP credentials.json from ServiceAccount with credentials for CAST AI
- `delete_nodes_on_disconnect` (Boolean) Should CAST AI remove nodes managed by CAST.AI on disconnect
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
#### Read-Only
- `cluster_token` (String, Sensitive) CAST.AI agent cluster token
- `credentials_id` (String) CAST AI credentials id for cluster
- `id` (String) The ID of this resource.
- `organization_id` (String) CAST AI organization ID
### Nested Schema for `timeouts`
Optional:
- `create` (String)
- `delete` (String)
- `update` (String)
### Example Usage
```terraform
resource "castai_gke_cluster" "this" {
project_id = var.project_id
location = module.gke.location
name = var.gke_cluster_name
delete_nodes_on_disconnect = var.delete_nodes_on_disconnect
credentials_json = var.gke_credentials
}
```
```
--------------------------------
### Example Usage of castai_gke_user_policies
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/data-sources/gke_user_policies.md
Use this data source to fetch the required GCP policies for CAST AI integration. No specific configuration is needed for basic usage.
```terraform
data "castai_gke_user_policies" "gke" {}
```
--------------------------------
### Configure AWS Edge Location with Terraform
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/edge_location.md
Examples demonstrating how to define an AWS edge location resource with default, custom, or no addons.
```terraform
# AWS Edge Location with default addons (nvidia-gpu-operator installed by default when addons is omitted)
resource "castai_edge_location" "aws_example" {
organization_id = "your-org-id"
cluster_id = castai_omni_cluster.example.id
name = "aws-edge-us-east"
description = "AWS edge location in us-east-1"
region = "us-east-1"
zones = [
{
id = "us-east-1a"
name = "us-east-1a"
},
{
id = "us-east-1b"
name = "us-east-1b"
}
]
aws = {
account_id = "123456789012"
access_key_id_wo = "AKIAIOSFODNN7EXAMPLE"
secret_access_key_wo = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
vpc_id = "vpc-12345678"
security_group_id = "sg-12345678"
subnet_ids = {
"us-east-1a" = "subnet-12345678"
"us-east-1b" = "subnet-87654321"
}
name_tag = "castai-edge-location"
}
}
# AWS Edge Location with custom addons
resource "castai_edge_location" "aws_example_custom_addons" {
organization_id = "your-org-id"
cluster_id = castai_omni_cluster.example.id
name = "aws-edge-us-east-gpu"
region = "us-east-1"
addons = [
{
name = "nvidia-gpu-operator"
values = jsonencode({
driver = {
enabled = true
}
})
},
{
name = "nvidia-network-operator"
}
]
aws = {
account_id = "123456789012"
vpc_id = "vpc-12345678"
security_group_id = "sg-12345678"
subnet_ids = {
"us-east-1a" = "subnet-12345678"
}
}
}
# AWS Edge Location with no addons
resource "castai_edge_location" "aws_example_no_addons" {
organization_id = "your-org-id"
cluster_id = castai_omni_cluster.example.id
name = "aws-edge-us-east-minimal"
region = "us-east-1"
addons = []
aws = {
account_id = "123456789012"
vpc_id = "vpc-12345678"
security_group_id = "sg-12345678"
subnet_ids = {
"us-east-1a" = "subnet-12345678"
}
}
}
```
--------------------------------
### Recommended: Use presets for standard metrics
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/workload_custom_metrics_data_source.md
Use presets for standard metrics managed by CAST AI, which are kept up-to-date automatically. This example configures a Prometheus data source with the 'jvm' preset.
```terraform
resource "castai_workload_custom_metrics_data_source" "prometheus" {
cluster_id = castai_eks_cluster.this.id
name = "my-prometheus"
prometheus {
url = "http://prometheus-server.monitoring.svc.cluster.local:9090"
timeout = "30s"
presets = ["jvm"]
}
}
```
--------------------------------
### Azure Exported Reservations CSV Structure
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/reservations.md
Provides an example of the CSV format for reservations exported from Azure, including specific Azure-related fields.
```csv
Name,Reservation Id,Reservation order Id,Status,Expiration date,Purchase date,Term,Scope,Scope subscription,Scope resource group,Type,Product name,Region,Quantity,Utilization % 1 Day,Utilization % 7 Day,Utilization % 30 Day,Deep link to reservation
VM_RI_01-01-2023_01-01,3b3de39c-bc44-4d69-be2d-69527dfe9958,630226bb-5170-4b95-90b0-f222757130c1,Succeeded,2050-01-01T00:00:00Z,2023-01-11T00:00:00Z,P3Y,Single subscription,8faa0959-093b-4612-8686-a996ac19db00,All resource groups,VirtualMachines,Standard_D32as_v4,eastus,3,100,100,100,https://portal.azure.com#resource/providers/microsoft.capacity/reservationOrders/59791a62-264b-4b9f-aa3a-5eeb761e4583/reservations/883afd52-54c8-4bc6-a0f2-ccbaf7b84bda/overview
VM_RI_01-01-2023_01-02,3b3de39c-bc44-4d69-be2d-69527dfe9958,630226bb-5170-4b95-90b0-f222757130c1,Succeeded,2050-01-01T00:00:00Z,2023-01-11T00:00:01Z,P3Y,Single subscription,8faa0959-093b-4612-8686-a996ac19db00,All resource groups,VirtualMachines,Standard_D32as_v4,eastus,2,100,100,100,https://portal.azure.com#resource/providers/microsoft.capacity/reservationOrders/59791a62-264b-4b9f-aa3a-5eeb761e4583/reservations/25b95bdb-b78b-4973-a60c-71e70f158eca/overview
VM_RI_01-01-2023_01-03,3b3de39c-bc44-4d69-be2d-69527dfe9958,630226bb-5170-4b95-90b0-f222757130c1,Succeeded,2050-01-01T00:00:00Z,2023-01-11T00:00:02Z,P3Y,Single subscription,8faa0959-093b-4612-8686-a996ac19db00,All resource groups,VirtualMachines,Standard_D32as_v4,eastus,1,100,100,100,https://portal.azure.com#resource/providers/microsoft.capacity/reservationOrders/59791a62-264b-4b9f-aa3a-5eeb761e4583/reservations/1745741b-f3c6-46a9-ad16-b93775a1bc38/overview
```
--------------------------------
### Granting EC2 and Pricing Read Permissions to Kentroller
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_kent/README.MD
This example demonstrates how to create a dedicated IAM role with specific read permissions for EC2 inventory, instance offerings, spot-price, and pricing lookups, and associate it with the `castai-kentroller` ServiceAccount.
```terraform
resource "aws_iam_role" "castai_kentroller" {
name = "${var.cluster_name}-castai-kentroller"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Federated = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${data.aws_eks_cluster.castai.identity.0.oidc.0.issuer}"
}
Condition = {
"oidc.eks.amazonaws.com/TokenEx": {
"${data.aws_eks_cluster.castai.identity.0.oidc.0.issuer}": "system:serviceaccount:castai-agent:castai-kentroller"
}
}
}
]
})
}
resource "aws_iam_role_policy" "castai_kentroller" {
name = "castai-kentroller"
role = aws_iam_role.castai_kentroller.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"ec2:DescribeInstanceTypes",
"ec2:DescribeInstances",
"ec2:DescribeImages",
"ec2:DescribeSubnets",
"ec2:DescribeSecurityGroups",
"ec2:DescribeVpcs",
"ec2:DescribeAddresses",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeInstanceAttribute",
"ec2:DescribeInstanceTopology",
"ec2:DescribeInstanceStatus",
"ec2:DescribeEbsVolumes",
"ec2:DescribeVolumesModifications",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:DescribeRegions",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeHostTenancy"
]
Effect = "Allow"
Resource = "*"
},
{
Action = "pricing:GetProducts"
Effect = "Allow"
Resource = "*"
},
{
Action = "eks:DescribeCluster"
Effect = "Allow"
Resource = "${data.aws_eks_cluster.castai.arn}"
}
]
})
}
resource "aws_eks_pod_identity_association" "castai_kentroller" {
cluster_id = data.aws_eks_cluster.castai.id
namespace = "castai-agent"
service_account_name = "castai-kentroller"
role_arn = aws_iam_role.castai_kentroller.arn
}
```
--------------------------------
### Fetch CAST AI Runtime Rules
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_with_security_runtime_rules/README.MD
Execute the provided shell script to fetch CAST AI runtime rules. This script requires 'jq' to be installed. You can fetch all rules or only those that are already enabled.
```bash
# Fetch all rules
./fetch_castai_runtime_rules.sh
# Fetch only already enabled rules
./fetch_castai_runtime_rules.sh --enabled-only
```
--------------------------------
### Deploy CAST AI Spot Handler on AKS
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/aks/aks_cluster_gitops/README.md
Installs the spot handler component. This command configures it to use the cluster's metadata and sets the provider to Azure. Ensure the `CAST_CONFIG_CLUSTERID` is correctly set.
```bash
helm upgrade -i castai-spot-handler castai-helm/castai-spot-handler -n castai-agent \
--set "envFrom[0].configMapRef.name=$CAST_CONFIG_CLUSTERID" \
--set castai.provider=azure
```
--------------------------------
### Deploy CAST AI Cluster Controller using Helm
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_gitops/README.md
Installs or upgrades the castai-cluster-controller Helm chart. This component requires specific environment variables for configuration and enabling autoscaling.
```bash
helm upgrade -i cluster-controller castai-helm/castai-cluster-controller -n castai-agent \
--set autoscaling.enabled=true \
--set "envFrom[0].secretRef.name=$CAST_SECRET_APIKEY" \
--set "envFrom[1].configMapRef.name=$CAST_CONFIG_CLUSTERID"
```
--------------------------------
### Deploy CAST AI Agent using Helm
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_gitops/README.md
Installs or upgrades the castai-agent Helm chart. This is a mandatory component for cluster onboarding and requires the CAST AI API key and cluster ID.
```bash
CASTAI_API_KEY=""
CAST_CONFIG_CLUSTERID="castai-agent-metadata"
CAST_SECRET_APIKEY="castai-agent"
helm upgrade -i castai-agent castai-helm/castai-agent -n castai-agent --create-namespace \
--set apiKey="$CASTAI_API_KEY" \
--set provider=eks \
--set createNamespace=false \
--set metadataStore.enabled=true
```
--------------------------------
### Importing an Existing Scaling Policy Order
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/workload_scaling_policy_order.md
This example shows how to import an existing workload scaling policy order into your Terraform state. Ensure you have the correct cluster ID and adjust the import configuration as needed.
```terraform
import {
to = castai_workload_scaling_policy_order.custom
id = var.castai_gke_cluster_id
}
```
--------------------------------
### EKS Settings Data Source Example
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/data-sources/eks_settings.md
Use this data source to fetch EKS settings, including IAM policies, for a specified cluster. Ensure you have the necessary AWS credentials and cluster information configured.
```terraform
data "castai_eks_settings" "current" {
account_id = data.aws_caller_identity.current.account_id
region = var.cluster_region
cluster = var.cluster_name
vpc = var.vpc
}
```
--------------------------------
### Import CAST AI Runtime Rules Script
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/aks/aks_cluster_with_security_runtime_rules/README.MD
This shell script fetches CAST AI runtime rules and generates Terraform resources. It requires `jq` to be installed. Set `CASTAI_API_KEY` and optionally `CASTAI_BASE_URL` environment variables before running.
```shell
export CASTAI_API_KEY="your-api-key-here"
export CASTAI_BASE_URL="https://api.cast.ai" # Optional, default is https://api.cast.ai
# Fetch all rules
./fetch_castai_runtime_rules.sh
# Fetch only already enabled rules
./fetch_castai_runtime_rules.sh --enabled-only
```
--------------------------------
### Deploy CAST AI Agent on AKS
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/aks/aks_cluster_gitops/README.md
Installs the core CAST AI agent using Helm. Ensure you replace the placeholder for CASTAI_API_KEY with your actual cluster token. This component is mandatory for cluster onboarding.
```bash
CASTAI_API_KEY=""
CAST_CONFIG_CLUSTERID="castai-agent-metadata"
CAST_SECRET_APIKEY="castai-agent"
helm upgrade -i castai-agent castai-helm/castai-agent -n castai-agent --create-namespace \
--set apiKey="$CASTAI_API_KEY" \
--set provider=aks \
--set createNamespace=false \
--set metadataStore.enabled=true
```
--------------------------------
### Deploy CAST AI Pod Pinner on AKS
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/aks/aks_cluster_gitops/README.md
Installs the pod pinner component. Note that `replicaCount` is set to 0, indicating it might be disabled by default or configured for manual activation. It requires references to secrets and config maps.
```bash
helm upgrade -i castai-pod-pinner castai-helm/castai-pod-pinner -n castai-agent \
--set "envFrom[0].secretRef.name=$CAST_SECRET_APIKEY" \
--set "envFrom[1].configMapRef.name=$CAST_CONFIG_CLUSTERID" \
--set replicaCount=0
```
--------------------------------
### Initialize and Apply Terraform Configuration
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_existing_with_ai_optimizer/README.MD
Initialize Terraform and apply the configuration to set up CAST AI resources, NVIDIA device plugin, and model deployments. Use `terraform destroy` to remove created resources.
```bash
terraform init
terraform apply
terraform destroy
```
--------------------------------
### Generate import plan
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/workload_scaling_policy.md
Execute the plan command to generate configuration for imported resources.
```shell
terraform plan -out=import.plan -var-file=tf.vars -generate-config-out=generated.tf
```
--------------------------------
### Apply Terraform Configuration
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/aks/aks_cluster/README.MD
Execute this command to create the resources defined in your Terraform configuration.
```bash
terraform apply
```
--------------------------------
### Initialize and Apply Terraform Configuration
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_kent/README.MD
Initialize the Terraform working directory and apply the configuration to deploy the EKS cluster stack. Ensure you have filled in the required variables in `terraform.tfvars`.
```sh
cp terraform.tfvars.example terraform.tfvars
# fill in cluster_name, cluster_region, castai_api_token
terraform init
terraform apply
```
--------------------------------
### Install CAST AI in read-only mode
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/gke/gke_cluster_gitops_umbrella_chart/README.md
Installs the CAST AI umbrella Helm chart in read-only mode on a GKE cluster. This mode allows CAST AI to observe the cluster without making any changes to workloads or nodes. Requires a CAST AI member API key and Helm.
```sh
helm upgrade -i castai castai-helm/castai -n castai-agent --create-namespace \
--set global.castai.apiKey="" \
--set global.castai.provider="gke" \
--set tags.readonly=true
```
--------------------------------
### Enable Debug Logging for Terraform
Source: https://github.com/castai/terraform-provider-castai/blob/master/README.md
To get more detailed logs during Terraform operations, set the `TF_LOG` environment variable to `DEBUG`.
```bash
TF_LOG=DEBUG terraform plan
```
--------------------------------
### Manage Cloud Commitments with Terraform
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/commitment.md
Examples of defining various cloud provider commitments including GCP, AWS, and Azure resources.
```terraform
# GCP committed use discount (resource CUD).
resource "castai_commitment" "gcp_cud" {
name = "prod-cud-us-central1"
cloud = "GCP"
region = "us-central1"
type = "RESOURCE_CUD"
start_time = "2026-01-01T00:00:00Z"
end_time = "2027-01-01T00:00:00Z"
autoscaling_status = "ACTIVE"
allowed_usage = 1.0
gcp_resource_cud_details = {
cud_id = "123456789"
plan = "TWELVE_MONTH"
type = "GENERAL_PURPOSE_E2"
cpu = 32
memory_mb = 131072
status = "ACTIVE"
}
}
# AWS reserved instances.
resource "castai_commitment" "aws_ri" {
name = "prod-ri-us-east-1"
cloud = "AWS"
region = "us-east-1"
type = "RESERVED_INSTANCE"
start_time = "2026-01-01T00:00:00Z"
end_time = "2027-01-01T00:00:00Z"
aws_reserved_instances_details = {
id = "abcdef01-2345-6789-abcd-ef0123456789"
scope = "Region"
instance_type = "m5.xlarge"
instance_count = 10
state = "active"
}
}
# Azure reservation.
resource "castai_commitment" "azure_reservation" {
name = "prod-reservation-eastus"
cloud = "AZURE"
region = "eastus"
type = "RESERVED_INSTANCE"
start_time = "2026-01-01T00:00:00Z"
end_time = "2029-01-01T00:00:00Z"
azure_reservation_details = {
id = "abcdef01-2345-6789-abcd-ef0123456789"
plan = "THREE_YEAR"
status = "Succeeded"
scope = "Shared"
instance_type = "Standard_D4s_v3"
count = 5
instance_flexibility = "ON"
}
}
# GCP capacity reservation (on-demand).
resource "castai_commitment" "gcp_capacity_reservation" {
name = "gpu-reservation-us-central1"
cloud = "GCP"
region = "us-central1"
type = "ON_DEMAND_CAPACITY_RESERVATION"
start_time = "2026-01-01T00:00:00Z"
gcp_capacity_reservation_details = {
id = "my-reservation"
self_link = "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/reservations/my-reservation"
project_id = "my-project"
zone = "us-central1-a"
instance_type = "a2-highgpu-1g"
total_instance_count = 4
state = "READY"
accelerators = [
{
accelerator_type = "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/acceleratorTypes/nvidia-tesla-a100"
accelerator_count = 1
}
]
}
}
# AWS on-demand capacity reservation (ODCR).
resource "castai_commitment" "aws_odcr" {
name = "prod-odcr-us-east-1"
cloud = "AWS"
region = "us-east-1"
type = "ON_DEMAND_CAPACITY_RESERVATION"
start_time = "2026-01-01T00:00:00Z"
autoscaling_status = "ACTIVE"
allowed_usage = 1.0
aws_odcr_details = {
id = "cr-abcdef01234567890"
availability_zone = "us-east-1a"
instance_type = "m5.xlarge"
instance_platform = "Linux/UNIX"
tenancy = "default"
total_instance_count = 10
available_instance_count = 10
state = "active"
end_date_type = "unlimited"
instance_match_criteria = "open"
interruptible = false
}
}
```
--------------------------------
### Create Organization Workspace and Resources
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/gke/gke_clusters_with_workspaces/README.md
Create a new Terraform workspace for the organization and apply the initial configuration using the organization's variable file.
```bash
terraform workspace new org-workspace
terraform plan -var-file=tf.vars
terraform apply -var-file=tf.vars
```
--------------------------------
### Plan import for multiple policies
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/workload_scaling_policy.md
Generate an import plan for multiple policies without generating new configuration files.
```shell
terraform plan -out=import.plan -var-file=tf.vars
```
--------------------------------
### Define resource for CLI import
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/workload_scaling_policy.md
Establish the resource block in configuration before running the import command.
```hcl
resource "castai_workload_scaling_policy" "services" {
# ...
}
```
--------------------------------
### Terraform Lifecycle Commands
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_readonly_kvisor/README.MD
Standard Terraform commands to initialize, apply, and destroy the infrastructure configuration.
```bash
terraform init
```
```bash
terraform apply
```
```bash
terraform destroy
```
--------------------------------
### Plan Terraform Deployment
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/anywhere/README.md
Previews the resources Terraform will create or modify.
```sh
terraform plan
```
--------------------------------
### Azure Commitments Configuration
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/commitments.md
Example of configuring Azure Reserved Instances with specific matchers, allowed usage, and cluster assignments. Auto-assignment is enabled by default.
```terraform
resource "castai_commitments" "azure_test" {
azure_reservations_csv = file("./reservations.csv")
commitment_configs {
matcher {
region = "eastus"
type = "Standard_D32as_v4"
name = "test-res-1"
}
prioritization = false
allowed_usage = 0.9
status = "Active"
scaling_strategy = "Default"
assignments {
cluster_id = "cluster-id-3"
}
assignments {
cluster_id = "cluster-id-4"
}
}
}
```
--------------------------------
### Add castai-helm repository
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/gke/gke_cluster_gitops_umbrella_chart/README.md
Adds the castai-helm repository to your Helm configuration and updates the repository list. This is a prerequisite for installing the CAST AI Helm chart.
```sh
helm repo add castai-helm https://castai.github.io/helm-charts
helm repo update
```
--------------------------------
### Enable Extended Permissions in Terraform
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/castware-operator/README.md
Set the `extended_permissions` variable to `true` in your Terraform configuration to enable extended permissions, which is required for installing the `cluster-controller` component.
```hcl
extended_permissions = true
```
--------------------------------
### Initialize and apply Terraform for Full mode
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/gke/gke_cluster_gitops_umbrella_chart/README.md
Initializes the Terraform configuration and applies it to create a GCP service account with necessary IAM permissions for node provisioning and to register the cluster with CAST AI. This step is required before upgrading to Full mode.
```sh
terraform init
terraform apply
```
--------------------------------
### Expected CAST AI Stream Connection Log Output
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_kent/README.MD
This is an example of successful log messages indicating a healthy stream connection and registration with CAST AI.
```log
msg="getStream: stream registered confirmation received, stream is ready" cluster_id=
msg="streaming messages..." cluster_id=
msg="stream connected, syncing all schedules to Kent" cluster_id=
```
--------------------------------
### Run Unit Tests for CastAI Terraform Provider
Source: https://github.com/castai/terraform-provider-castai/blob/master/README.md
Execute the unit tests for the provider using the `make test` command.
```bash
make test
```
--------------------------------
### Get Service Account Unique IDs
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/gke/gke_castai_iam/README.md
Run this script to obtain the unique IDs for service accounts, which are necessary for configuring IAM policies with custom conditions.
```bash
PROJECT_ID= LOCATION= CLUSTER_NAME= ./script.sh
```
--------------------------------
### Configure Terraform for Local Provider Development
Source: https://github.com/castai/terraform-provider-castai/blob/master/README.md
Set up the `~/.terraformrc` file to use a locally built provider. Replace `` with the actual path to your cloned repository.
```terraform
provider_installation {
dev_overrides {
"castai/castai" = ""
}
direct {}
}
```
--------------------------------
### Deploy CAST AI Workload Autoscaler using Helm
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_gitops/README.md
Installs or upgrades the castai-workload-autoscaler Helm chart. This component requires specific secret and configMap references for its configuration.
```bash
helm upgrade -i castai-workload-autoscaler castai-helm/castai-workload-autoscaler -n castai-agent \
--set "envFrom[0].secretRef.name=$CAST_SECRET_APIKEY" \
--set "envFrom[1].configMapRef.name=$CAST_CONFIG_CLUSTERID" \
```
--------------------------------
### Import Node Configuration
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/node_configuration.md
Execute the import command to attach an existing node configuration to the defined Terraform resource.
```shell
$ terraform import castai_node_configuration.default /default
```
```shell
$ terraform import 'module.castai-eks-cluster.castai_node_configuration.this["default"]' /default
```
--------------------------------
### Retrieve CAST AI Cluster ID
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_kent/README.MD
Get the CAST AI cluster ID from the agent's ConfigMap, which is used for identification within the CAST AI platform.
```sh
kubectl -n castai-agent get cm castai-agent-metadata -o jsonpath='{.data.CLUSTER_ID}'
```
--------------------------------
### Configure S3 Model Registry
Source: https://github.com/castai/terraform-provider-castai/blob/master/docs/resources/ai_optimizer_model_registry.md
Example of how to configure an AWS S3 bucket as the AI optimizer model registry. Ensure the `registry_credentials` variable is properly set with JSON-encoded credentials.
```terraform
resource "castai_ai_optimizer_model_registry" "example" {
provider_type = "S3"
credentials = var.registry_credentials
s3 {
bucket = "my-company-model-registry"
region = "us-east-1"
prefix = "models/"
}
}
```
--------------------------------
### Enable CAST AI Live Migrations (CLM)
Source: https://github.com/castai/terraform-provider-castai/blob/master/examples/eks/eks_cluster_kent/README.MD
Configure the `kent` subchart to enable live migrations by setting the CLM controller replica count.
```hcl
kent = {
enabled = true
castai-live = {
controller = { replicaCount = 2 }
}
}
```