i have a terraform code in main.tf and outputs.tf and i have an error about key vault, this section is available on my azure dashboard :
module.virtual_machine.azurerm_key_vault_secret.client_credentials_login: Still creating... [6m20s elapsed]
module.virtual_machine.azurerm_key_vault_secret.client_credentials_password: Still creating... [6m20s elapsed]
│ Error: checking for presence of existing Secret "toto-login" (Key Vault "https://kvapplitest2sbx.vault.azure.net/"): autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: Get "https://kvapplitest2sbx.vault.azure.net/secrets/toto-login/?api-version=7.4": dial tcp: lookup kvapplitest2sbx.vault.azure.net: no such host
│
│ with module.virtual_machine.azurerm_key_vault_secret.client_credentials_login,
│ on ....modulesvirtual_machine14_keyvault.tf line 13, in resource "azurerm_key_vault_secret" "client_credentials_login":
│ 13: resource "azurerm_key_vault_secret" "client_credentials_login" {
│
my file of terraform main.tf is :
terraform {
required_version = ">= 1.0.0"
}
provider "azurerm" {
skip_provider_registration = true
features {}
}
provider "azurerm" {
skip_provider_registration = true
alias = "gallery"
subscription_id = sort(data.azurerm_subscriptions.osfactory.subscriptions.*.subscription_id)[0]
features {}
}
data "azurerm_subscriptions" "osfactory" {
display_name_prefix = "Suez IT OSFactory"
}
data "azurerm_resource_group" "cloud_bundle_rg" {
name = "rg-applitest2-sbx" # To be updated
}
module "virtual_machine" {
source = "../../modules/virtual_machine"
providers = {
azurerm.gallery = azurerm.gallery
}
cloudbundle_info = data.azurerm_resource_group.cloud_bundle_rg
index = 123
size = "Standard_D2s_v3"
os_disk_type = "Standard_LRS"
role = "example"
ad_domain = "green.local"
os = {
type = "Windows"
version = "2022"
}
}
my file outputs.tf is :
output "virtual_machine_outputs" {
value = module.virtual_machine
description = "Virtual machine outputs."
}
can you tell me why there are an error please,
2
Answers
The error message you’re encountering is related to the creation of a secret in Azure Key Vault using Terraform. It seems like Terraform is unable to find the specified Key Vault host, as indicated by the error:
dial tcp: lookup kvapplitest2sbx.vault.azure.net: no such host
.Here are some steps and considerations to troubleshoot this issue:
Verify Key Vault DNS Name: Ensure that the DNS name
kvapplitest2sbx.vault.azure.net
is correct. It’s possible that there is a typo or misconfiguration in the name of the Key Vault.Check Key Vault Existence: Verify that the Key Vault
kvapplitest2sbx
exists in your Azure environment and that it is accessible. You can do this through the Azure Portal or Azure CLI.Network Issues: The error could be due to network-related issues preventing Terraform from accessing the Key Vault URL. Check if there are any network configurations or firewall settings that might be blocking the connection.
Azure Provider Configuration: Your Terraform configuration shows two
provider "azurerm"
blocks with one using an aliasgallery
. Ensure that the Key Vault is accessible under the subscription and context these provider blocks are set to use.Permissions and Access Policies: Ensure that the Terraform service principal (or the account running Terraform) has the necessary permissions to access and manage secrets in the Key Vault. You need to set access policies in Key Vault to allow this.
Terraform State Refresh: Sometimes, Terraform’s state can get out of sync. You can try refreshing the state using the command
terraform refresh
and see if it resolves the issue.Key Vault Secret Resource Configuration: Check the configuration in your
14_keyvault.tf
file to ensure that the resourceazurerm_key_vault_secret
is correctly set up. The error is pointing to this configuration.Review the Terraform Version and Providers: You are using Terraform version
>= 1.0.0
(Up today, the last version is 1.6.4). Ensure that this version is compatible with your AzureRM provider version and the resources you are using. Sometimes, updating to a newer version can resolve unforeseen issues.Azure Service Endpoints: If you are using Azure Service Endpoints or Private Endpoints for Key Vault, ensure they are configured correctly and that Terraform can access them.
If after checking these aspects the issue persists, you might need to look into more detailed logs or consider reaching out to Azure support for more specific guidance, especially if it seems like a network or Azure service-related issue.
The error you’re encountering in your Terraform configuration seems to be related to the Azure Key Vault which indicates a problem with resolving the DNS for the Key Vault service.
The error message "no such host" typically means that the DNS name
kvapplitest2sbx.vault.azure.net
could not be resolved. This could be due to a typo in the Key Vault URL, a misconfiguration in DNS, or an issue with your network connection.My terraform configuration:
main.tf:
/modules/virtual_machine/main.tf:
/modules/virtual_machine/variables.tf:
Output: