Prepare for public release #4

Merged
benvin merged 3 commits from benvin/public-release-docs into main 2026-11-17 22:25:04 +11:00
24 changed files with 366 additions and 135 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 IUCLabs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+5 -2
View File
@@ -1,10 +1,10 @@
.PHONY: build install test lint fmt clean tidy package patch minor major
.PHONY: build install test lint fmt clean tidy package docs patch minor major
BINARY := terraform-provider-encapi
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-dev")
OS_ARCH := linux_amd64
INSTALL_VERSION := $(shell echo $(VERSION) | sed 's/^v//')
INSTALL_DIR := ~/.terraform.d/plugins/git.unkin.net/unkin/encapi/$(INSTALL_VERSION)/$(OS_ARCH)
INSTALL_DIR := ~/.terraform.d/plugins/registry.terraform.io/iuclabs/encapi/$(INSTALL_VERSION)/$(OS_ARCH)
ZIP := $(BINARY)_$(INSTALL_VERSION)_$(OS_ARCH).zip
GO_VERSION_REQUIRED := 1.23
@@ -39,6 +39,9 @@ package: build
clean:
rm -f $(BINARY) *.zip
docs:
go generate ./...
tidy:
go mod tidy
+37 -41
View File
@@ -1,65 +1,61 @@
# terraform-provider-encapi
# Terraform Provider encapi
Terraform / OpenTofu provider for [encapi](https://git.unkin.net/unkin/encapi),
the Puppet External Node Classifier that replaces Cobbler.
The encapi provider manages a Puppet External Node Classifier (ENC) served by
encapi: Puppet environments (statuses), roles with inheritable default
parameters, and per-node role assignments. It works with Terraform and OpenTofu.
It manages three resources and two data sources over the encapi HTTP API.
## Provider configuration
## Quick start
```hcl
terraform {
required_providers {
encapi = {
source = "git.unkin.net/unkin/encapi"
version = "0.0.1"
source = "IUCLabs/encapi"
}
}
}
provider "encapi" {
endpoint = "https://encapi.k8s.syd1.au.unkin.net"
# token = "..." # defaults to $ENCAPI_WRITE_TOKEN
endpoint = "https://encapi.example.com"
# token defaults to the ENCAPI_WRITE_TOKEN environment variable
}
resource "encapi_status" "production" {
name = "production"
}
resource "encapi_role" "web" {
name = "roles::web"
default_params = jsonencode({ port = 8080 })
}
resource "encapi_node" "web01" {
certname = "web01.example.com"
role = encapi_role.web.name
environment = encapi_status.production.name
}
```
Reads are unauthenticated; writes require the token. Set it out-of-band via the
`ENCAPI_WRITE_TOKEN` environment variable (managed in Vault) rather than in HCL.
Reads are unauthenticated; writes need the bearer token.
## Resources
## Requirements
| Resource | Purpose |
|------------------|----------------------------------------------------------------|
| `encapi_status` | A Puppet environment (Cobbler "status"): testing, production… |
| `encapi_role` | A class assignment target with inheritable `default_params`. |
| `encapi_node` | Assigns a host (certname) to a role + environment, with `params`. |
- [Terraform](https://developer.hashicorp.com/terraform/downloads) >= 1.0 or [OpenTofu](https://opentofu.org) >= 1.6
- [Go](https://go.dev/doc/install) >= 1.25 (to build the provider)
## Data sources
## Building
| Data source | Purpose |
|------------------|------------------------------------------|
| `encapi_node` | Look up a node's role/environment/params. |
| `encapi_role` | Look up a role and its default params. |
## Parameters
`default_params` (role) and `params` (node) are JSON-object strings. Use
`jsonencode({...})` so numbers, bools, lists, and nested objects keep their
types in the rendered ENC document:
```hcl
resource "encapi_role" "minio" {
name = "roles::infra::storage::minio"
default_params = jsonencode({ minio_pool = "pool1", replicas = 4, tls = true })
}
```sh
make build # or: go build
make test
make docs # regenerate docs/ from the schema and examples/
```
Node `params` override the role's `default_params` on key collisions.
## Documentation
## Releases
See [`docs/`](docs/index.md) for the provider, resource and data source
reference, and [`examples/`](examples/) for usage.
Tagging `vX.Y.Z` builds `terraform-provider-encapi_X.Y.Z_linux_amd64.zip` and
uploads it to the ArtifactAPI Terraform registry (`terraform-unkin` remote,
namespace `unkin/encapi`), which serves it as a GPG-signed provider registry.
## License
See `examples/` for full usage.
[MIT](LICENSE)
+40
View File
@@ -0,0 +1,40 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "encapi_node Data Source - encapi"
subcategory: ""
description: |-
Looks up the role/environment/params assigned to a Puppet node.
---
# encapi_node (Data Source)
Looks up the role/environment/params assigned to a Puppet node.
## Example Usage
```terraform
data "encapi_node" "web0" {
certname = "node01.example.com"
}
output "web0_role" {
value = data.encapi_node.web0.role
}
output "web0_environment" {
value = data.encapi_node.web0.environment
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `certname` (String) Puppet certname (fqdn).
### Read-Only
- `environment` (String) Assigned environment/status.
- `params` (String) Per-node params as JSON.
- `role` (String) Assigned role.
+35
View File
@@ -0,0 +1,35 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "encapi_role Data Source - encapi"
subcategory: ""
description: |-
Looks up a role and its inheritable default params.
---
# encapi_role (Data Source)
Looks up a role and its inheritable default params.
## Example Usage
```terraform
data "encapi_role" "vault" {
name = "roles::infra::storage::vault"
}
output "vault_default_params" {
value = jsondecode(data.encapi_role.vault.default_params)
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `name` (String) Role/class name.
### Read-Only
- `default_params` (String) Default params as JSON.
- `description` (String) Description.
+38
View File
@@ -0,0 +1,38 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "encapi Provider"
description: |-
Manage the Puppet External Node Classifier (encapi): roles, statuses (environments), and node role assignments.
---
# encapi Provider
Manage the Puppet External Node Classifier (encapi): roles, statuses (environments), and node role assignments.
## Example Usage
```terraform
terraform {
required_providers {
encapi = {
source = "IUCLabs/encapi"
}
}
}
provider "encapi" {
endpoint = "https://encapi.example.com"
# token defaults to the ENCAPI_WRITE_TOKEN environment variable
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `endpoint` (String) The encapi server base URL, e.g. `https://encapi.example.com`.
### Optional
- `token` (String, Sensitive) Write token (bearer) for mutating operations. Defaults to the `ENCAPI_WRITE_TOKEN` environment variable.
+50
View File
@@ -0,0 +1,50 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "encapi_node Resource - encapi"
subcategory: ""
description: |-
Assigns a Puppet node (by certname) to a role and environment, with optional per-node parameter overrides.
---
# encapi_node (Resource)
Assigns a Puppet node (by certname) to a role and environment, with optional per-node parameter overrides.
## Example Usage
```terraform
resource "encapi_node" "example" {
certname = "node01.example.com"
role = "roles::infra::storage::vault"
environment = "testing"
# Optional per-node overrides (win over the role's default_params).
params = jsonencode({
vault_role = "leader"
})
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `certname` (String) Puppet certname (fqdn) of the host.
- `environment` (String) Environment/status. Must reference an existing encapi_status.
- `role` (String) Role/class to assign. Must reference an existing encapi_role.
### Optional
- `params` (String) Per-node parameter overrides as a JSON object. Use jsonencode({...}) to preserve value types. These override the role's default_params.
## Import
Import is supported using the following syntax:
The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:
```shell
# Import by certname.
terraform import encapi_node.example node01.example.com
```
+51
View File
@@ -0,0 +1,51 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "encapi_role Resource - encapi"
subcategory: ""
description: |-
A Puppet class assignment target (e.g. roles::infra::storage::vault) with inheritable default parameters.
---
# encapi_role (Resource)
A Puppet class assignment target (e.g. roles::infra::storage::vault) with inheritable default parameters.
## Example Usage
```terraform
resource "encapi_role" "minio" {
name = "roles::infra::storage::minio"
description = "MinIO object storage node"
# Inheritable defaults, merged into every node with this role.
# Use jsonencode so numbers/bools keep their type in the ENC output.
default_params = jsonencode({
minio_pool = "pool1"
replicas = 4
tls = true
})
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `name` (String) Fully-qualified role/class name, e.g. roles::infra::storage::vault.
### Optional
- `default_params` (String) Inheritable default parameters as a JSON object. Use jsonencode({...}) to preserve value types. Merged into every node carrying this role; node params win on collisions.
- `description` (String) Human-readable description.
## Import
Import is supported using the following syntax:
The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:
```shell
# Import by role name.
terraform import encapi_role.minio roles::infra::storage::minio
```
+52
View File
@@ -0,0 +1,52 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "encapi_status Resource - encapi"
subcategory: ""
description: |-
A Puppet environment, referred to as a status (e.g. testing, production, development). Nodes may only reference a status that exists.
---
# encapi_status (Resource)
A Puppet environment, referred to as a status (e.g. testing, production, development). Nodes may only reference a status that exists.
## Example Usage
```terraform
# Statuses map to Puppet environments. Define as many as you need;
# a node can only be pinned to one that exists.
resource "encapi_status" "testing" {
name = "testing"
}
resource "encapi_status" "production" {
name = "production"
description = "Production environment"
}
resource "encapi_status" "development" {
name = "development"
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `name` (String) Status/environment name.
### Optional
- `description` (String) Human-readable description.
## Import
Import is supported using the following syntax:
The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:
```shell
# Import by status name.
terraform import encapi_status.production production
```
@@ -1,5 +1,5 @@
data "encapi_node" "web0" {
certname = "ausyd1nxvm2000.main.unkin.net"
certname = "node01.example.com"
}
output "web0_role" {
@@ -0,0 +1,7 @@
data "encapi_role" "vault" {
name = "roles::infra::storage::vault"
}
output "vault_default_params" {
value = jsondecode(data.encapi_role.vault.default_params)
}
-82
View File
@@ -1,82 +0,0 @@
terraform {
required_providers {
encapi = {
source = "git.unkin.net/unkin/encapi"
version = "0.0.1"
}
}
}
provider "encapi" {
endpoint = "https://encapi.k8s.syd1.au.unkin.net"
# token defaults to the ENCAPI_WRITE_TOKEN environment variable
}
# ---------------------------------------------------------------------------
# Statuses (Puppet environments / Cobbler "status")
# ---------------------------------------------------------------------------
resource "encapi_status" "testing" {
name = "testing"
description = "Implicit environment; dropped from ENC output so agents use their default."
}
resource "encapi_status" "production" {
name = "production"
}
resource "encapi_status" "development" {
name = "development"
}
# ---------------------------------------------------------------------------
# Roles, with inheritable default params (use jsonencode to keep value types)
# ---------------------------------------------------------------------------
resource "encapi_role" "vault" {
name = "roles::infra::storage::vault"
description = "HashiCorp Vault cluster member"
}
resource "encapi_role" "minio" {
name = "roles::infra::storage::minio"
description = "MinIO object storage node"
default_params = jsonencode({
minio_pool = "pool1"
replicas = 4
})
}
# ---------------------------------------------------------------------------
# Node assignments
# ---------------------------------------------------------------------------
resource "encapi_node" "vault0" {
certname = "ausyd1nxvm2000.main.unkin.net"
role = encapi_role.vault.name
environment = encapi_status.testing.name
}
resource "encapi_node" "minio0" {
certname = "ausyd1nxvm2100.main.unkin.net"
role = encapi_role.minio.name
environment = encapi_status.production.name
# per-node override of the role default
params = jsonencode({
minio_pool = "pool2"
})
}
# ---------------------------------------------------------------------------
# Data sources
# ---------------------------------------------------------------------------
data "encapi_node" "vault0" {
certname = encapi_node.vault0.certname
}
output "vault0_role" {
value = data.encapi_node.vault0.role
}
+12
View File
@@ -0,0 +1,12 @@
terraform {
required_providers {
encapi = {
source = "IUCLabs/encapi"
}
}
}
provider "encapi" {
endpoint = "https://encapi.example.com"
# token defaults to the ENCAPI_WRITE_TOKEN environment variable
}
+2
View File
@@ -0,0 +1,2 @@
# Import by certname.
terraform import encapi_node.example node01.example.com
@@ -1,5 +1,5 @@
resource "encapi_node" "example" {
certname = "ausyd1nxvm2000.main.unkin.net"
certname = "node01.example.com"
role = "roles::infra::storage::vault"
environment = "testing"
+2
View File
@@ -0,0 +1,2 @@
# Import by role name.
terraform import encapi_role.minio roles::infra::storage::minio
@@ -0,0 +1,2 @@
# Import by status name.
terraform import encapi_status.production production
@@ -1,4 +1,4 @@
# Statuses map to Puppet environments. Define as many as your estate uses;
# Statuses map to Puppet environments. Define as many as you need;
# a node can only be pinned to one that exists.
resource "encapi_status" "testing" {
name = "testing"
+1 -1
View File
@@ -1,4 +1,4 @@
module git.unkin.net/unkin/terraform-provider-encapi
module github.com/IUCLabs/terraform-provider-encapi
go 1.25.9
+1 -1
View File
@@ -1,6 +1,6 @@
package provider
// API wire types, mirroring git.unkin.net/unkin/encapi/pkg/models. They are
// API wire types, mirroring the encapi API models. They are
// duplicated here to keep the provider's dependency surface small.
type roleAPI struct {
+2 -2
View File
@@ -39,11 +39,11 @@ func (p *encapiProvider) Schema(_ context.Context, _ provider.SchemaRequest, res
Description: "Manage the Puppet External Node Classifier (encapi): roles, statuses (environments), and node role assignments.",
Attributes: map[string]schema.Attribute{
"endpoint": schema.StringAttribute{
Description: "The encapi server base URL (e.g. https://encapi.k8s.syd1.au.unkin.net).",
Description: "The encapi server base URL, e.g. `https://encapi.example.com`.",
Required: true,
},
"token": schema.StringAttribute{
Description: "Write token (bearer) for mutating operations. Defaults to the ENCAPI_WRITE_TOKEN environment variable.",
Description: "Write token (bearer) for mutating operations. Defaults to the `ENCAPI_WRITE_TOKEN` environment variable.",
Optional: true,
Sensitive: true,
},
+1 -1
View File
@@ -37,7 +37,7 @@ func (r *statusResource) Metadata(_ context.Context, req resource.MetadataReques
func (r *statusResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "A Puppet environment (Cobbler \"status\", e.g. testing, production, development). Nodes may only reference a status that exists.",
Description: "A Puppet environment, referred to as a status (e.g. testing, production, development). Nodes may only reference a status that exists.",
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: "Status/environment name.",
+4 -2
View File
@@ -3,6 +3,8 @@
// role assignments.
package main
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.24.0 generate --provider-name encapi
import (
"context"
"flag"
@@ -10,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"git.unkin.net/unkin/terraform-provider-encapi/internal/provider"
"github.com/IUCLabs/terraform-provider-encapi/internal/provider"
)
var version = "0.0.1"
@@ -21,7 +23,7 @@ func main() {
flag.Parse()
opts := providerserver.ServeOpts{
Address: "git.unkin.net/unkin/encapi",
Address: "registry.terraform.io/iuclabs/encapi",
Debug: debug,
}