ArgoCD

This assumes you are using ArgoCD applications to deploy your Terraform operators resource.

Health assesment

By default, ArgoCD will just create the Terraform Operator resource and see that all is well in the world. Except it isn’t actually; until the Terraform operator has said it is.

It is therefore necessary to tell ArgoCD how it must read the status from the Terraform Operator resource.

This is done by making a custom health specification

# Enable the health assessment of terraform
resource.customizations.health.tf.galleybytes.com_Terraform: |
  hs = {}
  hs.status = "Progressing"
  hs.message = ""
  if obj.status ~= nil then
    if obj.status.phase ~= nil then
      if obj.status.phase == "initializing" or obj.status.phase == "running" or obj.status.phase == "initializing-delete" or obj.status.phase == "deleting" then
        if obj.status.stage.state == "failed" then
          hs.status = "Degraded"
        else
          hs.status = "Progressing"
        end
      elseif obj.status.phase == "completed" then
        hs.status = "Healthy"
      else
        hs.status = "Degraded"
      end
    end
    if obj.status.stage ~= nil then
      if obj.status.stage.message ~= nil then
        hs.message = obj.status.stage.message
      end
    end
  end
  return hs  
This configuration goes in the ArgoCD, not the Terraform Operator. See the above link for how to configure `argocd-cm` or if using [helm chart](https://artifacthub.io/packages/helm/argo/argo-cd) to deploy ArgoCD you can set the above with `configs.cm."resource\.customizations\.health\.tf\.galleybytes\.com_Terraform"`.