Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform doesn't work in wsl to provision azure resource #30588

Closed
backwind1233 opened this issue Feb 28, 2022 · 2 comments
Closed

Terraform doesn't work in wsl to provision azure resource #30588

backwind1233 opened this issue Feb 28, 2022 · 2 comments
Labels
bug new new issue not yet triaged

Comments

@backwind1233
Copy link

backwind1233 commented Feb 28, 2022

Terraform Version

Terraform v1.1.3
on linux_amd64

Terraform Configuration Files

here is the link of terraform scripts.

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.75"
    }
    azurecaf = {
      source  = "aztfmod/azurecaf"
      version = "1.2.10"
    }
  }
}

provider "azurerm" {
  features {}
}

// ===========resource_group===========
resource "azurecaf_name" "resource_group" {
  name          = var.application_name
  resource_type = "azurerm_resource_group"
  random_length = 5
  clean_input   = true
}

resource "azurerm_resource_group" "main" {
  name     = azurecaf_name.resource_group.result
  location = var.location

  tags = {
    "terraform"                 = "true"
    "application-name"          = var.application_name
    "spring-cloud-azure-sample" = var.sample_tag_value
  }
}

data "azurerm_client_config" "current" {
}

// ===========azurerm_key_vault===========
resource "azurecaf_name" "kv" {
  name          = var.application_name
  resource_type = "azurerm_key_vault"
  random_length = 5
  clean_input   = true
}

resource "azurerm_key_vault" "kv_account" {
  name                        = azurecaf_name.kv.result
  location                    = azurerm_resource_group.main.location
  resource_group_name         = azurerm_resource_group.main.name
  enabled_for_disk_encryption = true
  tenant_id                   = data.azurerm_client_config.current.tenant_id
  soft_delete_retention_days  = 7
  purge_protection_enabled    = false

  sku_name = "standard"

  access_policy {
    tenant_id = data.azurerm_client_config.current.tenant_id
    object_id = data.azurerm_client_config.current.object_id

    secret_permissions = [
      "Get",
      "List",
      "Set",
      "Purge",
      "Delete"
    ]
  }

  tags = {
    "terraform"                 = "true"
    "spring-cloud-azure-sample" = var.sample_tag_value
  }
}

resource "azurerm_key_vault_secret" "kv" {
  name         = "sampleProperty"
  value        = "kv: sampleProperty: value"
  key_vault_id = azurerm_key_vault.kv_account.id
}

Debug Output

With export TF_LOG=TRACE, the Error stack shows below:


2022-02-28T22:41:24.929+0800 [DEBUG] provider.terraform-provider-azurerm_v2.90.0_x5: Genereated Provider Correlation Request Id: cecc0d0d-8f1c-dc10-17f3-2443e2767ac6: timestamp=2022-02-28T22:41:24.929+0800
2022-02-28T22:41:25.178+0800 [DEBUG] provider.terraform-provider-azurerm_v2.90.0_x5: error retrieving locations: retrieving supported locations from Azure MetaData service: Get "https://management.azure
.com//metadata/endpoints?api-version=2018-01-01": dial tcp: lookup management.azure.com on 172.31.112.1:53: cannot unmarshal DNS message. Enhanced validation will be unavailable: timestamp=2022-02-28T22
:41:25.178+0800
2022-02-28T22:41:25.181+0800 [DEBUG] provider.terraform-provider-azurerm_v2.90.0_x5: AzureRM Request:
GET /subscriptions/799c12ba-353c-44a1-883d-84808ebb2216/providers?api-version=2016-02-01 HTTP/1.1
Host: management.azure.com
User-Agent: Go/go1.17.3 (amd64-linux) go-autorest/v14.2.1 Azure-SDK-For-Go/v59.3.0 resources/2016-02-01 HashiCorp Terraform/1.1.3 (+https://www.terraform.io) Terraform Plugin SDK/2.10.0 terraform-provid
er-azurerm/2.90.0 pid-222c6c49-1b0a-5959-a213-6608f9eb8820
X-Ms-Correlation-Request-Id: cecc0d0d-8f1c-dc10-17f3-2443e2767ac6
Accept-Encoding: gzip: timestamp=2022-02-28T22:41:25.181+0800
2022-02-28T22:41:25.183+0800 [DEBUG] provider.terraform-provider-azurerm_v2.90.0_x5: AzureRM Response Error: Get "https://management.azure.com/subscriptions/799c12ba-353c-44a1-883d-84808ebb2216/provider
s?api-version=2016-02-01": dial tcp: lookup management.azure.com on 172.31.112.1:53: cannot unmarshal DNS message for https://management.azure.com/subscriptions/799c12ba-353c-44a1-883d-84808ebb2216/prov
iders?api-version=2016-02-01: timestamp=2022-02-28T22:41:25.183+0800

the whole Gist containing the debug output is linked here.

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

References

Sample can not work when running terraform scripts in WSL environment, but it works in PowerShell, macOS, and Linux.

can anyone help me with this issue?

@backwind1233 backwind1233 added bug new new issue not yet triaged labels Feb 28, 2022
@backwind1233 backwind1233 changed the title Terraform doesn't work in wsl Terraform doesn't work in wsl to provision azure resource Feb 28, 2022
@jbardin
Copy link
Member

jbardin commented Feb 28, 2022

Hi @backwind1233,

The error you're seeing here is from the azurerm provider, not from Terraform, but unfortunately it is likely not something the provider can directly control either. There is an open issue with WSL regarding their resolver responses here, which appears to be the cause of the problem you are seeing.

Since there's nothing we can change within Terraform to avoid the problem, I'm going to close this issue. There may be a workaround coming in the go1.18 release, but that would require a new release of the provider to implement.

Thanks!

@jbardin jbardin closed this as completed Feb 28, 2022
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants