Skip to content

nolte/terraform-operator

Repository files navigation

terraform-operator:

Kubernetes CRD to handle terraform operations.

Architecture

Below is a diagram of the basic idea of the project

The controller is responsible for fetching tfvars or other files, and then creates a Kubernetes Job to perform the actual terraform execution. By default, the Terraform-operator will save state in a Consul on the same cluster. Even though Consul is the default, other state backends can be configured.

Docs

Install the Operator and CRDs

To get started, install the files in deploy

kubectl apply -f deploy/crds/tf.isaaguilar.com_terraforms_crd.yaml
kubectl apply -f deploy --namespace tf-system

Create Terraform Resources

Once the operator is installed, terraform resources are ready to be deployed.

Check out the examples directory to see the different options tf-operator handles. See complete-examples for realistic examples.

Creating your first terraform

Apply your first terraform resource by running a hello_world example:

$ printf 'apiVersion: tf.isaaguilar.com/v1alpha1
kind: Terraform
metadata:
  name: tf-operator-test
spec:
  stack:
    terraformVersion: 0.12.23
    source:
      address: https://github.com/cloudposse/terraform-aws-test-module.git
  config:
    customBackend: |-
      terraform {
        backend "local" {
          path = "relative/path/to/terraform.tfstate"
        }
      }
    applyOnCreate: true
    applyOnUpdate: true
    ignoreDelete: true
'|kubectl apply -f-

Check the kubectl pod logs:

$ kubectl logs -f job/tf-operator-test

Delete the resource:

$ kubectl delete terraform tf-operator-test

More examples coming soon!

Development

Requires the following installed on your system:

  • go v1.13.3
  • operator-sdk v0.15.1

About

A Kubernetes CRD to handle terraform operations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 86.8%
  • Shell 8.8%
  • Makefile 2.8%
  • Dockerfile 1.4%
  • HCL 0.2%