kube-tf-reconciler
Kube Terraform Reconciler
NOTE: This project is currently developed for internal use, but may later be developed for broader consumption
Kube Terraform Reconciler (krec) is a Kubernetes operator for managing infrastructure as code using Terraform. It allows you to define Terraform workspaces as Kubernetes custom resources and automatically reconciles your infrastructure based on these resources.
Features
- Define Terraform workspaces as Kubernetes resources
- Automatic reconciliation of infrastructure
- Support for custom providers and modules
- Terraform backend configuration
- Auto-apply functionality
- State tracking through Kubernetes status
Usage
To deploy the operator, the recommended approach is using the provided Helm chart under /charts/terraform-reconciler
After deploying the operator, get started by deploying a Workspace resource. A workspace is a completely self-contained Terraform execution environment, including the Terraform version, authentication, backend configuration, provider specifications, and module definitions.
A simple example manifest would look like this:
Authentication towards private module repositories
If the Terraform module resides in a private repository (like a private GitHub repository), the workspace needs additional environment variables to use for authentication.
where the GitHub credentials would look like:
Authentication towards cloud providers
In the simple example above, authentication credentials are stored in a Kubernetes secret. A more secure approach however would be to set up OIDC authentication for your Kubernetes cluster and use service accounts with the appropriate permissions.
For example, granting admin access in AWS would look something like this:
Then, the Workspace can assume the role and access the necessary resources using the following parameters
Contributors Guide
Ensure CRDs are updated by running the following command:
Running tests
Debugging in a live cluster
To debug the operator locally:
- build the debug image:
ALTERNATIVELY, with minikube it’s possible to directly build images into minikube’s internal Docker Engine, which makes step 2 unneccessary
- Load the image into your local Kubernetes cluster:
- Deploy the operator with the debug image (make sure the CRD is installed beforehand):
- Set up port forwarding:
- Connect your debugger:
- For VS Code: Configure launch.json to connect to localhost:2345
- For GoLand: Set up a Go Remote configuration targeting localhost:2345
- For Delve CLI: dlv connect localhost:2345
License
This project is licensed under Apache License 2.0. See the LICENSE
MPL Dependencies
This project includes the following dependencies that are licensed under the Mozilla Public License (MPL):
- https://github.com/hashicorp/go-version
- https://github.com/hashicorp/hc-install
- https://github.com/hashicorp/hcl
- https://github.com/hashicorp/terraform-exec
MPL Modifications
If you change any MPL-2.0 files, you must distribute those modified files under the MPL-2.0. The full text of the MPL licenses can be found in the LICENSES folder. It’s recommended to look at the licenses stipulated in the repositories of the dependencies as listed above to make sure they are up to date.
Contributions
We welcome contributions to the Kube TF Reconciler, please read the contribution guidelines for more information on how to contribute.
As this project is in the early stages of development, we are still working on the contribution guidelines and best practices. We appreciate your patience and understanding as we work to improve the project.