How to get terraform to generate outputs even when it fails?

I’m trying to use Terraform to generate an AKS private cluster and am having a lot of difficulty, the AKS does spin up but then it always either times out or gives a “Pods not in running status” error. Nobody has ever been able to solve this on the internet before (did a thorough google search) so I’m trying to debug what wrong by taking a look at the cluster’s logs by connecting to it with kubectl.

The cluster does successfully create itself (at least Azure thinks so) so this should be possible. However, here’s the problem: because it’s a private cluster, I can’t access kubectl without using the kubeconfig file which azurerm outputs from the terraform. But the output files won’t generate, because the terraform ended in error. So I’m in a catch 22 here where it’s impossible to debug my cluster and figure out why it’s failing.

Is there a way to “force” terraform to always generate the output files even if the resource fails to create?

Hi @tdevopsottawa,

If terraform apply fails after already performing some operations, there can potentially be a subset of output values saved as long as those output values are derived only from objects which already succeeded. If you have any of those you should be able to see them by running terraform output.

Unfortunately if the output value you want to view is derived from the same resource instance that is producing the error then there will be no way to save and review that output value, because Terraform will only evaluate the output value expression once all of the objects it refers to are ready, and an errored object is never “ready”.

Unfortunately if the output value you want to view is derived from the same resource instance that is producing the error then there will be no way to save and review that output value, because Terraform will only evaluate the output value expression once all of the objects it refers to are ready, and an errored object is never “ready”.

Ok. So that means what I’m trying to do is impossible :frowning: