I think you may run your terraform code from your local machine. So try to run you code in Azure environment such as Azure cloud shell then you may surprise that your terraform code will work well.
If you still need to run your terraform code from your local machine to provision azure resources. I think you may need to authenicate with service principal so you can follow this https://learn.microsoft.com/en-us/azure/developer/terraform/authenticate-to-azure-with-service-principle?tabs=bash