Terrafomer Azure import Error --- azurerm_virtual_machine not supported service

127 Views Asked by At

`Hello Team ,

I am trying to import the existing resources running in Azure , In this case in my local windows machine i installed terraformer terraformer-azure-windows-amd64.exe and terraform terraform version Terraform v1.6.5 on windows_386 , provider registry.terraform.io/hashicorp/azurerm v3.0.0 but unfortunately i faced with below error

Error *********************************************************
PS C:\terraformer> .\terraformer-azure-windows-amd64.exe import azure -R dr-rg-infra-northeurope -r azurerm_virtual_machine

2023/12/08 09:13:28 Testing if Obtaining a token from the Azure CLI is applicable for Authentication..
2023/12/08 09:13:28 Using Obtaining a token from the Azure CLI for Authentication
2023/12/08 09:13:29 Getting OAuth config for endpoint https://login.microsoftonline.com/ with  tenant 8eac64b0-XXXXXX
2023/12/08 09:13:29 azurerm importing... azurerm_virtual_machine
2023/12/08 09:13:29 azurerm error importing azurerm_virtual_machine, err: azurerm: azurerm_virtual_machine not supported service

I am trying to import the existing resources running in Azure .In this case in my local windows machine i installed terraformer terraformer-azure-windows-amd64.exe and terraform terraform version Terraform v1.6.5 on windows_386 , provider registry.terraform.io/hashicorp/azurerm v3.0.0 but unfortunately i faced with below error `

1

There are 1 best solutions below

3
Venkat V On
.\terraformer-azure-windows-amd64.exe import azure -R dr-rg-infra-northeurope -r azurerm_virtual_machine

The command you're using to import an existing Azure Virtual Machine is not valid.

To import existing Azure Virtual Machines you have to use VMresource id, refer the Terraform registry.

    terraform {
      required_providers {
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "=3.0.0"
        }
      }
    }
    
    provider "azurerm" {
        features {}
      subscription_id = "xxxxxxxxxxxxxxxx"
      client_id       = "xxxxxxxxxxxxxx"
      tenant_id       = "xxxxxxxxxxxxxxx"
      client_secret   = "xxxxxxxxxxxxxxxxxxxxx"
    }
    
     resource "azurerm_virtual_machine" "example" {
      name                = "venkatvm"
      resource_group_name = "vm-RG"
    }

You can find the Resource ID of the existingVirtual Machine by navigating to your VM, and then selecting the JSON View option.

enter image description here

Import Command

terraform init

terraform import azurerm_virtual_machine.azure_vm  "/subscriptions/xxxxxx6-44fb-b5ba-2b83a074c23f/resourceGroups/<RG_NAMe>/providers/Microsoft.Compute/virtualMachines/TESTVM1"

Response:

enter image description here