This is the official Terraform Provider for KBCloud(KubeBlocks Enterprise), allowing you to manage databases, clusters, backups, and other KBCloud resources via infrastructure as code.
The provider is built using the Terraform Plugin Framework.
- Terraform >= 1.0
- Go >= 1.21 (to build the provider plugin)
- Python 3 & Poetry (for code generation)
- KubeBlocks Enterprise >= 2.2.0
Clone this repository and build the provider locally:
# Build the provider executable
make buildThis will create the terraform-provider-kbcloud binary in your workspace.
To test the provider locally without publishing it to the Terraform Registry, you need to configure Terraform's dev_overrides.
Create or edit your ~/.terraformrc (or %APPDATA%\terraform.rc on Windows) to point to the directory where you built the binary:
provider_installation {
dev_overrides {
# Point this to the ABSOLUTE path of the directory containing the built binary
"registry.terraform.io/apecloud/kbcloud" = "/Users/your_username/path/to/terraform-provider-kbcloud"
}
# For all other providers, install them directly from their origin provider registries as normal
direct {}
}Create a main.tf file (e.g., in the example/mysql/ directory) and configure the provider:
terraform {
required_providers {
kbcloud = {
source = "registry.terraform.io/apecloud/kbcloud"
}
}
}
provider "kbcloud" {
api_url = "https://kb-cloud-apiserver-endpoint.com/api" # or your target API endpoint
api_key = "your_api_key"
api_secret = "your_api_secret"
}
resource "kbcloud_cluster" "my_mysql" {
name = "my-mysql-cluster"
org_name = "my-org"
environment_name = "prod"
engine = "mysql"
version = "8.0.44"
mode = "replication"
cluster_type = "Normal"
# ... Add components and other configurations ...
}Then, you can run the standard Terraform workflow:
terraform plan
terraform apply
terraform destroy(Note: Because of dev_overrides, terraform init is not required for the kbcloud provider and may show warnings).
This provider heavily utilizes an OpenAPI-based Python code generator to automatically create Terraform models and schemas.
When the OpenAPI spec changes or you modify the generation templates, you should run the generator:
# Generate Go models and schemas, and automatically format them
make generateThis command runs the Python CLI under .generator/src/ to parse .generator/specs/adminapi-bundle-tmp.yaml and updates the files inside:
internal/types/internal/resource/internal/datasource/
For more details on how the generator works, see the Generator README.
For debugging the provider, refer to the official Terraform Plugin Framework documentation on Debugging Providers.
Please see the LICENSE file for details.