How keycloak/terraform-provider-keycloak works
Main Components
• Terraform CLI/Configuration – The client side that runs Terraform commands.
• Terraform Provider Plugin (this project) – The heart of this project, which handles resource definitions, state management, and API interactions.
▪ The “provider” package: Contains the Terraform provider implementation, data sources, and resource schemas.
▪ The “keycloak” package: Contains the underlying client code that interacts with the Keycloak API (handling HTTP calls, parsing data, error management, etc.).
▪ Custom integrations (e.g., custom-user-federation-example): Provides examples and extensions like custom identity providers or event listeners.
▪ Tests & CI Support: Represent the acceptance tests (both unit and integration) and the local development environment (using Docker Compose) which includes Keycloak, PostgreSQL, and OpenLDAP.
• External Keycloak Server – The target system where the provider pushes configuration changes.
• (Optionally) Local development environment – The Docker Compose setup that spins up Keycloak along with dependent services for testing.
Relationships and Data Flows
• The provider plugin internally routes operations to the keycloak package, which then invokes Keycloak REST API endpoints to create, update, or delete configurations.
• For acceptance tests and local development, show that the Docker Compose environment (including Keycloak, PostgreSQL, OpenLDAP) is used to simulate production-like interactions.
• That configuration and authentication details flow from the Terraform configuration (including provider arguments and environment variables) to the provider.
Architectural Patterns & Design Principles
• Modularity: The project separates concerns between the Terraform provider (which maps to Terraform’s plugin interface) and the lower-level Keycloak API client layer.
• Extensibility: With custom packages (like custom-user-federation-example) and a wide range of supported Keycloak resources, the design supports a modular and extensible structure.
• Continuous integration and automated releases (using GitHub Actions and GoReleaser) are also part of the architecture.
• Testing: Emphasize the layered testing strategy (unit tests in the “keycloak” package and acceptance tests in the “provider” package).
Relevant Technologies and Frameworks
• Go (with Go Modules for dependency management)
• Terraform SDK (for provider integration)
• Keycloak APIs (REST endpoints)
• Docker Compose (for local development/testing)
• GitHub Actions (for CI/CD pipelines)
• GoReleaser (for automated release building)