When I was trying to run
terraform plan in WSL Ubuntu (20.04) it seemed like it had hung. However, when exiting from the process I was receiving the following error:
The error was a red herring as my permissions were OK after double checking in Azure. Turning on the Terraform debug trace feature I found my real clue, and yes, it was DNS 🙂
When editing the /etc/resolve.conf file and restarting the WSL terminal the issue returns. The resolve.conf file is being auto generated on boot, reverting the changes.
To stop this and permanently keep your preferred nameserver entry, run the following commands in the terminal:
sudo rm /etc/resolv.conf sudo bash -c 'echo "nameserver 188.8.131.52" > /etc/resolv.conf' sudo bash -c 'echo "[network]" > /etc/wsl.conf' sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf' sudo chattr +i /etc/resolv.conf
This is removing the existing resolv.conf file, creating a new one and inserting the Google nameserver and then generating a wsl.conf file with the required entries. The last command sets the file attribute +i which means it cannot be modified.
Next, open PowerShell and run:
When relaunching the WSL terminal and running
cat /etc/resolv.conf it’s now retaining the nameserver!
Finally, when runnign
terraform plan it is no longer hanging!
The resolv.conf file there is a message stating to generate wsl.conf within /etc/ however this doesn’t seem to do much. There is a large GitHub issue on this about this https://github.com/microsoft/WSL/issues/5420.
Although not directly related to Terraform, I stumbled across this issue when using WSL and Terraform.
Hope this helps others out there with the same issue!