A machine-readable index of this documentation for AI agents is available at https://kubevela.io/llms.txt. Markdown versions of documentation pages are available by appending .md to their URLs.
Skip to main content
Version: Terraform Controller Next

Quick Start

One complete run, start to finish: install the controller, give it a piece of Terraform, read what Terraform produced, then destroy it. It uses the random provider, which needs no credentials, so it works on any cluster, a laptop k3d one included.

You need kubectl and helm (v3), and a cluster kubectl points at.

1. Install the controller​

helm repo add kubevela https://kubevela.github.io/charts
helm repo update
helm upgrade --install terraform-controller kubevela/terraform-controller \
--version 0.9.1 --namespace terraform --create-namespace \
--set backend.namespace=terraform --wait
kubectl get pods -n terraform
NAME READY STATUS RESTARTS AGE
terraform-controller-d44c4bf5f-9bhjt 1/1 Running 0 13s

backend.namespace=terraform keeps the Terraform state in the controller's namespace; the default, vela-system, only exists alongside KubeVela. On an arm64 machine (an Apple silicon laptop, say), also set terraformImage as Install shows: the default Terraform image is amd64 only.

2. Apply a Configuration​

Save this as random.yaml:

apiVersion: terraform.core.oam.dev/v1beta2
kind: Configuration
metadata:
name: random-id
namespace: default
spec:
hcl: |
resource "random_id" "server" {
byte_length = 8
}

output "random_id" {
value = random_id.server.hex
}
# The random provider takes no credentials, so no Provider object is needed.
inlineCredentials: true
writeConnectionSecretToRef:
name: random-conn
namespace: default
kubectl apply -f random.yaml
kubectl wait configuration/random-id --for=jsonpath='{.status.apply.state}'=Available --timeout=10m -n default
kubectl get configuration random-id -n default

The controller starts a Job that runs terraform init and terraform apply. It shows ProvisioningAndChecking while that runs; the first run pulls the Terraform image and the provider, so give it a minute or two. Available means the apply finished and the outputs are written:

NAME APPLY DESTROY AGE
random-id Available 87s

3. Read the output​

Each Terraform output becomes a key in the connection Secret:

kubectl get secret random-conn -o jsonpath='{.data.random_id}' -n default | base64 -d; echo
8ada6ec5c220af65

The same value is on the Configuration's status:

kubectl get configuration random-id -o jsonpath='{.status.apply.outputs}' -n default; echo
{"random_id":{"value":"8ada6ec5c220af65"}}

Along the way the controller made the objects How It Works describes: the tf-random-id ConfigMap, the variable-random-id Secret and the random-id-apply Job in default, and the state Secret tfstate-default-random-id in terraform.

4. Clean up​

Deleting the Configuration runs terraform destroy, then removes the Secret, the state and the Jobs:

kubectl delete -f random.yaml
helm uninstall terraform-controller -n terraform

Next​