Is production: true
#issue #azure #dns #wsl #terraform

Title: Terraform Opertaion hangs for Long Time

Created: 31 Mar 2023 Modified: 31 Mar 2023

Description: Are you encountering issues with Terraform and az-cli suddenly breaking during `terraform apply` or `terraform plan`? One possible cause could be a DNS problem, as shown in this article. Learn how to modify the DNS server configuration in your WSL environment and resolve the issue to ensure a smooth Terraform experience.



When working with the terraform of az-cli, it works fine until it suddenly breaks. After that (breaks suddenly), I found terraform only works show success when executing terraform init, but failed on terraform apply or terraform plan. The terraform cli hangs for a long time, and finally, shows an error(attached is the screen capture). It shows like an authentication problem at the head, but it’s a DNS problem which is disclosed at the end of the error.

 Error: Unable to list provider registration status, it is possible that this is due to invalid credentials or the service principal does not have permission to use the Resource Manager API, Azure error: resources.ProvidersClient#List: Failure sending request: StatusCode=0 -- Original Error: Get "https://management.azure.com/subscriptions/4c36ba90-bfa3-49d6-803d-6a9ad9103cc1/providers?api-version=2016-02-01": dial tcp: lookup management.azure.com on 172.21.112.1:53: cannot unmarshal DNS message

image info

The problem solved after viewing the github issue, by modify the dns server config in WSL.

Check the /etc/resolve.conf, which shows the current dns server is pointing to 172.21.112.1.

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.21.112.1

Solved by remark the last line and add a new line to point to other name server.

.
.
# generateResolvConf = false
# nameserver 172.21.112.1
nameserver 8.8.8.8

But why does this happens?
I thought maybe because of some windows WSL problem, but I do not so conform.
One thing to be mentioned is that my windows have an installation of ubuntu 20.04 and then before the terraform DNS break, I installed another WSL of ubuntu 22.04. The initialization of the ubuntu 22.04 maybe also affect the existing running WSL.