Debugging in terraform

What is the best way to debug errors in Terraform. I have huge terraform build infrastructure of 2 Azure services

  1. ADB2C
  2. APIM

So the error usually I get is very common. For example, if I am using the below code to create application in ADB2C

resource “azuread_application” “Client_Credentials_Application” {
display_name = var.cc_display_name
sign_in_audience = “AzureADandPersonalMicrosoftAccount”
fallback_public_client_enabled = false

and many more lines inside it, it will just give in the error that this resource is having issue. Now its very difficult to understand the problem since this resource has many other things attached to it. Is there any way where I can get the exact specific error of that particular line which is giving problem?

Hi @syedobaid123,

If the error is coming from Terraform itself, the diagnostic message should show the location of the error. An example of your actual error message would help determine what’s going on.

If the error is coming from the provider, then the provider can indicate which attribute is likely at fault, but that’s not required so Terraform may only be able to point to the resource in general. In most cases the error message is context-specific for the provider from an API request it made, so the issue will have to be investigated from the point of view of making that particular API request, and sometimes the service documentation can help figure out what the error means. If more details of the request are needed, that can often be found in the provider debug logs (I think AzureAD may be logging all API requests and responses)