Skip to content

Data Source: azurermVirtualMachine

Use this data source to access information about an existing Virtual Machine.

Example Usage

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
new azurerm.provider.AzurermProvider(this, "azurerm", {
  features: [{}],
});
const dataAzurermVirtualMachineExample =
  new azurerm.dataAzurermVirtualMachine.DataAzurermVirtualMachine(
    this,
    "example",
    {
      name: "production",
      resource_group_name: "networking",
    }
  );
new cdktf.TerraformOutput(this, "virtual_machine_id", {
  value: dataAzurermVirtualMachineExample.id,
});

Argument Reference

  • name - Specifies the name of the Virtual Machine.

  • resourceGroupName - Specifies the name of the resource group the Virtual Machine is located in.

Attributes Reference

  • id - The ID of the Virtual Machine.

  • identity - A identity block as defined below.

*

  • privateIpAddress - The Primary Private IP Address assigned to this Virtual Machine.

  • privateIpAddresses - A list of Private IP Addresses assigned to this Virtual Machine.

  • publicIpAddress - The Primary Public IP Address assigned to this Virtual Machine.

  • publicIpAddresses - A list of the Public IP Addresses assigned to this Virtual Machine.

\~> In this release there's a known issue where the publicIpAddress and publicIpAddresses fields may not be fully populated for Dynamic Public IP's.


An identity block exports the following:

  • identityIds - The list of User Managed Identity IDs which are assigned to the Virtual Machine.

  • principalId - The ID of the System Managed Service Principal assigned to the Virtual Machine.

  • tenantId - The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.

  • type - The identity type of the Managed Identity assigned to the Virtual Machine.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • read - (Defaults to 5 minutes) Used when retrieving the Virtual Machine.