A Terraform provider for managing Lambda GPU Cloud resources, generated from their OpenAPI specification.
Features
- Instance Management: Launch, read, and terminate GPU instances
- Instance Types: Query available instance types with pricing and specifications
- SSH Key Management: Manage SSH keys for instance access
- API Authentication: Secure API key-based authentication
Quick Start
1. Get Your API Key
Visit Lambda Cloud API Keys to generate your API key.
terraform {
required_providers {
lambda = {
source = "github.com/albertocavalcante/lambda"
version = "~> 0.1"
}
}
}
provider "lambda" {
api_key = var.lambda_api_key # or set LAMBDA_CLOUD_API_KEY environment variable
}
3. Query Available Instance Types
data "lambda_instance_types" "available" {}
output "instance_types" {
value = data.lambda_instance_types.available.instance_types
}
4. Launch an Instance
resource "lambda_instance" "my_gpu" {
name = "my-gpu-instance"
instance_type = "gpu_1x_a10"
region = "us-west-2"
ssh_key_names = ["my-ssh-key"]
}
Authentication
The provider supports authentication via:
-
Environment Variable (recommended):
export LAMBDA_CLOUD_API_KEY="your-api-key-here"
-
Provider Configuration:
provider "lambda" {
api_key = "your-api-key-here"
}
Resources
lambda_instance
Manages Lambda GPU Cloud instances.
resource "lambda_instance" "example" {
name = "my-instance"
instance_type = "gpu_1x_a10"
region = "us-west-2"
ssh_key_names = ["my-key"]
quantity = 1
}
Arguments:
name (Required) - Instance name
instance_type (Required) - Instance type (see data source for available types)
region (Required) - Region to launch in
ssh_key_names (Required) - List of SSH key names
quantity (Optional) - Number of instances to launch (default: 1)
Attributes:
id - Instance ID
status - Current instance status
ip - Instance IP address
Data Sources
lambda_instance_types
Retrieves available instance types with pricing and specifications.
data "lambda_instance_types" "all" {}
output "gpu_instances" {
value = [
for instance_type in data.lambda_instance_types.all.instance_types :
instance_type if can(regex("gpu", instance_type.name))
]
}
Attributes:
instance_types - List of available instance types with:
name - Instance type name
price_cents_per_hour - Hourly price in cents
description - Instance description
specs - Hardware specifications
Development
Prerequisites
Tools are automatically installed with pinned versions when you run the generation script:
# Tools are automatically installed from tools.mod with pinned versions
./scripts/generate-provider.sh
Or run tools manually using Go 1.24 with separate tools.mod:
# Download tool dependencies
go mod download -modfile=tools.mod
# Run code generation tools directly with -modfile flag
go run -modfile=tools.mod github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi --help
go run -modfile=tools.mod github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework --help
# Run golangci-lint (install separately due to dependency complexity)
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.2.0
golangci-lint run --timeout=5m
Setup Development Environment
-
Clone the repository:
git clone https://github.com/albertocavalcante/terraform-provider-lambda.git
cd terraform-provider-lambda
-
Fetch the latest OpenAPI specification:
./scripts/fetch-openapi-spec.sh
-
Generate and build the provider:
./scripts/generate-provider.sh
-
Set up local development:
./scripts/setup-local-dev.sh
-
Test the provider:
export LAMBDA_CLOUD_API_KEY="your-api-key"
cd examples
terraform init
terraform plan
Updating the Provider
The provider is generated from Lambda Cloud's OpenAPI specification. To update:
-
Fetch the latest API spec:
./scripts/fetch-openapi-spec.sh
-
Regenerate the provider:
./scripts/generate-provider.sh
-
Test the changes:
./scripts/setup-local-dev.sh
cd examples && terraform plan
Reproducible Builds
This repository uses pinned tool versions for reproducible builds:
- Tool Versions: Defined in
tools.mod (separate from main dependencies)
- API Versioning: OpenAPI spec includes version metadata in
openapi.version
- Generated Code: Committed to git for visibility and reproducibility
Manual OpenAPI Specification Download
If the script doesn't work, download manually:
curl -L -o openapi.json https://cloud.lambda.ai/api/v1/openapi.json
Generator Configuration
The provider generation is controlled by generator_config.yml. Key settings:
- Resource Mappings: Maps API endpoints to Terraform resources
- Field Ignores: Complex fields that can't be auto-generated
- Aliases: Maps API field names to Terraform attribute names
Directory Structure
terraform-provider-lambda/
├── scripts/ # Development and build scripts
│ ├── fetch-openapi-spec.sh # Download latest OpenAPI spec
│ ├── generate-provider.sh # Complete provider generation
│ ├── setup-local-dev.sh # Local development setup
│ ├── setup_local_provider.sh # Alternative local setup (legacy)
│ └── test_provider.sh # Quick test script
├── internal/provider/ # Custom provider implementation
├── codegen/ # Auto-generated framework code (committed)
├── examples/ # Example Terraform configurations
├── .github/workflows/ # CI/CD workflows
├── tools.mod # Go 1.24 native tool management (separate from main deps)
├── generator_config.yml # OpenAPI generator configuration
└── go.mod # Go module definition
Provider Generation Process
This provider is automatically generated from Lambda Cloud's OpenAPI specification:
- OpenAPI Spec →
tfplugingen-openapi → Provider Spec JSON
- Provider Spec JSON →
tfplugingen-framework → Go Provider Code
- Go Provider Code →
go build → Provider Binary
Known Limitations
Some complex API features are not yet implemented:
- Image Specification: Currently uses default Lambda Stack
- User Data: Cloud-init configuration not supported
- Complex Filesystem Mounts: Advanced storage configurations
- Instance Tags: Metadata and tagging not implemented
These features can be added incrementally as the provider matures.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes to the generator configuration or custom provider code
- Test with
./scripts/generate-provider.sh && ./scripts/setup-local-dev.sh
- Submit a pull request
Resources
License
This project is licensed under the MPL-2.0 License - see the LICENSE file for details.
Support