A Kubernetes CRD and Controller to handle Terraform operations by generating k8s jobs catered to perform Terraform workflows
This project is:
- A way to run Terraform in Kubernetes by defining Terraform deployments as Kubernetes manifests
- A controller that configures and starts Kubernetes Jobs when it sees changes to the Kubernetes manifest
- A Terraform runner which runs Terraform plan/apply, and can also perform pre and post scripts
This project is not:
- An HCL to YAML converter or vice versa
- A Terraform module definition
Install the operator with helm:
helm repo add isaaguilar https://isaaguilar.github.io/helm-charts
helm repo update
helm install terraform-operator isaaguilar/terraform-operator
Then start running workloads. For example from this repo, run:
kubectl apply -f examples/complete-examples/simple-template.yaml
A terraform runner pod should appear shortly. The runner executes the terraform module configured in spec.terraformModule.address
. In the example, the module configured is https://github.com/cloudposse/terraform-example-module.git?ref=master
which simply generates a random number.
Requires the following installed on your system:
- go >= v1.15.0
Run make install
to install or update the crd in your current-context cluster.
Finally, run make run
to start the controller to operate in your current-context cluster.
Installation
- Installing Terraform-operator (Install using helm or kubectl)
- Hello Terraform Operator (A very quick example of defining a resource)
Configurations
- Terraform-state (Pushing State to consul, S3, etc.)
- Terraform-provider credentials (ie Cloud Credentials)
- Operator Actions (Configuring when to run
terraform apply
) - Exporting TFvars (Saving your tfvars for reference elsewhere)
- Pre/Post Run Scripts (Scripts that run before and after Terraform commands)
- Terraform Runner Versions (A list of officially supported Terraform Runners)
Advanced Topics
- Git Authentication (Using SSH Keys and or Tokens with Git)
- Using an SSH Proxy (Getting to Private and Enterprise Git Servers)
Architecture
- Terraform Operator Design (The design overview of the Project)
- Terraform Outputs (Finding Terraform outputs after running terraform)
Issues and Pull Requests are welcomed.