Terraform console output generally provides all the feedback I need for execution status. But recent deployment of an Azure App Service Environment returned this gem:
Error: Error creating App Service Environment "appServiceEnvironment" (Resource Group "rg-ase-example"): web.AppServiceEnvironmentsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
on ..\..\main.tf line 76, in resource "azurerm_app_service_environment" "this":
76: resource "azurerm_app_service_environment" "this" {
Not the most descriptive error. A quick web search revealed Issue #6796 of the AzureRM provider. The issue doesn’t explain my particular problem, but hints that logging may reveal more details about my error (and the Dev team is already aware of the general problem - +1).
Terraform Logs
Debugging Terraform provides full information on configuring logs and interpreting crash logs.
Terraform doesn’t provide user logs by default, but you can quickly configure them when needed. Two environment variables control logging:
TF_LOG
sets the logging level desired, and enables logging when it existsTF_LOG_PATH
Indicates the full path and file to use for dumping logs to a file
I configured my logs for TRACE level - let’s see everything and be done with it! Dumped them out to a file so I could parse at my leisure. My workstation runs Windows in this environment so I set the environment variables in PowerShell.
PS L:\source\ase\terraform\examples\basic_deploy> $env:TF_LOG="TRACE"
PS L:\source\ase\terraform\examples\basic_deploy> $ENV:TF_LOG_PATH="l:\logs\tf.log"
With logging configured I re-ran terraform plan
and terraform apply
to reproduce the issue. My execution resulted in a short log because I deployed a small test environment, and this re-run only needed to deploy the ASE. I manually skimmed the log to find the error.
2020-11-20T09:00:08.640-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.37.0_x5.exe: {"Code":"Conflict","Message":"A stamp with the specified name already exists in the location appServiceEnvironment.","Target":null,"Details":[{"Message":"A stamp with the specified name already exists in the location appServiceEnvironment."},{"Code":"Conflict"},{"ErrorEntity": {"ExtendedCode":"57005","MessageTemplate":"A stamp with the specified name already exists in the location {0}.","Parameters":["appServiceEnvironment"],"Code":"Conflict","Message":"A stamp with the specified name already exists in the location appServiceEnvironment."}}], "Innererror":null}
2020/11/20 09:00:08 [DEBUG] module.ase.azurerm_app_service_environment.this: apply errored, but we're indicating that via the Error pointer rather than returning it: Error creating App Service Environment "appServiceEnvironment" (Resource Group "rg-ase-example"): web. AppServiceEnvironmentsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
This output clearly shows my error. Another ASE with the same name already exists - Oops! Fortunately I can quickly change the name variable for deployment.