A Module from Git
Rather than inline HCL, a Configuration can point at a git repository: remote is the repository, path the directory holding the root module, and gitRef the branch, tag or commit to check out. The controller clones it in an init container before Terraform runs.
This one uses the random module in terraform-controller's own repository, pinned to the v0.9.1 tag, so it needs no credentials and the module can't change under you.
1. Apply it
Save this as remote.yaml:
apiVersion: terraform.core.oam.dev/v1beta2
kind: Configuration
metadata:
name: random-remote
namespace: default
spec:
remote: https://github.com/kubevela/terraform-controller.git
path: examples/tf-native/random
gitRef:
tag: v0.9.1
inlineCredentials: true
writeConnectionSecretToRef:
name: random-remote-conn
namespace: default
kubectl apply -f remote.yaml
kubectl wait configuration/random-remote --for=jsonpath='{.status.apply.state}'=Available --timeout=10m -n default
kubectl get configuration random-remote -n default
NAME APPLY DESTROY AGE
random-remote Available 36s
2. Check what ran
The apply Job's pod clones the repository in its git-configuration init container:
kubectl logs job/random-remote-apply -c git-configuration -n default
Cloning into '/opt/tf-backend'...
Terraform's own output is in the main container, terraform-executor (it is coloured; | sed 's/\x1b\[[0-9;]*m//g' strips the escapes):
kubectl logs job/random-remote-apply -c terraform-executor -n default | tail -6
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
random_id = "b489e985fcee6157"
And the output in the connection Secret:
kubectl get secret random-remote-conn -o jsonpath='{.data.random_id}' -n default | base64 -d; echo
b489e985fcee6157
3. Clean up
kubectl delete -f remote.yaml
Notes
remotetakes a public repository over HTTPS. For a private one, use an SSH URL andgitCredentialsSecretReference, naming the Secret'snameandnamespace, where the namespace is the one the Terraform Jobs run in (the Configuration's own, orcontrollerNamespacewhen that's set), with the private key underssh-privatekey(thekubernetes.io/ssh-authlayout) and the host's key underknown_hosts.gitReftakes one ofbranch,tagorcommit. Without it, the default branch is cloned, so a change to the repository changes what the next apply runs.- A KubeVela component type does the same with
schematic.terraform.type: remote,configuration: <repository URL>andpath: see Extend Cloud Resources.