mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Add comprehensive documentation for OneUptime Terraform Provider
- Created main documentation index for Terraform Provider. - Added Quick Start Guide for rapid setup and configuration. - Developed detailed installation and usage guide from Terraform Registry. - Introduced Self-Hosted Configuration Guide emphasizing version compatibility. - Included troubleshooting sections and best practices for self-hosted users. - Provided complete configuration examples for various environments.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -117,5 +117,6 @@ InfrastructureAgent/oneuptime-infrastructure-agent
|
||||
.eslintcache*
|
||||
|
||||
# Terraform generated files
|
||||
Terraform/
|
||||
openapi.json
|
||||
|
||||
Terraform/**
|
||||
613
Docs/Content/terraform/README.md
Normal file
613
Docs/Content/terraform/README.md
Normal file
@@ -0,0 +1,613 @@
|
||||
# OneUptime Terraform Provider
|
||||
|
||||
The OneUptime Terraform Provider allows you to manage OneUptime resources using Infrastructure as Code (IaC). This provider enables you to configure monitoring, incident management, status pages, and other OneUptime features through Terraform.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Provider Configuration](#provider-configuration)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Version Compatibility](#version-compatibility)
|
||||
- [Available Resources](#available-resources)
|
||||
- [Examples](#examples)
|
||||
- [Best Practices](#best-practices)
|
||||
- [Migration Guide](#migration-guide)
|
||||
|
||||
## Installation
|
||||
|
||||
### From Terraform Registry (Recommended)
|
||||
|
||||
The OneUptime Terraform provider is available on the [Terraform Registry](https://registry.terraform.io/providers/oneuptime/oneuptime).
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0" # Use latest 7.x version
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
```
|
||||
|
||||
### Version Pinning for Self-Hosted Installations
|
||||
|
||||
⚠️ **Important for Self-Hosted Customers**: Always pin the Terraform provider version to match your OneUptime installation version to ensure API compatibility.
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Pin to exact version matching your OneUptime installation
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
```
|
||||
|
||||
#### Finding Your OneUptime Version
|
||||
|
||||
You can find your OneUptime version in several ways:
|
||||
|
||||
1. **Dashboard**: Go to Settings → About in your OneUptime dashboard
|
||||
2. **API**: Call `GET /api/status` endpoint
|
||||
3. **Docker**: Check the image tag you're using
|
||||
4. **Helm**: Check your Helm chart version
|
||||
|
||||
```bash
|
||||
# Example: If running OneUptime 7.0.123
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Provider Configuration
|
||||
|
||||
### Basic Configuration
|
||||
|
||||
```hcl
|
||||
provider "oneuptime" {
|
||||
api_url = "https://your-oneuptime-instance.com" # Or https://api.oneuptime.com for cloud
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
### Environment Variables
|
||||
|
||||
You can configure the provider using environment variables:
|
||||
|
||||
```bash
|
||||
export ONEUPTIME_API_URL="https://your-oneuptime-instance.com"
|
||||
export ONEUPTIME_API_KEY="your-api-key-here"
|
||||
```
|
||||
|
||||
Then use the provider without explicit configuration:
|
||||
|
||||
```hcl
|
||||
provider "oneuptime" {
|
||||
# Configuration will be read from environment variables
|
||||
}
|
||||
```
|
||||
|
||||
### Configuration Options
|
||||
|
||||
| Argument | Environment Variable | Description | Required |
|
||||
|----------|---------------------|-------------|----------|
|
||||
| `api_url` | `ONEUPTIME_API_URL` | OneUptime API URL | Yes |
|
||||
| `api_key` | `ONEUPTIME_API_KEY` | OneUptime API Key | Yes |
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Create API Key
|
||||
|
||||
First, create an API key in your OneUptime dashboard:
|
||||
|
||||
1. Go to **Settings** → **API Keys**
|
||||
2. Click **Create API Key**
|
||||
3. Give it a descriptive name (e.g., "Terraform Automation")
|
||||
4. Select appropriate permissions
|
||||
5. Copy the generated API key
|
||||
|
||||
### 2. Basic Terraform Configuration
|
||||
|
||||
Create a `main.tf` file:
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://api.oneuptime.com" # Use your instance URL
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
# Create a project
|
||||
resource "oneuptime_project" "example" {
|
||||
name = "My Terraform Project"
|
||||
description = "Project created with Terraform"
|
||||
}
|
||||
|
||||
# Create a monitor
|
||||
resource "oneuptime_monitor" "website" {
|
||||
name = "Website Monitor"
|
||||
project_id = oneuptime_project.example.id
|
||||
|
||||
monitor_type = "website"
|
||||
url = "https://example.com"
|
||||
interval = "5m"
|
||||
|
||||
tags = {
|
||||
environment = "production"
|
||||
team = "platform"
|
||||
}
|
||||
}
|
||||
|
||||
# Create an alert policy
|
||||
resource "oneuptime_alert_policy" "critical" {
|
||||
name = "Critical Alerts"
|
||||
project_id = oneuptime_project.example.id
|
||||
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.website.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
notifications {
|
||||
type = "email"
|
||||
value = "alerts@example.com"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Initialize and Apply
|
||||
|
||||
```bash
|
||||
# Initialize Terraform
|
||||
terraform init
|
||||
|
||||
# Plan the changes
|
||||
terraform plan
|
||||
|
||||
# Apply the configuration
|
||||
terraform apply
|
||||
```
|
||||
|
||||
## Version Compatibility
|
||||
|
||||
### Cloud Customers
|
||||
|
||||
For OneUptime Cloud customers, use the latest provider version:
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0" # Always use latest compatible version
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Self-Hosted Customers
|
||||
|
||||
**Critical**: Self-hosted customers must pin the provider version to match their OneUptime installation:
|
||||
|
||||
| OneUptime Version | Provider Version | Configuration |
|
||||
|-------------------|------------------|---------------|
|
||||
| 7.0.x | 7.0.x | `version = "~> 7.0.0"` |
|
||||
| 7.1.x | 7.1.x | `version = "~> 7.1.0"` |
|
||||
| 7.2.x | 7.2.x | `version = "~> 7.2.0"` |
|
||||
|
||||
Example for OneUptime 7.0.123:
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Exact version match
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Available Resources
|
||||
|
||||
The OneUptime Terraform provider supports the following resources:
|
||||
|
||||
### Core Resources
|
||||
- `oneuptime_project` - Manage projects
|
||||
- `oneuptime_team` - Manage teams
|
||||
- `oneuptime_user` - Manage users (enterprise only)
|
||||
|
||||
### Monitoring
|
||||
- `oneuptime_monitor` - Create and manage monitors
|
||||
- `oneuptime_monitor_group` - Organize monitors into groups
|
||||
- `oneuptime_probe` - Manage monitoring probes
|
||||
|
||||
### Incident Management
|
||||
- `oneuptime_incident` - Manage incidents
|
||||
- `oneuptime_alert_policy` - Configure alerting rules
|
||||
- `oneuptime_on_call_policy` - Set up on-call schedules
|
||||
- `oneuptime_escalation_policy` - Define escalation procedures
|
||||
|
||||
### Status Pages
|
||||
- `oneuptime_status_page` - Create status pages
|
||||
- `oneuptime_status_page_group` - Organize status page components
|
||||
- `oneuptime_announcement` - Manage announcements
|
||||
|
||||
### Service Catalog
|
||||
- `oneuptime_service` - Define services
|
||||
- `oneuptime_service_dependency` - Map service dependencies
|
||||
|
||||
### Data Sources
|
||||
- `oneuptime_project` - Fetch project information
|
||||
- `oneuptime_monitor` - Fetch monitor details
|
||||
- `oneuptime_team` - Fetch team information
|
||||
|
||||
## Examples
|
||||
|
||||
### Complete Monitoring Setup
|
||||
|
||||
```hcl
|
||||
# Variables
|
||||
variable "oneuptime_api_key" {
|
||||
description = "OneUptime API Key"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "oneuptime_api_url" {
|
||||
description = "OneUptime API URL"
|
||||
type = string
|
||||
default = "https://api.oneuptime.com"
|
||||
}
|
||||
|
||||
# Provider configuration
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = var.oneuptime_api_url
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
# Project
|
||||
resource "oneuptime_project" "production" {
|
||||
name = "Production Environment"
|
||||
description = "Production monitoring and alerting"
|
||||
}
|
||||
|
||||
# Team
|
||||
resource "oneuptime_team" "platform" {
|
||||
name = "Platform Team"
|
||||
project_id = oneuptime_project.production.id
|
||||
}
|
||||
|
||||
# Monitors
|
||||
resource "oneuptime_monitor" "api" {
|
||||
name = "API Health Check"
|
||||
project_id = oneuptime_project.production.id
|
||||
|
||||
monitor_type = "api"
|
||||
url = "https://api.mycompany.com/health"
|
||||
method = "GET"
|
||||
interval = "1m"
|
||||
timeout = "30s"
|
||||
|
||||
expected_status_codes = [200]
|
||||
|
||||
tags = {
|
||||
service = "api"
|
||||
environment = "production"
|
||||
criticality = "high"
|
||||
}
|
||||
}
|
||||
|
||||
resource "oneuptime_monitor" "database" {
|
||||
name = "Database Connection"
|
||||
project_id = oneuptime_project.production.id
|
||||
|
||||
monitor_type = "port"
|
||||
hostname = "db.mycompany.com"
|
||||
port = 5432
|
||||
interval = "2m"
|
||||
|
||||
tags = {
|
||||
service = "database"
|
||||
environment = "production"
|
||||
criticality = "critical"
|
||||
}
|
||||
}
|
||||
|
||||
# On-call policy
|
||||
resource "oneuptime_on_call_policy" "platform_oncall" {
|
||||
name = "Platform On-Call"
|
||||
project_id = oneuptime_project.production.id
|
||||
team_id = oneuptime_team.platform.id
|
||||
|
||||
schedules {
|
||||
name = "Business Hours"
|
||||
timezone = "America/New_York"
|
||||
|
||||
layers {
|
||||
name = "Primary"
|
||||
users = ["user1@mycompany.com", "user2@mycompany.com"]
|
||||
rotation_type = "weekly"
|
||||
start_time = "09:00"
|
||||
end_time = "17:00"
|
||||
days = ["monday", "tuesday", "wednesday", "thursday", "friday"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Alert policy
|
||||
resource "oneuptime_alert_policy" "critical_alerts" {
|
||||
name = "Critical System Alerts"
|
||||
project_id = oneuptime_project.production.id
|
||||
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.api.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.database.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
actions {
|
||||
type = "webhook"
|
||||
url = "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"
|
||||
}
|
||||
|
||||
actions {
|
||||
type = "oncall_escalation"
|
||||
oncall_policy_id = oneuptime_on_call_policy.platform_oncall.id
|
||||
}
|
||||
}
|
||||
|
||||
# Status page
|
||||
resource "oneuptime_status_page" "public" {
|
||||
name = "MyCompany Status"
|
||||
project_id = oneuptime_project.production.id
|
||||
|
||||
domain = "status.mycompany.com"
|
||||
|
||||
components {
|
||||
name = "API"
|
||||
monitor_id = oneuptime_monitor.api.id
|
||||
}
|
||||
|
||||
components {
|
||||
name = "Database"
|
||||
monitor_id = oneuptime_monitor.database.id
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Self-Hosted Configuration Example
|
||||
|
||||
```hcl
|
||||
# For self-hosted OneUptime instance version 7.0.123
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Must match your OneUptime version exactly
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://oneuptime.mycompany.com" # Your self-hosted URL
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
# Rest of your configuration...
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### 1. Version Management
|
||||
|
||||
**For Cloud Customers:**
|
||||
- Use semantic versioning with `~>` to get compatible updates
|
||||
- Review changelog before major version upgrades
|
||||
|
||||
**For Self-Hosted Customers:**
|
||||
- Always pin to exact version matching your installation
|
||||
- Update provider version when you upgrade OneUptime
|
||||
- Test in non-production environment first
|
||||
|
||||
### 2. State Management
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "my-terraform-state"
|
||||
key = "oneuptime/terraform.tfstate"
|
||||
region = "us-west-2"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Environment Separation
|
||||
|
||||
Use workspaces or separate state files for different environments:
|
||||
|
||||
```bash
|
||||
# Using workspaces
|
||||
terraform workspace new production
|
||||
terraform workspace new staging
|
||||
|
||||
# Using separate directories
|
||||
mkdir -p environments/{staging,production}
|
||||
```
|
||||
|
||||
### 4. Variable Management
|
||||
|
||||
```hcl
|
||||
# variables.tf
|
||||
variable "environment" {
|
||||
description = "Environment name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "monitors" {
|
||||
description = "List of monitors to create"
|
||||
type = list(object({
|
||||
name = string
|
||||
url = string
|
||||
type = string
|
||||
}))
|
||||
}
|
||||
|
||||
# terraform.tfvars
|
||||
environment = "production"
|
||||
monitors = [
|
||||
{
|
||||
name = "Website"
|
||||
url = "https://example.com"
|
||||
type = "website"
|
||||
},
|
||||
{
|
||||
name = "API"
|
||||
url = "https://api.example.com/health"
|
||||
type = "api"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### 5. Resource Naming
|
||||
|
||||
Use consistent naming conventions:
|
||||
|
||||
```hcl
|
||||
resource "oneuptime_monitor" "website_production" {
|
||||
name = "${var.environment}-website-monitor"
|
||||
# ...
|
||||
}
|
||||
|
||||
resource "oneuptime_alert_policy" "critical_production" {
|
||||
name = "${var.environment}-critical-alerts"
|
||||
# ...
|
||||
}
|
||||
```
|
||||
|
||||
## Migration Guide
|
||||
|
||||
### From Manual Configuration
|
||||
|
||||
1. **Audit existing resources** in OneUptime dashboard
|
||||
2. **Create Terraform configuration** for existing resources
|
||||
3. **Import existing resources** to Terraform state
|
||||
4. **Validate configuration** matches current state
|
||||
5. **Apply changes** incrementally
|
||||
|
||||
Example import:
|
||||
|
||||
```bash
|
||||
# Import existing monitor
|
||||
terraform import oneuptime_monitor.website monitor-id-here
|
||||
|
||||
# Import existing project
|
||||
terraform import oneuptime_project.main project-id-here
|
||||
```
|
||||
|
||||
### Version Upgrades
|
||||
|
||||
When upgrading OneUptime (self-hosted):
|
||||
|
||||
1. **Backup your current state**
|
||||
2. **Check provider compatibility**
|
||||
3. **Update provider version** in configuration
|
||||
4. **Test in staging environment**
|
||||
5. **Apply to production**
|
||||
|
||||
```bash
|
||||
# Backup state
|
||||
terraform state pull > backup.tfstate
|
||||
|
||||
# Update provider version
|
||||
# Edit terraform block in your configuration
|
||||
|
||||
# Plan and apply
|
||||
terraform init -upgrade
|
||||
terraform plan
|
||||
terraform apply
|
||||
```
|
||||
|
||||
## Support and Resources
|
||||
|
||||
- **Documentation**: [OneUptime Docs](https://docs.oneuptime.com)
|
||||
- **Terraform Registry**: [OneUptime Provider](https://registry.terraform.io/providers/oneuptime/oneuptime)
|
||||
- **GitHub Issues**: [OneUptime GitHub](https://github.com/OneUptime/oneuptime/issues)
|
||||
- **Community**: [OneUptime Community](https://community.oneuptime.com)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Version Mismatch (Self-Hosted)**
|
||||
```
|
||||
Error: API version incompatible
|
||||
```
|
||||
**Solution**: Ensure provider version matches OneUptime installation
|
||||
|
||||
2. **Authentication Issues**
|
||||
```
|
||||
Error: Invalid API key
|
||||
```
|
||||
**Solution**: Verify API key and permissions
|
||||
|
||||
3. **Resource Not Found**
|
||||
```
|
||||
Error: Resource not found
|
||||
```
|
||||
**Solution**: Check resource IDs and ensure resource exists
|
||||
|
||||
### Debug Mode
|
||||
|
||||
Enable detailed logging:
|
||||
|
||||
```bash
|
||||
export TF_LOG=DEBUG
|
||||
terraform apply
|
||||
```
|
||||
|
||||
### Version Check
|
||||
|
||||
Verify your setup:
|
||||
|
||||
```bash
|
||||
# Check Terraform version
|
||||
terraform version
|
||||
|
||||
# Check provider version
|
||||
terraform providers
|
||||
|
||||
# Validate configuration
|
||||
terraform validate
|
||||
```
|
||||
780
Docs/Content/terraform/examples.md
Normal file
780
Docs/Content/terraform/examples.md
Normal file
@@ -0,0 +1,780 @@
|
||||
# Terraform Provider Examples
|
||||
|
||||
This document provides comprehensive examples for common OneUptime Terraform configurations.
|
||||
|
||||
## Basic Examples
|
||||
|
||||
### Simple Website Monitor
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0" # Use "= 7.0.123" for self-hosted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://api.oneuptime.com" # Change for self-hosted
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
resource "oneuptime_project" "website" {
|
||||
name = "Website Monitoring"
|
||||
description = "Monitoring for company website"
|
||||
}
|
||||
|
||||
resource "oneuptime_monitor" "homepage" {
|
||||
name = "Homepage Monitor"
|
||||
project_id = oneuptime_project.website.id
|
||||
|
||||
monitor_type = "website"
|
||||
url = "https://example.com"
|
||||
interval = "5m"
|
||||
timeout = "30s"
|
||||
|
||||
expected_status_codes = [200]
|
||||
|
||||
tags = {
|
||||
service = "website"
|
||||
team = "frontend"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### API Health Check
|
||||
|
||||
```hcl
|
||||
resource "oneuptime_monitor" "api_health" {
|
||||
name = "API Health Check"
|
||||
project_id = oneuptime_project.website.id
|
||||
|
||||
monitor_type = "api"
|
||||
url = "https://api.example.com/health"
|
||||
method = "GET"
|
||||
interval = "2m"
|
||||
timeout = "15s"
|
||||
|
||||
headers = {
|
||||
"Authorization" = "Bearer ${var.api_token}"
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
|
||||
expected_status_codes = [200]
|
||||
expected_response_body = "healthy"
|
||||
|
||||
tags = {
|
||||
service = "api"
|
||||
environment = "production"
|
||||
criticality = "high"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Advanced Monitoring Setup
|
||||
|
||||
### Complete Infrastructure Monitoring
|
||||
|
||||
```hcl
|
||||
# Variables
|
||||
variable "environment" {
|
||||
description = "Environment name"
|
||||
type = string
|
||||
default = "production"
|
||||
}
|
||||
|
||||
variable "services" {
|
||||
description = "Services to monitor"
|
||||
type = map(object({
|
||||
url = string
|
||||
type = string
|
||||
interval = string
|
||||
criticality = string
|
||||
}))
|
||||
default = {
|
||||
frontend = {
|
||||
url = "https://app.example.com"
|
||||
type = "website"
|
||||
interval = "1m"
|
||||
criticality = "high"
|
||||
}
|
||||
api = {
|
||||
url = "https://api.example.com/health"
|
||||
type = "api"
|
||||
interval = "1m"
|
||||
criticality = "critical"
|
||||
}
|
||||
docs = {
|
||||
url = "https://docs.example.com"
|
||||
type = "website"
|
||||
interval = "5m"
|
||||
criticality = "medium"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Project
|
||||
resource "oneuptime_project" "infrastructure" {
|
||||
name = "${title(var.environment)} Infrastructure"
|
||||
description = "Infrastructure monitoring for ${var.environment}"
|
||||
}
|
||||
|
||||
# Teams
|
||||
resource "oneuptime_team" "sre" {
|
||||
name = "SRE Team"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
}
|
||||
|
||||
resource "oneuptime_team" "development" {
|
||||
name = "Development Team"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
}
|
||||
|
||||
# Monitors for each service
|
||||
resource "oneuptime_monitor" "services" {
|
||||
for_each = var.services
|
||||
|
||||
name = "${var.environment}-${each.key}"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
monitor_type = each.value.type
|
||||
url = each.value.url
|
||||
interval = each.value.interval
|
||||
timeout = "30s"
|
||||
|
||||
expected_status_codes = [200]
|
||||
|
||||
tags = {
|
||||
service = each.key
|
||||
environment = var.environment
|
||||
criticality = each.value.criticality
|
||||
managed_by = "terraform"
|
||||
}
|
||||
}
|
||||
|
||||
# Database monitors
|
||||
resource "oneuptime_monitor" "database_primary" {
|
||||
name = "${var.environment}-database-primary"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
monitor_type = "port"
|
||||
hostname = "db-primary.internal"
|
||||
port = 5432
|
||||
interval = "2m"
|
||||
timeout = "10s"
|
||||
|
||||
tags = {
|
||||
service = "database"
|
||||
role = "primary"
|
||||
environment = var.environment
|
||||
criticality = "critical"
|
||||
}
|
||||
}
|
||||
|
||||
resource "oneuptime_monitor" "database_replica" {
|
||||
name = "${var.environment}-database-replica"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
monitor_type = "port"
|
||||
hostname = "db-replica.internal"
|
||||
port = 5432
|
||||
interval = "5m"
|
||||
timeout = "10s"
|
||||
|
||||
tags = {
|
||||
service = "database"
|
||||
role = "replica"
|
||||
environment = var.environment
|
||||
criticality = "medium"
|
||||
}
|
||||
}
|
||||
|
||||
# Redis monitor
|
||||
resource "oneuptime_monitor" "redis" {
|
||||
name = "${var.environment}-redis"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
monitor_type = "port"
|
||||
hostname = "redis.internal"
|
||||
port = 6379
|
||||
interval = "3m"
|
||||
timeout = "10s"
|
||||
|
||||
tags = {
|
||||
service = "cache"
|
||||
environment = var.environment
|
||||
criticality = "high"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### On-Call and Alerting
|
||||
|
||||
```hcl
|
||||
# On-call schedules
|
||||
resource "oneuptime_on_call_policy" "sre_oncall" {
|
||||
name = "SRE On-Call"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
team_id = oneuptime_team.sre.id
|
||||
|
||||
schedules {
|
||||
name = "Business Hours"
|
||||
timezone = "America/New_York"
|
||||
|
||||
layers {
|
||||
name = "Primary SRE"
|
||||
users = ["sre1@example.com", "sre2@example.com"]
|
||||
rotation_type = "weekly"
|
||||
start_time = "09:00"
|
||||
end_time = "17:00"
|
||||
days = ["monday", "tuesday", "wednesday", "thursday", "friday"]
|
||||
}
|
||||
|
||||
layers {
|
||||
name = "Secondary SRE"
|
||||
users = ["sre3@example.com", "sre4@example.com"]
|
||||
rotation_type = "weekly"
|
||||
start_time = "09:00"
|
||||
end_time = "17:00"
|
||||
days = ["monday", "tuesday", "wednesday", "thursday", "friday"]
|
||||
}
|
||||
}
|
||||
|
||||
schedules {
|
||||
name = "After Hours"
|
||||
timezone = "America/New_York"
|
||||
|
||||
layers {
|
||||
name = "After Hours Primary"
|
||||
users = ["sre1@example.com", "sre2@example.com", "sre3@example.com"]
|
||||
rotation_type = "weekly"
|
||||
start_time = "17:00"
|
||||
end_time = "09:00"
|
||||
days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Alert policies
|
||||
resource "oneuptime_alert_policy" "critical_services" {
|
||||
name = "Critical Service Alerts"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
# Critical service conditions
|
||||
dynamic "conditions" {
|
||||
for_each = {
|
||||
for k, v in var.services : k => v
|
||||
if v.criticality == "critical"
|
||||
}
|
||||
|
||||
content {
|
||||
monitor_id = oneuptime_monitor.services[conditions.key].id
|
||||
threshold = "down"
|
||||
}
|
||||
}
|
||||
|
||||
# Database conditions
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.database_primary.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
# Immediate Slack notification
|
||||
actions {
|
||||
type = "webhook"
|
||||
url = var.slack_webhook_url
|
||||
headers = {
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
payload = jsonencode({
|
||||
text = "🚨 CRITICAL ALERT: {{monitor_name}} is DOWN"
|
||||
channel = "#alerts-critical"
|
||||
})
|
||||
}
|
||||
|
||||
# Page SRE team
|
||||
actions {
|
||||
type = "oncall_escalation"
|
||||
oncall_policy_id = oneuptime_on_call_policy.sre_oncall.id
|
||||
escalation_delay = "0m"
|
||||
}
|
||||
|
||||
# Email backup
|
||||
actions {
|
||||
type = "email"
|
||||
recipients = ["sre-team@example.com"]
|
||||
delay = "2m"
|
||||
}
|
||||
}
|
||||
|
||||
resource "oneuptime_alert_policy" "high_priority" {
|
||||
name = "High Priority Alerts"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
# High priority service conditions
|
||||
dynamic "conditions" {
|
||||
for_each = {
|
||||
for k, v in var.services : k => v
|
||||
if v.criticality == "high"
|
||||
}
|
||||
|
||||
content {
|
||||
monitor_id = oneuptime_monitor.services[conditions.key].id
|
||||
threshold = "down"
|
||||
}
|
||||
}
|
||||
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.redis.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
# Slack notification
|
||||
actions {
|
||||
type = "webhook"
|
||||
url = var.slack_webhook_url
|
||||
payload = jsonencode({
|
||||
text = "⚠️ HIGH PRIORITY: {{monitor_name}} is DOWN"
|
||||
channel = "#alerts-high"
|
||||
})
|
||||
}
|
||||
|
||||
# Escalate to on-call after 5 minutes
|
||||
actions {
|
||||
type = "oncall_escalation"
|
||||
oncall_policy_id = oneuptime_on_call_policy.sre_oncall.id
|
||||
escalation_delay = "5m"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Status Pages
|
||||
|
||||
```hcl
|
||||
# Public status page
|
||||
resource "oneuptime_status_page" "public" {
|
||||
name = "Example.com Status"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
domain = "status.example.com"
|
||||
is_public = true
|
||||
|
||||
# Branding
|
||||
title = "Example.com Service Status"
|
||||
description = "Current status of Example.com services"
|
||||
logo_url = "https://example.com/logo.png"
|
||||
favicon_url = "https://example.com/favicon.ico"
|
||||
|
||||
# Theme
|
||||
primary_color = "#1f2937"
|
||||
secondary_color = "#6b7280"
|
||||
|
||||
# Components from monitors
|
||||
components {
|
||||
name = "Website"
|
||||
description = "Main website and application"
|
||||
monitor_id = oneuptime_monitor.services["frontend"].id
|
||||
order = 1
|
||||
}
|
||||
|
||||
components {
|
||||
name = "API"
|
||||
description = "REST API services"
|
||||
monitor_id = oneuptime_monitor.services["api"].id
|
||||
order = 2
|
||||
}
|
||||
|
||||
components {
|
||||
name = "Database"
|
||||
description = "Primary database cluster"
|
||||
monitor_id = oneuptime_monitor.database_primary.id
|
||||
order = 3
|
||||
}
|
||||
|
||||
# Component groups
|
||||
component_groups {
|
||||
name = "Core Services"
|
||||
description = "Essential services for application functionality"
|
||||
components = [
|
||||
oneuptime_monitor.services["frontend"].id,
|
||||
oneuptime_monitor.services["api"].id,
|
||||
oneuptime_monitor.database_primary.id
|
||||
]
|
||||
order = 1
|
||||
}
|
||||
|
||||
component_groups {
|
||||
name = "Support Services"
|
||||
description = "Additional services and infrastructure"
|
||||
components = [
|
||||
oneuptime_monitor.redis.id,
|
||||
oneuptime_monitor.database_replica.id
|
||||
]
|
||||
order = 2
|
||||
}
|
||||
}
|
||||
|
||||
# Internal status page
|
||||
resource "oneuptime_status_page" "internal" {
|
||||
name = "Internal Services Status"
|
||||
project_id = oneuptime_project.infrastructure.id
|
||||
|
||||
domain = "status.internal.example.com"
|
||||
is_public = false
|
||||
|
||||
# All services for internal view
|
||||
dynamic "components" {
|
||||
for_each = oneuptime_monitor.services
|
||||
|
||||
content {
|
||||
name = title(components.key)
|
||||
monitor_id = components.value.id
|
||||
order = index(keys(oneuptime_monitor.services), components.key) + 1
|
||||
}
|
||||
}
|
||||
|
||||
components {
|
||||
name = "Primary Database"
|
||||
monitor_id = oneuptime_monitor.database_primary.id
|
||||
order = 10
|
||||
}
|
||||
|
||||
components {
|
||||
name = "Replica Database"
|
||||
monitor_id = oneuptime_monitor.database_replica.id
|
||||
order = 11
|
||||
}
|
||||
|
||||
components {
|
||||
name = "Redis Cache"
|
||||
monitor_id = oneuptime_monitor.redis.id
|
||||
order = 12
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Multi-Environment Example
|
||||
|
||||
### Environment Module
|
||||
|
||||
```hcl
|
||||
# modules/environment/main.tf
|
||||
variable "environment" {
|
||||
description = "Environment name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "oneuptime_project_id" {
|
||||
description = "OneUptime project ID"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "domain" {
|
||||
description = "Domain for this environment"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "api_domain" {
|
||||
description = "API domain for this environment"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "team_emails" {
|
||||
description = "Team member emails for notifications"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
# Environment-specific monitors
|
||||
resource "oneuptime_monitor" "app" {
|
||||
name = "${var.environment}-application"
|
||||
project_id = var.oneuptime_project_id
|
||||
|
||||
monitor_type = "website"
|
||||
url = "https://${var.domain}"
|
||||
interval = var.environment == "production" ? "1m" : "5m"
|
||||
timeout = "30s"
|
||||
|
||||
expected_status_codes = [200]
|
||||
|
||||
tags = {
|
||||
environment = var.environment
|
||||
service = "application"
|
||||
criticality = var.environment == "production" ? "critical" : "medium"
|
||||
}
|
||||
}
|
||||
|
||||
resource "oneuptime_monitor" "api" {
|
||||
name = "${var.environment}-api"
|
||||
project_id = var.oneuptime_project_id
|
||||
|
||||
monitor_type = "api"
|
||||
url = "https://${var.api_domain}/health"
|
||||
method = "GET"
|
||||
interval = var.environment == "production" ? "1m" : "3m"
|
||||
timeout = "15s"
|
||||
|
||||
expected_status_codes = [200]
|
||||
|
||||
tags = {
|
||||
environment = var.environment
|
||||
service = "api"
|
||||
criticality = var.environment == "production" ? "critical" : "medium"
|
||||
}
|
||||
}
|
||||
|
||||
# Environment-specific alerting
|
||||
resource "oneuptime_alert_policy" "environment_alerts" {
|
||||
name = "${title(var.environment)} Environment Alerts"
|
||||
project_id = var.oneuptime_project_id
|
||||
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.app.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.api.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
# Production gets immediate alerts, others are delayed
|
||||
actions {
|
||||
type = "email"
|
||||
recipients = var.team_emails
|
||||
delay = var.environment == "production" ? "0m" : "5m"
|
||||
}
|
||||
|
||||
# Only production gets Slack alerts
|
||||
dynamic "actions" {
|
||||
for_each = var.environment == "production" ? [1] : []
|
||||
|
||||
content {
|
||||
type = "webhook"
|
||||
url = var.slack_webhook_url
|
||||
payload = jsonencode({
|
||||
text = "🚨 PRODUCTION ALERT: {{monitor_name}} is DOWN"
|
||||
channel = "#alerts-production"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Outputs
|
||||
output "app_monitor_id" {
|
||||
value = oneuptime_monitor.app.id
|
||||
}
|
||||
|
||||
output "api_monitor_id" {
|
||||
value = oneuptime_monitor.api.id
|
||||
}
|
||||
```
|
||||
|
||||
### Using the Environment Module
|
||||
|
||||
```hcl
|
||||
# main.tf
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = var.oneuptime_api_url
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
# Main project
|
||||
resource "oneuptime_project" "company" {
|
||||
name = "Company Infrastructure"
|
||||
description = "Multi-environment infrastructure monitoring"
|
||||
}
|
||||
|
||||
# Development environment
|
||||
module "development" {
|
||||
source = "./modules/environment"
|
||||
|
||||
environment = "development"
|
||||
oneuptime_project_id = oneuptime_project.company.id
|
||||
domain = "dev.example.com"
|
||||
api_domain = "api-dev.example.com"
|
||||
team_emails = ["dev-team@example.com"]
|
||||
}
|
||||
|
||||
# Staging environment
|
||||
module "staging" {
|
||||
source = "./modules/environment"
|
||||
|
||||
environment = "staging"
|
||||
oneuptime_project_id = oneuptime_project.company.id
|
||||
domain = "staging.example.com"
|
||||
api_domain = "api-staging.example.com"
|
||||
team_emails = ["qa-team@example.com", "dev-team@example.com"]
|
||||
}
|
||||
|
||||
# Production environment
|
||||
module "production" {
|
||||
source = "./modules/environment"
|
||||
|
||||
environment = "production"
|
||||
oneuptime_project_id = oneuptime_project.company.id
|
||||
domain = "example.com"
|
||||
api_domain = "api.example.com"
|
||||
team_emails = ["sre-team@example.com", "dev-team@example.com"]
|
||||
}
|
||||
|
||||
# Cross-environment status page
|
||||
resource "oneuptime_status_page" "all_environments" {
|
||||
name = "All Environments Status"
|
||||
project_id = oneuptime_project.company.id
|
||||
|
||||
domain = "status-internal.example.com"
|
||||
|
||||
component_groups {
|
||||
name = "Production"
|
||||
components = [
|
||||
module.production.app_monitor_id,
|
||||
module.production.api_monitor_id
|
||||
]
|
||||
order = 1
|
||||
}
|
||||
|
||||
component_groups {
|
||||
name = "Staging"
|
||||
components = [
|
||||
module.staging.app_monitor_id,
|
||||
module.staging.api_monitor_id
|
||||
]
|
||||
order = 2
|
||||
}
|
||||
|
||||
component_groups {
|
||||
name = "Development"
|
||||
components = [
|
||||
module.development.app_monitor_id,
|
||||
module.development.api_monitor_id
|
||||
]
|
||||
order = 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Service Catalog Example
|
||||
|
||||
```hcl
|
||||
# Service catalog with dependencies
|
||||
resource "oneuptime_service" "frontend" {
|
||||
name = "Frontend Application"
|
||||
project_id = oneuptime_project.company.id
|
||||
description = "Customer-facing web application"
|
||||
|
||||
service_level = "customer_facing"
|
||||
criticality = "high"
|
||||
|
||||
team_id = oneuptime_team.frontend.id
|
||||
|
||||
monitors = [
|
||||
oneuptime_monitor.services["frontend"].id
|
||||
]
|
||||
|
||||
tags = {
|
||||
language = "typescript"
|
||||
framework = "react"
|
||||
repository = "github.com/example/frontend"
|
||||
}
|
||||
}
|
||||
|
||||
resource "oneuptime_service" "api" {
|
||||
name = "Backend API"
|
||||
project_id = oneuptime_project.company.id
|
||||
description = "REST API backend service"
|
||||
|
||||
service_level = "internal"
|
||||
criticality = "critical"
|
||||
|
||||
team_id = oneuptime_team.backend.id
|
||||
|
||||
monitors = [
|
||||
oneuptime_monitor.services["api"].id
|
||||
]
|
||||
|
||||
tags = {
|
||||
language = "nodejs"
|
||||
framework = "express"
|
||||
repository = "github.com/example/api"
|
||||
}
|
||||
}
|
||||
|
||||
resource "oneuptime_service" "database" {
|
||||
name = "PostgreSQL Database"
|
||||
project_id = oneuptime_project.company.id
|
||||
description = "Primary application database"
|
||||
|
||||
service_level = "infrastructure"
|
||||
criticality = "critical"
|
||||
|
||||
team_id = oneuptime_team.sre.id
|
||||
|
||||
monitors = [
|
||||
oneuptime_monitor.database_primary.id,
|
||||
oneuptime_monitor.database_replica.id
|
||||
]
|
||||
|
||||
tags = {
|
||||
type = "database"
|
||||
engine = "postgresql"
|
||||
version = "14"
|
||||
}
|
||||
}
|
||||
|
||||
# Service dependencies
|
||||
resource "oneuptime_service_dependency" "frontend_api" {
|
||||
service_id = oneuptime_service.frontend.id
|
||||
depends_on_service_id = oneuptime_service.api.id
|
||||
dependency_type = "hard"
|
||||
}
|
||||
|
||||
resource "oneuptime_service_dependency" "api_database" {
|
||||
service_id = oneuptime_service.api.id
|
||||
depends_on_service_id = oneuptime_service.database.id
|
||||
dependency_type = "hard"
|
||||
}
|
||||
```
|
||||
|
||||
## Data Sources Example
|
||||
|
||||
```hcl
|
||||
# Use existing project
|
||||
data "oneuptime_project" "existing" {
|
||||
name = "Legacy Project"
|
||||
}
|
||||
|
||||
# Use existing monitor
|
||||
data "oneuptime_monitor" "legacy_api" {
|
||||
name = "Legacy API Monitor"
|
||||
project_id = data.oneuptime_project.existing.id
|
||||
}
|
||||
|
||||
# Create new alert policy using existing monitor
|
||||
resource "oneuptime_alert_policy" "legacy_migration" {
|
||||
name = "Legacy System Migration Alerts"
|
||||
project_id = oneuptime_project.company.id
|
||||
|
||||
conditions {
|
||||
monitor_id = data.oneuptime_monitor.legacy_api.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
actions {
|
||||
type = "email"
|
||||
recipients = ["migration-team@example.com"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
These examples demonstrate various patterns and use cases for the OneUptime Terraform provider, from simple monitoring setups to complex multi-environment configurations with service catalogs and dependencies.
|
||||
90
Docs/Content/terraform/index.md
Normal file
90
Docs/Content/terraform/index.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# Terraform Provider Documentation
|
||||
|
||||
The OneUptime Terraform Provider enables Infrastructure as Code (IaC) management of your OneUptime monitoring, alerting, and observability resources.
|
||||
|
||||
## 📚 Documentation Sections
|
||||
|
||||
### [Getting Started](./quick-start.md)
|
||||
Quick setup guide to get you started with the OneUptime Terraform Provider in minutes.
|
||||
|
||||
### [Complete Provider Guide](./README.md)
|
||||
Comprehensive documentation covering installation, configuration, resources, and best practices.
|
||||
|
||||
### [Self-Hosted Configuration](./self-hosted.md)
|
||||
**Critical for self-hosted customers**: Version pinning, compatibility, and deployment strategies.
|
||||
|
||||
### [Examples](./examples.md)
|
||||
Real-world examples and patterns for common OneUptime Terraform configurations.
|
||||
|
||||
## 🚀 Quick Links
|
||||
|
||||
### For OneUptime Cloud Customers
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://api.oneuptime.com"
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
### For Self-Hosted Customers
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Must match your OneUptime version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://oneuptime.yourcompany.com"
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
## ⚠️ Important for Self-Hosted Users
|
||||
|
||||
**Version Compatibility is Critical**: Always pin the Terraform provider version to exactly match your OneUptime installation version. Mismatched versions can cause API compatibility issues.
|
||||
|
||||
## 🔗 External Resources
|
||||
|
||||
- **Terraform Registry**: [OneUptime Provider](https://registry.terraform.io/providers/oneuptime/oneuptime)
|
||||
- **GitHub Repository**: [OneUptime Source Code](https://github.com/OneUptime/oneuptime)
|
||||
- **Community Support**: [OneUptime Community](https://community.oneuptime.com)
|
||||
|
||||
## 📋 Available Resources
|
||||
|
||||
The provider supports comprehensive OneUptime resource management:
|
||||
|
||||
- **Projects & Teams**: Organize your monitoring structure
|
||||
- **Monitors**: Website, API, port, heartbeat, and custom monitors
|
||||
- **Incident Management**: Alert policies, on-call schedules, escalations
|
||||
- **Status Pages**: Public and private status pages with custom branding
|
||||
- **Service Catalog**: Service definitions and dependency mapping
|
||||
- **Workflows**: Automated response and remediation workflows
|
||||
|
||||
## 🛠️ Support
|
||||
|
||||
For issues, questions, or contributions:
|
||||
|
||||
1. **Documentation Issues**: Create an issue in the [OneUptime repository](https://github.com/OneUptime/oneuptime/issues)
|
||||
2. **Provider Bugs**: Report in the main OneUptime repository
|
||||
3. **Feature Requests**: Discuss in the OneUptime community
|
||||
4. **General Questions**: Use the community forums
|
||||
|
||||
## 🎯 Next Steps
|
||||
|
||||
1. **New Users**: Start with the [Quick Start Guide](./quick-start.md)
|
||||
2. **Self-Hosted**: Review the [Self-Hosted Configuration](./self-hosted.md)
|
||||
3. **Advanced Users**: Explore [Examples](./examples.md) for complex setups
|
||||
4. **Full Reference**: Check the [Complete Guide](./README.md) for all features
|
||||
205
Docs/Content/terraform/quick-start.md
Normal file
205
Docs/Content/terraform/quick-start.md
Normal file
@@ -0,0 +1,205 @@
|
||||
# Terraform Provider Quick Start Guide
|
||||
|
||||
This guide will help you get started with the OneUptime Terraform Provider in just a few minutes.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Terraform >= 1.0 installed
|
||||
- OneUptime account (Cloud or Self-Hosted)
|
||||
- OneUptime API key
|
||||
|
||||
## Step 1: Create API Key
|
||||
|
||||
### For OneUptime Cloud
|
||||
1. Go to [OneUptime Cloud](https://oneuptime.com) and log in
|
||||
2. Navigate to **Settings** → **API Keys**
|
||||
3. Click **Create API Key**
|
||||
4. Name it "Terraform Provider"
|
||||
5. Select required permissions
|
||||
6. Copy the generated API key
|
||||
|
||||
### For Self-Hosted OneUptime
|
||||
1. Access your OneUptime instance
|
||||
2. Navigate to **Settings** → **API Keys**
|
||||
3. Click **Create API Key**
|
||||
4. Name it "Terraform Provider"
|
||||
5. Select required permissions
|
||||
6. Copy the generated API key
|
||||
|
||||
## Step 2: Create Terraform Configuration
|
||||
|
||||
Create a new directory and `main.tf` file:
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
# For Cloud customers
|
||||
version = "~> 7.0"
|
||||
|
||||
# For Self-Hosted customers - pin to your exact version
|
||||
# version = "= 7.0.123" # Replace with your OneUptime version
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
# For Cloud customers
|
||||
api_url = "https://api.oneuptime.com"
|
||||
|
||||
# For Self-Hosted customers - use your instance URL
|
||||
# api_url = "https://oneuptime.yourcompany.com"
|
||||
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
variable "oneuptime_api_key" {
|
||||
description = "OneUptime API Key"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
# Create a project
|
||||
resource "oneuptime_project" "demo" {
|
||||
name = "Demo Project"
|
||||
description = "Created with Terraform"
|
||||
}
|
||||
|
||||
# Create a simple website monitor
|
||||
resource "oneuptime_monitor" "website" {
|
||||
name = "Website Monitor"
|
||||
project_id = oneuptime_project.demo.id
|
||||
|
||||
monitor_type = "website"
|
||||
url = "https://google.com"
|
||||
interval = "5m"
|
||||
timeout = "30s"
|
||||
|
||||
tags = {
|
||||
created_by = "terraform"
|
||||
environment = "demo"
|
||||
}
|
||||
}
|
||||
|
||||
# Output the monitor ID
|
||||
output "monitor_id" {
|
||||
value = oneuptime_monitor.website.id
|
||||
}
|
||||
|
||||
output "project_id" {
|
||||
value = oneuptime_project.demo.id
|
||||
}
|
||||
```
|
||||
|
||||
## Step 3: Create Variables File
|
||||
|
||||
Create `terraform.tfvars`:
|
||||
|
||||
```hcl
|
||||
# terraform.tfvars
|
||||
oneuptime_api_key = "your-api-key-here"
|
||||
```
|
||||
|
||||
**Important**: Add `terraform.tfvars` to your `.gitignore` to keep API keys secret!
|
||||
|
||||
## Step 4: Initialize and Apply
|
||||
|
||||
```bash
|
||||
# Initialize Terraform
|
||||
terraform init
|
||||
|
||||
# Plan the deployment
|
||||
terraform plan
|
||||
|
||||
# Apply the configuration
|
||||
terraform apply
|
||||
```
|
||||
|
||||
## Step 5: Verify Resources
|
||||
|
||||
1. Check your OneUptime dashboard
|
||||
2. Look for the new "Demo Project"
|
||||
3. Verify the "Website Monitor" is created and running
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Explore More Resources**: Check the [full documentation](./README.md) for all available resources
|
||||
2. **Set Up Alerting**: Add alert policies and notification channels
|
||||
3. **Create Status Pages**: Set up public status pages for your services
|
||||
4. **Organize with Teams**: Create teams and assign permissions
|
||||
|
||||
## Version-Specific Examples
|
||||
|
||||
### Cloud Customers (Latest Version)
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0" # Always gets latest compatible 7.x version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://api.oneuptime.com"
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
### Self-Hosted Customers (Version Pinned)
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Must match your OneUptime version exactly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://oneuptime.mycompany.com" # Your self-hosted URL
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting Quick Start
|
||||
|
||||
### Issue: Provider not found
|
||||
```
|
||||
Error: Failed to query available provider packages
|
||||
```
|
||||
**Solution**: Run `terraform init` to download the provider
|
||||
|
||||
### Issue: Authentication failed
|
||||
```
|
||||
Error: Invalid API key
|
||||
```
|
||||
**Solution**:
|
||||
1. Verify your API key in OneUptime dashboard
|
||||
2. Check the API key has sufficient permissions
|
||||
3. Ensure `api_url` is correct for your instance
|
||||
|
||||
### Issue: Version mismatch (Self-Hosted)
|
||||
```
|
||||
Error: API version incompatible
|
||||
```
|
||||
**Solution**:
|
||||
1. Check your OneUptime version in the dashboard
|
||||
2. Update the provider version to match exactly
|
||||
3. Run `terraform init -upgrade`
|
||||
|
||||
## Clean Up
|
||||
|
||||
To remove all resources created in this quick start:
|
||||
|
||||
```bash
|
||||
terraform destroy
|
||||
```
|
||||
|
||||
This will delete the monitor and project created during the quick start.
|
||||
151
Docs/Content/terraform/registry.md
Normal file
151
Docs/Content/terraform/registry.md
Normal file
@@ -0,0 +1,151 @@
|
||||
# Terraform Provider Installation and Usage Guide
|
||||
|
||||
## Installation from Terraform Registry
|
||||
|
||||
The OneUptime Terraform Provider is available on the official [Terraform Registry](https://registry.terraform.io/providers/oneuptime/oneuptime).
|
||||
|
||||
### For OneUptime Cloud Users
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0" # Use latest compatible version
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://api.oneuptime.com"
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
### For Self-Hosted OneUptime Users
|
||||
|
||||
⚠️ **Critical**: Self-hosted customers must pin the provider version to match their OneUptime installation exactly.
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Replace with your exact OneUptime version
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://oneuptime.yourcompany.com" # Your self-hosted URL
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
## Why Version Pinning for Self-Hosted?
|
||||
|
||||
The OneUptime Terraform provider is automatically generated from the OneUptime API specification. Each OneUptime version may have:
|
||||
|
||||
- Different API endpoints
|
||||
- Updated resource schemas
|
||||
- New or removed features
|
||||
- Changed validation rules
|
||||
|
||||
Using a provider version that doesn't match your OneUptime installation can result in:
|
||||
- API compatibility errors
|
||||
- Failed resource creation/updates
|
||||
- Unexpected behavior
|
||||
- Resource state drift
|
||||
|
||||
## Finding Your OneUptime Version
|
||||
|
||||
### Method 1: Dashboard
|
||||
1. Log into your OneUptime dashboard
|
||||
2. Go to **Settings** → **About**
|
||||
3. Note the version number (e.g., "7.0.123")
|
||||
|
||||
### Method 2: API
|
||||
```bash
|
||||
curl https://your-oneuptime-instance.com/api/status | jq '.version'
|
||||
```
|
||||
|
||||
### Method 3: Docker
|
||||
```bash
|
||||
docker images | grep oneuptime
|
||||
# Look for the tag, e.g., oneuptime/dashboard:7.0.123
|
||||
```
|
||||
|
||||
## Provider Registry Information
|
||||
|
||||
- **Registry URL**: https://registry.terraform.io/providers/oneuptime/oneuptime
|
||||
- **Source Repository**: https://github.com/OneUptime/terraform-provider-oneuptime
|
||||
- **Documentation**: https://registry.terraform.io/providers/oneuptime/oneuptime/latest/docs
|
||||
- **Releases**: https://github.com/OneUptime/terraform-provider-oneuptime/releases
|
||||
|
||||
## Version Compatibility Matrix
|
||||
|
||||
| OneUptime Version | Provider Version | Terraform Config |
|
||||
|-------------------|------------------|------------------|
|
||||
| 7.0.x | 7.0.x | `version = "~> 7.0.0"` |
|
||||
| 7.1.x | 7.1.x | `version = "~> 7.1.0"` |
|
||||
| Latest Cloud | Latest Provider | `version = "~> 7.0"` |
|
||||
|
||||
## Quick Start Example
|
||||
|
||||
```hcl
|
||||
# Configure the provider
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> 7.0" # Adjust for self-hosted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://api.oneuptime.com" # Adjust for self-hosted
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
# Create a project
|
||||
resource "oneuptime_project" "example" {
|
||||
name = "Terraform Example"
|
||||
description = "Created with Terraform"
|
||||
}
|
||||
|
||||
# Create a website monitor
|
||||
resource "oneuptime_monitor" "website" {
|
||||
name = "Website Monitor"
|
||||
project_id = oneuptime_project.example.id
|
||||
|
||||
monitor_type = "website"
|
||||
url = "https://example.com"
|
||||
interval = "5m"
|
||||
|
||||
tags = {
|
||||
managed_by = "terraform"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Installation Steps
|
||||
|
||||
1. **Create your Terraform configuration** with the provider block
|
||||
2. **Initialize Terraform**: `terraform init`
|
||||
3. **Set your API key**: Create `terraform.tfvars` with your API key
|
||||
4. **Plan your deployment**: `terraform plan`
|
||||
5. **Apply your configuration**: `terraform apply`
|
||||
|
||||
## Getting Help
|
||||
|
||||
- **Full Documentation**: See the [complete Terraform documentation](./README.md)
|
||||
- **Self-Hosted Guide**: Check the [self-hosted configuration guide](./self-hosted.md)
|
||||
- **Examples**: Browse [configuration examples](./examples.md)
|
||||
- **Quick Start**: Follow the [quick start guide](./quick-start.md)
|
||||
|
||||
## Registry Updates
|
||||
|
||||
The provider is automatically published to the Terraform Registry when new OneUptime versions are released. Cloud users can use semantic versioning (`~> 7.0`) to automatically get compatible updates, while self-hosted users should pin to exact versions.
|
||||
503
Docs/Content/terraform/self-hosted.md
Normal file
503
Docs/Content/terraform/self-hosted.md
Normal file
@@ -0,0 +1,503 @@
|
||||
# Self-Hosted OneUptime Terraform Configuration Guide
|
||||
|
||||
This guide is specifically for customers running self-hosted OneUptime instances. It covers version management, configuration, and best practices for using the Terraform provider with your own OneUptime deployment.
|
||||
|
||||
## Critical: Version Compatibility
|
||||
|
||||
⚠️ **The most important rule for self-hosted customers**: Always pin your Terraform provider version to match your OneUptime installation version exactly.
|
||||
|
||||
### Why Version Pinning is Critical
|
||||
|
||||
- The Terraform provider is auto-generated from the OneUptime API
|
||||
- Each OneUptime version may have different API endpoints and schemas
|
||||
- Using a mismatched provider version can cause errors or unexpected behavior
|
||||
- Version pinning ensures compatibility and predictable behavior
|
||||
|
||||
## Finding Your OneUptime Version
|
||||
|
||||
### Method 1: Dashboard
|
||||
1. Log into your OneUptime dashboard
|
||||
2. Go to **Settings** → **About**
|
||||
3. Look for the version number (e.g., "7.0.123")
|
||||
|
||||
### Method 2: API Endpoint
|
||||
```bash
|
||||
curl https://your-oneuptime-instance.com/api/status
|
||||
```
|
||||
|
||||
### Method 3: Docker Images
|
||||
If you're running OneUptime with Docker:
|
||||
```bash
|
||||
docker images | grep oneuptime
|
||||
# Look for the tag, e.g., oneuptime/dashboard:7.0.123
|
||||
```
|
||||
|
||||
### Method 4: Helm Chart
|
||||
If you're using Helm:
|
||||
```bash
|
||||
helm list -n oneuptime
|
||||
# Check the chart version
|
||||
```
|
||||
|
||||
### Method 5: Environment Variables
|
||||
Check your configuration files for version variables:
|
||||
```bash
|
||||
grep -r "APP_VERSION\|IMAGE_TAG" /path/to/your/oneuptime/config
|
||||
```
|
||||
|
||||
## Provider Configuration Templates
|
||||
|
||||
### Template for Version 7.0.x
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Replace 123 with your exact build number
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://oneuptime.yourcompany.com" # Your self-hosted URL
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
### Template for Version 7.1.x
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.1.45" # Replace with your exact version
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
}
|
||||
|
||||
provider "oneuptime" {
|
||||
api_url = "https://oneuptime.yourcompany.com"
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
## Complete Self-Hosted Configuration Example
|
||||
|
||||
Here's a complete example for a self-hosted OneUptime instance:
|
||||
|
||||
```hcl
|
||||
# versions.tf
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.123" # Must match your OneUptime version
|
||||
}
|
||||
}
|
||||
required_version = ">= 1.0"
|
||||
|
||||
# Optional: Use remote state for team collaboration
|
||||
backend "s3" {
|
||||
bucket = "your-terraform-state-bucket"
|
||||
key = "oneuptime/terraform.tfstate"
|
||||
region = "us-west-2"
|
||||
}
|
||||
}
|
||||
|
||||
# variables.tf
|
||||
variable "oneuptime_api_url" {
|
||||
description = "OneUptime instance URL"
|
||||
type = string
|
||||
default = "https://oneuptime.yourcompany.com"
|
||||
}
|
||||
|
||||
variable "oneuptime_api_key" {
|
||||
description = "OneUptime API Key"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Environment name"
|
||||
type = string
|
||||
default = "production"
|
||||
}
|
||||
|
||||
# providers.tf
|
||||
provider "oneuptime" {
|
||||
api_url = var.oneuptime_api_url
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
|
||||
# main.tf
|
||||
# Create project for this environment
|
||||
resource "oneuptime_project" "main" {
|
||||
name = "${var.environment} Environment"
|
||||
description = "Managed by Terraform for ${var.environment}"
|
||||
}
|
||||
|
||||
# Create teams
|
||||
resource "oneuptime_team" "infrastructure" {
|
||||
name = "Infrastructure Team"
|
||||
project_id = oneuptime_project.main.id
|
||||
}
|
||||
|
||||
resource "oneuptime_team" "development" {
|
||||
name = "Development Team"
|
||||
project_id = oneuptime_project.main.id
|
||||
}
|
||||
|
||||
# Infrastructure monitors
|
||||
resource "oneuptime_monitor" "database" {
|
||||
name = "${var.environment}-database"
|
||||
project_id = oneuptime_project.main.id
|
||||
|
||||
monitor_type = "port"
|
||||
hostname = "db.internal.yourcompany.com"
|
||||
port = 5432
|
||||
interval = "2m"
|
||||
timeout = "10s"
|
||||
|
||||
tags = {
|
||||
team = "infrastructure"
|
||||
service = "database"
|
||||
environment = var.environment
|
||||
criticality = "critical"
|
||||
}
|
||||
}
|
||||
|
||||
resource "oneuptime_monitor" "application" {
|
||||
name = "${var.environment}-application"
|
||||
project_id = oneuptime_project.main.id
|
||||
|
||||
monitor_type = "website"
|
||||
url = "https://app.yourcompany.com/health"
|
||||
interval = "1m"
|
||||
timeout = "30s"
|
||||
|
||||
expected_status_codes = [200]
|
||||
|
||||
tags = {
|
||||
team = "development"
|
||||
service = "application"
|
||||
environment = var.environment
|
||||
criticality = "high"
|
||||
}
|
||||
}
|
||||
|
||||
# On-call policies
|
||||
resource "oneuptime_on_call_policy" "infrastructure_oncall" {
|
||||
name = "Infrastructure On-Call"
|
||||
project_id = oneuptime_project.main.id
|
||||
team_id = oneuptime_team.infrastructure.id
|
||||
|
||||
schedules {
|
||||
name = "24x7 Infrastructure"
|
||||
timezone = "America/New_York"
|
||||
|
||||
layers {
|
||||
name = "Primary"
|
||||
users = ["infra1@yourcompany.com", "infra2@yourcompany.com"]
|
||||
rotation_type = "weekly"
|
||||
start_time = "00:00"
|
||||
end_time = "23:59"
|
||||
days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Alert policies
|
||||
resource "oneuptime_alert_policy" "critical_infrastructure" {
|
||||
name = "Critical Infrastructure Alerts"
|
||||
project_id = oneuptime_project.main.id
|
||||
|
||||
conditions {
|
||||
monitor_id = oneuptime_monitor.database.id
|
||||
threshold = "down"
|
||||
}
|
||||
|
||||
actions {
|
||||
type = "email"
|
||||
recipients = ["infrastructure@yourcompany.com"]
|
||||
}
|
||||
|
||||
actions {
|
||||
type = "oncall_escalation"
|
||||
oncall_policy_id = oneuptime_on_call_policy.infrastructure_oncall.id
|
||||
}
|
||||
}
|
||||
|
||||
# Internal status page
|
||||
resource "oneuptime_status_page" "internal" {
|
||||
name = "Internal Services Status"
|
||||
project_id = oneuptime_project.main.id
|
||||
|
||||
domain = "status.internal.yourcompany.com"
|
||||
|
||||
components {
|
||||
name = "Database"
|
||||
monitor_id = oneuptime_monitor.database.id
|
||||
}
|
||||
|
||||
components {
|
||||
name = "Application"
|
||||
monitor_id = oneuptime_monitor.application.id
|
||||
}
|
||||
}
|
||||
|
||||
# outputs.tf
|
||||
output "project_id" {
|
||||
description = "Project ID"
|
||||
value = oneuptime_project.main.id
|
||||
}
|
||||
|
||||
output "status_page_url" {
|
||||
description = "Status page URL"
|
||||
value = "https://${oneuptime_status_page.internal.domain}"
|
||||
}
|
||||
```
|
||||
|
||||
## Environment-Specific Configuration
|
||||
|
||||
### Development Environment
|
||||
|
||||
```hcl
|
||||
# dev.tfvars
|
||||
oneuptime_api_url = "https://oneuptime-dev.yourcompany.com"
|
||||
environment = "development"
|
||||
```
|
||||
|
||||
### Staging Environment
|
||||
|
||||
```hcl
|
||||
# staging.tfvars
|
||||
oneuptime_api_url = "https://oneuptime-staging.yourcompany.com"
|
||||
environment = "staging"
|
||||
```
|
||||
|
||||
### Production Environment
|
||||
|
||||
```hcl
|
||||
# prod.tfvars
|
||||
oneuptime_api_url = "https://oneuptime.yourcompany.com"
|
||||
environment = "production"
|
||||
```
|
||||
|
||||
## Upgrade Process for Self-Hosted
|
||||
|
||||
When upgrading your OneUptime instance:
|
||||
|
||||
### 1. Pre-Upgrade Checklist
|
||||
|
||||
```bash
|
||||
# Backup current Terraform state
|
||||
terraform state pull > backup-$(date +%Y%m%d).tfstate
|
||||
|
||||
# Note current OneUptime version
|
||||
curl https://oneuptime.yourcompany.com/api/status | jq '.version'
|
||||
|
||||
# Note current provider version
|
||||
terraform providers | grep oneuptime
|
||||
```
|
||||
|
||||
### 2. Upgrade OneUptime Instance
|
||||
|
||||
Follow your standard OneUptime upgrade process (Docker, Helm, etc.)
|
||||
|
||||
### 3. Update Terraform Provider
|
||||
|
||||
```hcl
|
||||
# Update version in terraform block
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "= 7.0.124" # New version after upgrade
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. Test and Apply
|
||||
|
||||
```bash
|
||||
# Update provider
|
||||
terraform init -upgrade
|
||||
|
||||
# Plan to see any changes
|
||||
terraform plan
|
||||
|
||||
# Apply if everything looks good
|
||||
terraform apply
|
||||
```
|
||||
|
||||
## Network Configuration
|
||||
|
||||
### Firewall Rules
|
||||
|
||||
Ensure your Terraform runner can access:
|
||||
- OneUptime API endpoint (usually port 443/HTTPS)
|
||||
- Any internal resources being monitored
|
||||
|
||||
### VPN/Private Networks
|
||||
|
||||
If OneUptime is on a private network:
|
||||
|
||||
```hcl
|
||||
provider "oneuptime" {
|
||||
api_url = "https://10.0.1.100:443" # Internal IP
|
||||
api_key = var.oneuptime_api_key
|
||||
}
|
||||
```
|
||||
|
||||
## Security Best Practices
|
||||
|
||||
### 1. API Key Management
|
||||
|
||||
```bash
|
||||
# Use environment variables
|
||||
export ONEUPTIME_API_KEY="your-api-key"
|
||||
|
||||
# Or use a secret management system
|
||||
export ONEUPTIME_API_KEY=$(vault kv get -field=api_key secret/oneuptime)
|
||||
```
|
||||
|
||||
### 2. Least Privilege API Keys
|
||||
|
||||
Create API keys with minimal required permissions:
|
||||
- Monitor management
|
||||
- Alert policy management
|
||||
- Team management (if needed)
|
||||
|
||||
### 3. Network Security
|
||||
|
||||
```hcl
|
||||
# Example with TLS verification
|
||||
provider "oneuptime" {
|
||||
api_url = "https://oneuptime.yourcompany.com"
|
||||
api_key = var.oneuptime_api_key
|
||||
|
||||
# Additional security options if supported
|
||||
verify_ssl = true
|
||||
timeout = "30s"
|
||||
}
|
||||
```
|
||||
|
||||
## Monitoring Your Terraform Automation
|
||||
|
||||
Create monitors for your Terraform automation:
|
||||
|
||||
```hcl
|
||||
resource "oneuptime_monitor" "terraform_runner" {
|
||||
name = "Terraform Runner Health"
|
||||
project_id = oneuptime_project.main.id
|
||||
|
||||
monitor_type = "heartbeat"
|
||||
interval = "15m"
|
||||
|
||||
tags = {
|
||||
automation = "terraform"
|
||||
criticality = "medium"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting Self-Hosted Issues
|
||||
|
||||
### Issue: Connection Refused
|
||||
|
||||
```
|
||||
Error: connection refused
|
||||
```
|
||||
|
||||
**Solutions**:
|
||||
1. Check OneUptime instance is running
|
||||
2. Verify API URL is correct
|
||||
3. Check firewall/network connectivity
|
||||
4. Verify TLS certificates are valid
|
||||
|
||||
### Issue: API Version Mismatch
|
||||
|
||||
```
|
||||
Error: API version incompatible
|
||||
```
|
||||
|
||||
**Solutions**:
|
||||
1. Check OneUptime version: `curl https://your-instance/api/status`
|
||||
2. Update provider version to match
|
||||
3. Run `terraform init -upgrade`
|
||||
|
||||
### Issue: Self-Signed Certificates
|
||||
|
||||
If using self-signed certificates:
|
||||
|
||||
```bash
|
||||
# Temporarily skip TLS verification (not recommended for production)
|
||||
export ONEUPTIME_SKIP_TLS_VERIFY=true
|
||||
```
|
||||
|
||||
Better solution: Add your CA certificate to the system trust store.
|
||||
|
||||
## Backup and Disaster Recovery
|
||||
|
||||
### State Backup
|
||||
|
||||
```bash
|
||||
# Regular state backups
|
||||
terraform state pull > backup-$(date +%Y%m%d-%H%M%S).tfstate
|
||||
|
||||
# Automated backup script
|
||||
#!/bin/bash
|
||||
DATE=$(date +%Y%m%d-%H%M%S)
|
||||
terraform state pull > "backups/terraform-state-${DATE}.tfstate"
|
||||
find backups/ -name "terraform-state-*.tfstate" -mtime +30 -delete
|
||||
```
|
||||
|
||||
### Configuration Backup
|
||||
|
||||
```bash
|
||||
# Backup Terraform configuration
|
||||
tar -czf terraform-config-$(date +%Y%m%d).tar.gz *.tf *.tfvars
|
||||
```
|
||||
|
||||
## Multi-Environment Management
|
||||
|
||||
### Using Workspaces
|
||||
|
||||
```bash
|
||||
# Create environments
|
||||
terraform workspace new dev
|
||||
terraform workspace new staging
|
||||
terraform workspace new prod
|
||||
|
||||
# Switch between environments
|
||||
terraform workspace select prod
|
||||
terraform apply -var-file="prod.tfvars"
|
||||
```
|
||||
|
||||
### Using Separate Directories
|
||||
|
||||
```
|
||||
terraform/
|
||||
├── environments/
|
||||
│ ├── dev/
|
||||
│ │ ├── main.tf
|
||||
│ │ └── terraform.tfvars
|
||||
│ ├── staging/
|
||||
│ │ ├── main.tf
|
||||
│ │ └── terraform.tfvars
|
||||
│ └── prod/
|
||||
│ ├── main.tf
|
||||
│ └── terraform.tfvars
|
||||
└── modules/
|
||||
└── oneuptime/
|
||||
├── main.tf
|
||||
├── variables.tf
|
||||
└── outputs.tf
|
||||
```
|
||||
|
||||
This approach provides better isolation and easier version management per environment.
|
||||
Reference in New Issue
Block a user