We recommend using Azure Native.
Azure v6.28.0 published on Friday, Oct 3, 2025 by Pulumi
azure.compute.getVirtualMachine
Use this data source to access information about an existing Virtual Machine.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const example = azure.compute.getVirtualMachine({
name: "production",
resourceGroupName: "networking",
});
export const virtualMachineId = example.then(example => example.id);
import pulumi
import pulumi_azure as azure
example = azure.compute.get_virtual_machine(name="production",
resource_group_name="networking")
pulumi.export("virtualMachineId", example.id)
package main
import (
"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/compute"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := compute.LookupVirtualMachine(ctx, &compute.LookupVirtualMachineArgs{
Name: "production",
ResourceGroupName: "networking",
}, nil)
if err != nil {
return err
}
ctx.Export("virtualMachineId", example.Id)
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;
return await Deployment.RunAsync(() =>
{
var example = Azure.Compute.GetVirtualMachine.Invoke(new()
{
Name = "production",
ResourceGroupName = "networking",
});
return new Dictionary<string, object?>
{
["virtualMachineId"] = example.Apply(getVirtualMachineResult => getVirtualMachineResult.Id),
};
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azure.compute.ComputeFunctions;
import com.pulumi.azure.compute.inputs.GetVirtualMachineArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var example = ComputeFunctions.getVirtualMachine(GetVirtualMachineArgs.builder()
.name("production")
.resourceGroupName("networking")
.build());
ctx.export("virtualMachineId", example.id());
}
}
variables:
example:
fn::invoke:
function: azure:compute:getVirtualMachine
arguments:
name: production
resourceGroupName: networking
outputs:
virtualMachineId: ${example.id}
API Providers
This data source uses the following Azure API Providers:
Microsoft.Compute- 2024-03-01
Using getVirtualMachine
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getVirtualMachine(args: GetVirtualMachineArgs, opts?: InvokeOptions): Promise<GetVirtualMachineResult>
function getVirtualMachineOutput(args: GetVirtualMachineOutputArgs, opts?: InvokeOptions): Output<GetVirtualMachineResult>def get_virtual_machine(name: Optional[str] = None,
resource_group_name: Optional[str] = None,
opts: Optional[InvokeOptions] = None) -> GetVirtualMachineResult
def get_virtual_machine_output(name: Optional[pulumi.Input[str]] = None,
resource_group_name: Optional[pulumi.Input[str]] = None,
opts: Optional[InvokeOptions] = None) -> Output[GetVirtualMachineResult]func LookupVirtualMachine(ctx *Context, args *LookupVirtualMachineArgs, opts ...InvokeOption) (*LookupVirtualMachineResult, error)
func LookupVirtualMachineOutput(ctx *Context, args *LookupVirtualMachineOutputArgs, opts ...InvokeOption) LookupVirtualMachineResultOutput> Note: This function is named LookupVirtualMachine in the Go SDK.
public static class GetVirtualMachine
{
public static Task<GetVirtualMachineResult> InvokeAsync(GetVirtualMachineArgs args, InvokeOptions? opts = null)
public static Output<GetVirtualMachineResult> Invoke(GetVirtualMachineInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetVirtualMachineResult> getVirtualMachine(GetVirtualMachineArgs args, InvokeOptions options)
public static Output<GetVirtualMachineResult> getVirtualMachine(GetVirtualMachineArgs args, InvokeOptions options)
fn::invoke:
function: azure:compute/getVirtualMachine:getVirtualMachine
arguments:
# arguments dictionaryThe following arguments are supported:
- Name string
- Specifies the name of the Virtual Machine.
- Resource
Group stringName - Specifies the name of the resource group the Virtual Machine is located in.
- Name string
- Specifies the name of the Virtual Machine.
- Resource
Group stringName - Specifies the name of the resource group the Virtual Machine is located in.
- name String
- Specifies the name of the Virtual Machine.
- resource
Group StringName - Specifies the name of the resource group the Virtual Machine is located in.
- name string
- Specifies the name of the Virtual Machine.
- resource
Group stringName - Specifies the name of the resource group the Virtual Machine is located in.
- name str
- Specifies the name of the Virtual Machine.
- resource_
group_ strname - Specifies the name of the resource group the Virtual Machine is located in.
- name String
- Specifies the name of the Virtual Machine.
- resource
Group StringName - Specifies the name of the resource group the Virtual Machine is located in.
getVirtualMachine Result
The following output properties are available:
- Id string
- The provider-assigned unique ID for this managed resource.
- Identities
List<Get
Virtual Machine Identity> - A
identityblock as defined below. - Location string
- Name string
- Power
State string - The power state of the virtual machine.
- Private
Ip stringAddress - The Primary Private IP Address assigned to this Virtual Machine.
- Private
Ip List<string>Addresses - A list of Private IP Addresses assigned to this Virtual Machine.
- Public
Ip stringAddress - The Primary Public IP Address assigned to this Virtual Machine.
- Public
Ip List<string>Addresses - A list of the Public IP Addresses assigned to this Virtual Machine.
- Resource
Group stringName
- Id string
- The provider-assigned unique ID for this managed resource.
- Identities
[]Get
Virtual Machine Identity - A
identityblock as defined below. - Location string
- Name string
- Power
State string - The power state of the virtual machine.
- Private
Ip stringAddress - The Primary Private IP Address assigned to this Virtual Machine.
- Private
Ip []stringAddresses - A list of Private IP Addresses assigned to this Virtual Machine.
- Public
Ip stringAddress - The Primary Public IP Address assigned to this Virtual Machine.
- Public
Ip []stringAddresses - A list of the Public IP Addresses assigned to this Virtual Machine.
- Resource
Group stringName
- id String
- The provider-assigned unique ID for this managed resource.
- identities
List<Get
Virtual Machine Identity> - A
identityblock as defined below. - location String
- name String
- power
State String - The power state of the virtual machine.
- private
Ip StringAddress - The Primary Private IP Address assigned to this Virtual Machine.
- private
Ip List<String>Addresses - A list of Private IP Addresses assigned to this Virtual Machine.
- public
Ip StringAddress - The Primary Public IP Address assigned to this Virtual Machine.
- public
Ip List<String>Addresses - A list of the Public IP Addresses assigned to this Virtual Machine.
- resource
Group StringName
- id string
- The provider-assigned unique ID for this managed resource.
- identities
Get
Virtual Machine Identity[] - A
identityblock as defined below. - location string
- name string
- power
State string - The power state of the virtual machine.
- private
Ip stringAddress - The Primary Private IP Address assigned to this Virtual Machine.
- private
Ip string[]Addresses - A list of Private IP Addresses assigned to this Virtual Machine.
- public
Ip stringAddress - The Primary Public IP Address assigned to this Virtual Machine.
- public
Ip string[]Addresses - A list of the Public IP Addresses assigned to this Virtual Machine.
- resource
Group stringName
- id str
- The provider-assigned unique ID for this managed resource.
- identities
Sequence[Get
Virtual Machine Identity] - A
identityblock as defined below. - location str
- name str
- power_
state str - The power state of the virtual machine.
- private_
ip_ straddress - The Primary Private IP Address assigned to this Virtual Machine.
- private_
ip_ Sequence[str]addresses - A list of Private IP Addresses assigned to this Virtual Machine.
- public_
ip_ straddress - The Primary Public IP Address assigned to this Virtual Machine.
- public_
ip_ Sequence[str]addresses - A list of the Public IP Addresses assigned to this Virtual Machine.
- resource_
group_ strname
- id String
- The provider-assigned unique ID for this managed resource.
- identities List<Property Map>
- A
identityblock as defined below. - location String
- name String
- power
State String - The power state of the virtual machine.
- private
Ip StringAddress - The Primary Private IP Address assigned to this Virtual Machine.
- private
Ip List<String>Addresses - A list of Private IP Addresses assigned to this Virtual Machine.
- public
Ip StringAddress - The Primary Public IP Address assigned to this Virtual Machine.
- public
Ip List<String>Addresses - A list of the Public IP Addresses assigned to this Virtual Machine.
- resource
Group StringName
Supporting Types
GetVirtualMachineIdentity
- Identity
Ids List<string> - The list of User Managed Identity IDs which are assigned to the Virtual Machine.
- Principal
Id string - The ID of the System Managed Service Principal assigned to the Virtual Machine.
- Tenant
Id string - The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
- Type string
- The identity type of the Managed Identity assigned to the Virtual Machine.
- Identity
Ids []string - The list of User Managed Identity IDs which are assigned to the Virtual Machine.
- Principal
Id string - The ID of the System Managed Service Principal assigned to the Virtual Machine.
- Tenant
Id string - The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
- Type string
- The identity type of the Managed Identity assigned to the Virtual Machine.
- identity
Ids List<String> - The list of User Managed Identity IDs which are assigned to the Virtual Machine.
- principal
Id String - The ID of the System Managed Service Principal assigned to the Virtual Machine.
- tenant
Id String - The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
- type String
- The identity type of the Managed Identity assigned to the Virtual Machine.
- identity
Ids string[] - The list of User Managed Identity IDs which are assigned to the Virtual Machine.
- principal
Id string - The ID of the System Managed Service Principal assigned to the Virtual Machine.
- tenant
Id string - The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
- type string
- The identity type of the Managed Identity assigned to the Virtual Machine.
- identity_
ids Sequence[str] - The list of User Managed Identity IDs which are assigned to the Virtual Machine.
- principal_
id str - The ID of the System Managed Service Principal assigned to the Virtual Machine.
- tenant_
id str - The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
- type str
- The identity type of the Managed Identity assigned to the Virtual Machine.
- identity
Ids List<String> - The list of User Managed Identity IDs which are assigned to the Virtual Machine.
- principal
Id String - The ID of the System Managed Service Principal assigned to the Virtual Machine.
- tenant
Id String - The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
- type String
- The identity type of the Managed Identity assigned to the Virtual Machine.
Package Details
- Repository
- Azure Classic pulumi/pulumi-azure
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
azurermTerraform Provider.
