<p>I'm using the below Terraform file to create an AKS cluster:</p>
<pre><code>resource &quot;random_pet&quot; &quot;prefix&quot; {}

resource &quot;kubernetes_persistent_volume&quot; &quot;example&quot; {
  metadata {
    name = &quot;example&quot;
  }
  spec {
    capacity = {
      storage = &quot;1Gi&quot;
    }
    access_modes = [&quot;ReadWriteOnce&quot;]
    persistent_volume_source {
      azure_disk {
        caching_mode  = &quot;None&quot;
        data_disk_uri = azurerm_managed_disk.example.id
        disk_name     = &quot;example&quot;
        kind          = &quot;Managed&quot;
      }
    }
  }
}

resource &quot;azurerm_kubernetes_cluster&quot; &quot;example&quot; {
  name                = &quot;${random_pet.prefix.id}-aks&quot;
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  dns_prefix          = &quot;${random_pet.prefix.id}-k8s&quot;

  default_node_pool {
    name            = &quot;example&quot;
    node_count      = 2
    vm_size         = &quot;Standard_D2_v2&quot;
    os_disk_size_gb = 30
  }

  identity {
    type = &quot;SystemAssigned&quot;
  }

  role_based_access_control {
    enabled = true
  }

  addon_profile {
    kube_dashboard {
      enabled = true
    }
  }

  tags = {
    environment = &quot;Demo&quot;
  }
}

provider &quot;azurerm&quot; {
  version = &quot;&gt;=2.20.0&quot;
  features {}
}

resource &quot;azurerm_resource_group&quot; &quot;example&quot; {
  name     = &quot;${random_pet.prefix.id}-rg&quot;
  location = &quot;westus2&quot;
}


resource &quot;azurerm_managed_disk&quot; &quot;example&quot; {
  name                 = &quot;example&quot;
  location             = azurerm_resource_group.example.location
  resource_group_name  = azurerm_resource_group.example.name
  storage_account_type = &quot;Standard_LRS&quot;
  create_option        = &quot;Empty&quot;
  disk_size_gb         = &quot;1&quot;
  tags = {
    environment = azurerm_resource_group.example.name
  }
}
</code></pre>
<p>I've derived the above file from Terraform's tutorial on setting up an AKS cluster: <a href="https://learn.hashicorp.com/tutorials/terraform/aks" rel="nofollow noreferrer">https://learn.hashicorp.com/tutorials/terraform/aks</a></p>
<p>And I've used Terraform's example of setting up an Azure managed disk and k8s volume here: <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/persistent_volume" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/persistent_volume</a></p>
<p>When I try to run the above config with Terraform I get the following error:</p>
<pre><code>Error: Post &quot;https://pumped-llama-k8s-419df981.hcp.westus2.azmk8s.io:443/api/v1/persistentvolumes&quot;: dial tcp: lookup pumped-llama-k8s-419df981.hcp.westus2.azmk8s.io on 192.168.1.1:53: no such host

  on main.tf line 3, in resource &quot;kubernetes_persistent_volume&quot; &quot;example&quot;:
   3: resource &quot;kubernetes_persistent_volume&quot; &quot;example&quot; {
</code></pre>
<p>I get this same error whenever I attempt to use any non-<code>azurerm</code> Terraform resource. Eg. when trying to configure roles and role binding: <code>resource &quot;kubernetes_role&quot;</code></p>
<p>I'm assuming by the error message's url - trying to connect to HashiCorp Cloud Platform, which I assume is the default - that I need to explicitly tell these non-<code>azurerm</code> resources that I am connecting to an Azure hosted Kubernetes; however I can't figure out how to do that.</p>

Sam Carswell
<p>Turns out I needed to define the <code>kubernetes</code> provider in the Terraform file - surprised I wouldn't get some kind of a warning for not including it, considering I'm interacting with it's resources.</p>
<p>Here's what I did to fix it:</p>
<p>outputs.tf:</p>
<pre class="lang-yaml prettyprint-override"><code>output &quot;host&quot; {
  value = azurerm_kubernetes_cluster.default.kube_config.0.host
}

output &quot;client_key&quot; {
  value = azurerm_kubernetes_cluster.default.kube_config.0.client_key
}

output &quot;client_certificate&quot; {
  value = azurerm_kubernetes_cluster.default.kube_config.0.client_certificate
}

output &quot;kube_config&quot; {
  value = azurerm_kubernetes_cluster.default.kube_config_raw
}

output &quot;cluster_ca_certificate&quot; {
  value = azurerm_kubernetes_cluster.default.kube_config.0.cluster_ca_certificate
}

</code></pre>
<p>main.tf:</p>
<pre class="lang-yaml prettyprint-override"><code>...
provider &quot;kubernetes&quot; {
  version = &quot;=1.13.2&quot;
  load_config_file = &quot;false&quot;

  host = azurerm_kubernetes_cluster.default.kube_config.0.host
  
  client_certificate     = &quot;${base64decode(azurerm_kubernetes_cluster.default.kube_config.0.client_certificate)}&quot;
  client_key             = &quot;${base64decode(azurerm_kubernetes_cluster.default.kube_config.0.client_key)}&quot;
  cluster_ca_certificate = &quot;${base64decode(azurerm_kubernetes_cluster.default.kube_config.0.cluster_ca_certificate)}&quot;
}
...
</code></pre>
