vcluster Terraform Provider
Custom Terraform provider that talks to a vcluster API and calls /createcluster to create clusters.
Build
cd /home/behrooz/Projects/vcluster_terraform
go build -o terraform-provider-vcluster
Install locally for Terraform
Terraform expects the provider binary in a specific directory based on
<hostname>/<namespace>/<type>/<version>/<os>_<arch>.
For a local provider with:
- source:
local/vcluster/vcluster - version:
0.1
Copy the binary like this (Linux amd64 example):
mkdir -p ~/.terraform.d/plugins/local/vcluster/vcluster/0.1/linux_amd64
cp terraform-provider-vcluster ~/.terraform.d/plugins/local/vcluster/vcluster/0.1/linux_amd64/
Adjust the OS/arch folder name if necessary.
Example Terraform configuration
Create a new directory for using the provider, e.g. example/ and add main.tf:
terraform {
required_providers {
vcluster = {
source = "local/vcluster/vcluster"
version = "0.1"
}
}
}
provider "vcluster" {
base_url = "http://localhost:8082"
# Credentials used for POST /login. The provider will automatically
# call /login, get the token from {"token": "..."} and send it as
# the Authorization header on subsequent API calls.
username = "admin"
password = "admin"
}
resource "vcluster_cluster" "example" {
name = "mytiny"
cluster_id = "2qjqhhqr"
control_plane = "k8s"
status = "Progressing"
cpu = "1"
memory = "1024"
platform_version = "v1.31.6"
health_check = ""
alert = ""
endpoint = ""
cluster_type = "tiny"
coredns_cpu = "0.1"
coredns_memory = "0.25Gi"
apiserver_cpu = "0.1"
apiserver_memory = "0.25Gi"
}
Then run:
cd example
terraform init
terraform apply
Description
Languages
Go
89.9%
HCL
10.1%