'Unable to create azura resources using terraform despite being a subscription owner

I cannot create any resource in azure cloud using terraform.

WSL2 - Ubuntu:

             Ubuntu 20.04.3 LTS 

Terraform version:

             Terraform v1.1.5

AZ CLI version:

            "azure-cli": "2.33.0"
            "azure-cli-core": "2.33.0"
            "azure-cli-telemetry": "1.0.6"

At the beggining I login to azure subscription through az login. I have only one available subscription on this account and I am owner.

Then I create "main.tf" file same as here : https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#example-usage

After "terraform init" i do "terraform plan" but i recive that 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/00000000-0000-0000-0000-000000000000/providers?api-version=2016-02-01": dial tcp: lookup management.azure.com on 000.00.000.0:00: cannot unmarshal DNS message

                     with provider["registry.terraform.io/hashicorp/azurerm"],
                     on main.tf line 10, in provider "azurerm":
                     10: provider "azurerm" {

Also i go through this way: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret

My app has contributor/owner priviliges at the subscription level.

Then adding this configuration :

            provider "azurerm" {
               features {}
               subscription_id = "00000000-0000-0000-0000-000000000000"
               client_id       = "00000000-0000-0000-0000-000000000000"
               client_secret   = var.client_secret
               tenant_id       = "00000000-0000-0000-0000-000000000000"
            }

Finally I get the same error. Do you have any ideas?



Solution 1:[1]

sudo vim /etc/resolv.conf

and change nameserver value to 8.8.8.8

It should work, but every time you reboot you should do this action or write a script to automate it!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Csala