GalleyBytes / terraform-operator

A Kubernetes CRD to handle terraform operations
http://tf.galleybytes.com
Apache License 2.0
366 stars 47 forks source link

Reconcile behavior #85

Closed Sbou closed 2 years ago

Sbou commented 2 years ago

How reconcile doest it work?

I updated my terraform source but the controller doesn't trigger a new runner. So I delete the last pod and a new one is created but it doesn't get my last commit in the Git branch configured in the TerraformModule field.

I was expecting when I update the terraform source, the controller triiger a new runner with the last commit.

Thank you

isaaguilar commented 2 years ago

The term "reconcile" here sounds like you're updating the terraform module externally (not the TFO resource) and expecting a new build. If this is the case, TFO isn't aware of changes made outside of the k8s cluster.

I do want to point out there is a stub for reconcile that was added years ago. Unfortunately, that feature wasn't added. Issue https://github.com/isaaguilar/terraform-operator/issues/84 is an open discussion on the topic of "reconcile".

Now, what is interesting to me is that you said you have the terraformModule filled in and it's not picking up changes from the module. Maybe you're not pointing to a branch so it's pulling from master all the time. Try pointing to a branch using
?ref=<branch-name> syntax, like:

kind: Terraform
spec:
  ...
  terraformModule: https://github.com/cloudposse/terraform-example-module.git?ref=main  # "main" is the branch

If that works and the branch changes are picked up, you're in a good state to do a reconcile "hack".

Here's how it works:

  1. Terraform Operator starts the terraform workflow when changes are detected on the TFO resource
  2. On an interval, update the TFO resource spec.env with something like a revision number.
  3. Updating the resource will trigger a new build.

Personally, I have used an env like the following to force trigger builds:

kind: Terraform
spec:
  ...
  env:
  - name: _REVISION
    value: "10" # a counter or random string would work
Sbou commented 2 years ago

Thank you for your respnse.

I already target a branch and when I change the TFO resource is OK. I added a new env fiels as you mentioned and it triggers the operator.

Thanks