- Implemented a comprehensive bash script to automate the publishing process of the OneUptime Terraform provider to the Terraform Registry. - Included functionalities for version specification, testing mode, dependency installation, provider generation, GitHub repository interaction, release creation, and asset uploading. - Added error handling, prerequisite validation, and detailed logging for better user experience. - Integrated GPG signing for release assets and SHA256 checksum generation. - Provided usage instructions and examples for ease of use.
6.4 KiB
Local Terraform Provider Installation
This guide explains how to install the OneUptime Terraform provider locally for development and testing. The script automatically generates the provider and installs it locally.
Prerequisites
-
OneUptime Development Environment:
- Node.js and npm installed
- OneUptime project cloned and set up
-
Install Terraform: Make sure Terraform is installed and available in your PATH
terraform version
Installation Methods
Method 1: Using npm script (Recommended)
# Generate provider and install with auto-detected version
npm run install-terraform-provider-locally
# Generate provider and install with specific version
npm run install-terraform-provider-locally -- -v 1.0.0
# Force regenerate and reinstall
npm run install-terraform-provider-locally -- --force
# Skip generation (use existing provider)
npm run install-terraform-provider-locally -- --skip-generation
# Verbose output
npm run install-terraform-provider-locally -- --verbose
Method 2: Direct script execution
# Basic installation (generates provider first)
./Scripts/TerraformProvider/install-terraform-provider-locally.sh
# With options
./Scripts/TerraformProvider/install-terraform-provider-locally.sh -v 1.0.0 --force --verbose
# Skip generation (use existing provider)
./Scripts/TerraformProvider/install-terraform-provider-locally.sh --skip-generation
# Show help
./Scripts/TerraformProvider/install-terraform-provider-locally.sh --help
What the Script Does
-
Validates Prerequisites
- Checks if Node.js, npm, and Terraform are installed
- Verifies OneUptime project structure
-
Generates Terraform Provider (unless
--skip-generationis used)- Runs
npm run generate-terraform-provider - Creates OpenAPI specification
- Generates Go provider code
- Builds binaries for multiple platforms
- Runs
-
Detects Platform
- Automatically detects your OS (Darwin/Linux/Windows/FreeBSD)
- Determines architecture (amd64/arm64/arm/386)
-
Installs Provider Binary
- Copies the appropriate binary to Terraform's plugins directory
- Creates the correct directory structure:
~/.terraform.d/plugins/registry.terraform.io/oneuptime/oneuptime/{version}/{platform}/ - Makes the binary executable (Unix systems)
-
Creates Example Configuration
- Generates a sample Terraform configuration in
terraform-provider-example/ - Includes
main.tf,versions.tf, and documentation
- Generates a sample Terraform configuration in
-
Verifies Installation
- Runs
terraform initto verify the provider loads correctly - Shows provider information
- Runs
Directory Structure
After installation, you'll have:
~/.terraform.d/plugins/
└── registry.terraform.io/
└── oneuptime/
└── oneuptime/
└── {version}/
└── {platform}/
└── terraform-provider-oneuptime_v{version}
And in your project:
terraform-provider-example/
├── main.tf
├── versions.tf
├── .terraform-version
└── README.md
Usage Example
After installation, you can use the provider in any Terraform configuration:
terraform {
required_providers {
oneuptime = {
source = "oneuptime/oneuptime"
version = "~> 1.0.0"
}
}
}
provider "oneuptime" {
api_url = "https://oneuptime.com"
api_key = var.oneuptime_api_key
}
resource "oneuptime_monitor" "example" {
name = "My Website Monitor"
# Other configuration...
}
Testing the Installation
-
Navigate to the example directory:
cd terraform-provider-example -
Initialize Terraform:
terraform init -
Validate the configuration:
terraform validate
Platform Support
The script supports installation on:
- macOS: darwin_amd64, darwin_arm64
- Linux: linux_amd64, linux_arm64, linux_arm, linux_386
- Windows: windows_amd64, windows_arm64, windows_386
- FreeBSD: freebsd_amd64, freebsd_arm64, freebsd_arm, freebsd_386
Troubleshooting
Provider not found after installation
-
Check that the binary was copied correctly:
ls -la ~/.terraform.d/plugins/registry.terraform.io/oneuptime/oneuptime/ -
Verify the binary is executable (Unix systems):
file ~/.terraform.d/plugins/registry.terraform.io/oneuptime/oneuptime/{version}/{platform}/terraform-provider-oneuptime_v{version} -
Run terraform with debug logging:
TF_LOG=DEBUG terraform init
Version mismatch
The script auto-detects the version from:
- Command line argument (
-vflag) - Go module file (
go.mod) - Build directory binary names
- Defaults to "dev"
Ensure your Terraform configuration uses the same version.
Binary not found for your platform
Check what binaries are available:
ls -la Terraform/terraform-provider-framework/builds/
The provider generation should create binaries for multiple platforms. If your platform is missing, you may need to build it manually:
cd Terraform/terraform-provider-framework
GOOS={your_os} GOARCH={your_arch} go build -o builds/terraform-provider-oneuptime_{your_os}_{your_arch} ./cmd
Permission errors
On Unix systems, make sure you have write permissions to ~/.terraform.d/:
mkdir -p ~/.terraform.d/plugins
chmod 755 ~/.terraform.d/plugins
Development Workflow
The script provides a streamlined development workflow:
-
Generate and install in one step:
npm run install-terraform-provider-locally -
Test changes:
cd terraform-provider-example terraform init terraform plan -
Make changes to OneUptime API and regenerate:
npm run install-terraform-provider-locally -- --force -
Skip generation if provider already exists:
npm run install-terraform-provider-locally -- --skip-generation
Uninstalling
To remove the locally installed provider:
rm -rf ~/.terraform.d/plugins/registry.terraform.io/oneuptime/
Or remove just a specific version:
rm -rf ~/.terraform.d/plugins/registry.terraform.io/oneuptime/oneuptime/{version}/
Related Scripts
generate-terraform-provider: Generates the provider from OneUptime APIpublish-terraform-provider: Publishes the provider to Terraform Registryinstall-terraform-provider-locally: Installs provider locally (this script)