$ show lxc/terraform-provider-incus
This repository implements a Terraform provider for managing Incus, a container and virtual machine orchestration platform. It provides full CRUD operations for Incus resources such as instances, networks, storage pools, profiles, projects, certificates, cluster groups, and server configuration, along with corresponding data sources for reading existing state. The provider is built using the Terraform Plugin Framework (v1.19.0) with some fallback to Plugin SDK v2, and communicates with Incus via its client library (github.com/lxc/incus/v7). Key entry points include the main.go provider server, internal/provider/provider.go for resource registration, and individual resource files under internal/{certificate,cluster,image,instance,network,profile,project,server,storage}. The provider supports multiple remotes, OIDC authentication, clustering, and PKI, and includes a code generation tool (cmd/generate-datasources) that produces consistent data source implementations and documentation from a YAML configuration and Go templates. Acceptance tests require a live Incus environment and cover complex scenarios like instance lifecycle, exec triggers, file uploads, and import. The codebase is well-structured with shared utilities in internal/common for config/device/file/import handling, and demonstrates a consistent pattern for state synchronization and error handling. However, it carries some technical debt from its fork of the LXD provider, including dual SDK usage and heavy boilerplate that could benefit from further abstraction.
The LLM identified 5 files worth highlighting for reuse:
Provides functions ToConfigMap, ToConfigMapType, MergeConfig, and StripConfig for converting between Terraform map attributes and Incus API config structures. This is a reusable utility for any Terraform provider that needs to handle server-managed keys and config merging, and is isolated from the rest of the codebase.
Implements ToDeviceMap, ToDeviceSetType, and ToDeviceSetTypePreservingNulls for converting device definitions between Terraform types and Incus API types. This pattern is reusable for any provider that manages device-like resources with nested attributes and null preservation.
Contains ImportMetadata and ParseImportID for parsing complex import IDs with remote, project, and optional key-value pairs. This is a reusable component for any Terraform provider that needs to handle multi-part import identifiers.
A code generation tool that reads a YAML configuration (generate-datasources.yaml) and Go templates to produce consistent data source implementations and documentation. This pattern is reusable for any project that needs to generate repetitive Terraform provider code from a declarative config, reducing boilerplate and ensuring consistency.
Provides IsNotFoundError and diagnostic helper functions for Terraform providers. This is a small but reusable utility that can be extracted into any Terraform provider to standardize error handling and diagnostic creation.