This demo shows how to use the Runpod Terraform provider to manage Runpod resources.
- Terraform 1.0 or higher
- Runpod API token (get from https://runpod.io/console/user/settings)
mkdir -p ~/.terraform.d
cat > ~/.terraform.d/config.tfrc << 'EOF'
provider_installation {
dev_overrides {
"runpod/runpod" = "./"
}
direct {}
}
EOFgo build -o terraform-provider-runpod
# Configure Terraform to use local binary
cat > ~/.terraform.rc << 'EOF'
provider_installation {
filesystem_paths {
paths = ["."]
}
}
EOFSee LOCAL_SETUP.md for more details.
terraform {
required_providers {
runpod = {
source = "runpod/runpod"
}
}
}
provider "runpod" {
api_key = var.runpod_api_key
}
resource "runpod_pod" "demo_pod" {
machine_id = "your-machine-id"
image_name = "runpod/miniconda:py3.10-cuda11.8.0"
gpu_count = 1
name = "demo-pod"
start_ssh = true
start_jupyter = true
}
output "pod_id" {
value = runpod_pod.demo_pod.id
}
output "pod_status" {
value = runpod_pod.demo_pod.status
}# List available GPU types
data "runpod_gpu_types" "available" {}
# List available data centers
data "runpod_data_centers" "locations" {}
# Get current user info
data "runpod_user" "current" {}
# List available machines
data "runpod_machines" "available" {
listed = true
}
# Get specific machine
data "runpod_machine" "selected" {
id = "machine-id-here"
}
# Get specific pod
data "runpod_pod" "running" {
id = "pod-id-here"
}resource "runpod_pod_action" "stop_pod" {
pod_id = "pod-id-here"
action = "stop"
}
resource "runpod_pod_action" "resume_pod" {
pod_id = "pod-id-here"
action = "resume"
}
resource "runpod_pod_action" "terminate_pod" {
pod_id = "pod-id-here"
action = "terminate"
}resource "runpod_machine" "bid_machine" {
gpu_type_id = "RTX 3090"
gpu_count = 2
cpu_count = 8
memory_in_gb = 32
disk_in_gb = 50
data_center_id = "data-center-id"
secure_cloud = false
listed = true
host_price_per_gpu = 0.50
}Set these environment variables instead of using provider config:
export RUNPOD_API_KEY="your-api-key"runpod_pod- Create and manage podsrunpod_pod_action- Perform actions on pods (stop, resume, terminate, reset)runpod_machine- Manage machine listings and bidding
runpod_pod- Retrieve pod informationrunpod_machine- Retrieve machine informationrunpod_machines- List all machinesrunpod_gpu_types- List available GPU typesrunpod_data_centers- List data centersrunpod_user- Get current user info
- Set up your Terraform configuration with your API key
- Run:
terraform init && terraform plan && terraform apply