| .. | ||
| Core | ||
| GenerateProvider.ts | ||
| install-terraform-provider-locally.sh | ||
| publish-terraform-provider.sh | ||
| README.md | ||
OneUptime Terraform Provider Generator
Overview
This project provides a dynamic Terraform provider generator that automatically creates a complete, production-ready Terraform provider from OneUptime's OpenAPI specification. The generator is written in TypeScript and produces Go code that follows Terraform provider best practices.
🚀 Features
✅ Dynamic Generation
- Automatic resource discovery from OpenAPI tags and endpoints
- Schema generation from API request/response models
- CRUD operations mapped from HTTP methods (POST→Create, GET→Read, PUT/PATCH→Update, DELETE→Delete)
- Data sources generated from GET endpoints
- Type-safe Go code generation
✅ Complete Provider Structure
- Main provider file with authentication configuration
- HTTP client with support for API key, username/password authentication
- Resource files for all discovered API endpoints
- Data source files for read-only operations
- Documentation auto-generated for Terraform Registry
- Examples and usage guides
✅ Build System
- Go module with proper dependencies
- Makefile for common operations
- Build scripts for multiple platforms
- Installation scripts for local development
- Publishing scripts for Terraform Registry
📁 Generated Structure
Terraform/terraform-provider-oneuptime/
├── main.go # Provider entry point
├── go.mod # Go module definition
├── Makefile # Build automation
├── README.md # Documentation
├── build.sh # Build script
├── install.sh # Local installation
├── test.sh # Test runner
├── example.tf # Usage example
├── internal/provider/
│ ├── provider.go # Main provider implementation
│ ├── client.go # HTTP client
│ ├── config.go # Configuration management
│ ├── schema.go # Provider schema
│ ├── resources.go # Resource registry
│ ├── data_sources.go # Data source registry
│ ├── resource_*.go # Individual resources (100+)
│ └── data_source_*.go # Individual data sources
├── docs/
│ ├── index.md # Provider documentation
│ ├── resources/ # Resource documentation
│ └── data-sources/ # Data source documentation
└── examples/
├── provider.tf # Provider configuration
├── resources.tf # Resource examples
└── data-sources.tf # Data source examples
🔧 Usage
Generate the Provider
# Generate the complete Terraform provider
npm run generate-terraform-provider
Build and Install Locally
# Navigate to the generated provider
cd Terraform/terraform-provider-oneuptime
# Install dependencies and build
go mod tidy
go build
# Install locally for testing
./install.sh
Use in Terraform
terraform {
required_providers {
oneuptime = {
source = "oneuptime/oneuptime"
version = "1.0.0"
}
}
}
provider "oneuptime" {
oneuptime_url = "https://oneuptime.com"
api_key = var.oneuptime_api_key
}
# Create a project
resource "oneuptime_project" "example" {
name = "my-project"
description = "Created with Terraform"
}
# Get project data
data "oneuptime_project_data" "example" {
name = "my-project"
}
🏗️ Architecture
Core Components
- OpenAPIParser - Parses OpenAPI spec and extracts resource definitions
- ResourceGenerator - Generates Terraform resource files with CRUD operations
- DataSourceGenerator - Generates data source files for read operations
- ProviderGenerator - Creates main provider file with authentication
- GoModuleGenerator - Sets up Go module and dependencies
- DocumentationGenerator - Creates docs and examples
- FileGenerator - Handles file I/O operations
- StringUtils - Utility functions for naming conversions
Generation Flow
OpenAPI Spec → Parser → Resource Discovery → Code Generation → Build System
↓ ↓ ↓ ↓ ↓
JSON Schema → Operations → Resources/DataSources → Go Files → Terraform Provider
📋 Generated Resources
The generator automatically creates Terraform resources for all OneUptime API endpoints, including:
- Projects - Project management
- Monitors - Service monitoring
- Alerts - Alert management
- Incidents - Incident tracking
- Status Pages - Public status pages
- Teams - Team organization
- Users - User management
- API Keys - Authentication
- Workflows - Automation
- And 100+ more resources
🔐 Authentication
The provider supports multiple authentication methods:
provider "oneuptime" {
# Method 1: API Key
host = "https://oneuptime.com"
api_key = var.api_key
# Method 2: Username/Password
host = "https://oneuptime.com"
username = var.username
password = var.password
}
Environment variables are also supported:
ONEUPTIME_HOSTONEUPTIME_API_KEYONEUPTIME_USERNAMEONEUPTIME_PASSWORD
🧪 Testing
# Run unit tests
go test ./...
# Run acceptance tests
TF_ACC=1 go test ./... -v -timeout 120m
# Test with example configuration
terraform init
terraform plan
terraform apply
📦 Publishing
# Build for multiple platforms and prepare for publishing
./publish-terraform-provider.sh
# This creates:
# - Binaries for multiple OS/arch combinations
# - SHA256 checksums
# - Release notes
# - GitHub release assets
🔄 Dynamic Updates
The generator is designed to be completely dynamic:
- New API endpoints are automatically discovered and added as resources
- Schema changes are reflected in the generated code
- No manual updates required when the API evolves
- Regenerate anytime with a single command
🎯 Benefits
- Always Up-to-Date - Provider automatically includes new API features
- Type Safety - Generated Go code is type-safe and follows best practices
- Complete Coverage - All API endpoints become Terraform resources
- Production Ready - Includes error handling, logging, and documentation
- Standards Compliant - Follows Terraform provider conventions
- Easy Maintenance - Single source of truth (OpenAPI spec)
🛠️ Development
To modify the generator:
- Edit TypeScript files in
Scripts/TerraformProvider/Core/ - Run
npm run generate-terraform-providerto test changes - Check generated Go code in
Terraform/terraform-provider-oneuptime/ - Iterate and improve
📚 Documentation
- Provider docs are auto-generated for each resource and data source
- Examples show common usage patterns
- README provides setup and usage instructions
- Terraform Registry compatible format
This generator provides a complete, maintainable solution for creating Terraform providers from OpenAPI specifications, ensuring that your infrastructure-as-code tooling stays synchronized with your API evolution.