1. Packages
  2. Azure Classic
  3. API Docs
  4. compute
  5. getVirtualMachine

We recommend using Azure Native.

Azure v6.22.0 published on Tuesday, Apr 1, 2025 by Pulumi

azure.compute.getVirtualMachine

Explore with Pulumi AI

We recommend using Azure Native.

Azure v6.22.0 published on Tuesday, Apr 1, 2025 by Pulumi

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);
Copy
import pulumi
import pulumi_azure as azure

example = azure.compute.get_virtual_machine(name="production",
    resource_group_name="networking")
pulumi.export("virtualMachineId", example.id)
Copy
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
	})
}
Copy
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),
    };
});
Copy
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.applyValue(getVirtualMachineResult -> getVirtualMachineResult.id()));
    }
}
Copy
variables:
  example:
    fn::invoke:
      function: azure:compute:getVirtualMachine
      arguments:
        name: production
        resourceGroupName: networking
outputs:
  virtualMachineId: ${example.id}
Copy

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>
Copy
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]
Copy
func LookupVirtualMachine(ctx *Context, args *LookupVirtualMachineArgs, opts ...InvokeOption) (*LookupVirtualMachineResult, error)
func LookupVirtualMachineOutput(ctx *Context, args *LookupVirtualMachineOutputArgs, opts ...InvokeOption) LookupVirtualMachineResultOutput
Copy

> 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)
}
Copy
public static CompletableFuture<GetVirtualMachineResult> getVirtualMachine(GetVirtualMachineArgs args, InvokeOptions options)
public static Output<GetVirtualMachineResult> getVirtualMachine(GetVirtualMachineArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: azure:compute/getVirtualMachine:getVirtualMachine
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Name This property is required. string
Specifies the name of the Virtual Machine.
ResourceGroupName This property is required. string
Specifies the name of the resource group the Virtual Machine is located in.
Name This property is required. string
Specifies the name of the Virtual Machine.
ResourceGroupName This property is required. string
Specifies the name of the resource group the Virtual Machine is located in.
name This property is required. String
Specifies the name of the Virtual Machine.
resourceGroupName This property is required. String
Specifies the name of the resource group the Virtual Machine is located in.
name This property is required. string
Specifies the name of the Virtual Machine.
resourceGroupName This property is required. string
Specifies the name of the resource group the Virtual Machine is located in.
name This property is required. str
Specifies the name of the Virtual Machine.
resource_group_name This property is required. str
Specifies the name of the resource group the Virtual Machine is located in.
name This property is required. String
Specifies the name of the Virtual Machine.
resourceGroupName This property is required. String
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<GetVirtualMachineIdentity>
A identity block as defined below.
Location string
Name string
PowerState string
The power state of the virtual machine.
PrivateIpAddress string
The Primary Private IP Address assigned to this Virtual Machine.
PrivateIpAddresses List<string>
A list of Private IP Addresses assigned to this Virtual Machine.
PublicIpAddress string
The Primary Public IP Address assigned to this Virtual Machine.
PublicIpAddresses List<string>
A list of the Public IP Addresses assigned to this Virtual Machine.
ResourceGroupName string
Id string
The provider-assigned unique ID for this managed resource.
Identities []GetVirtualMachineIdentity
A identity block as defined below.
Location string
Name string
PowerState string
The power state of the virtual machine.
PrivateIpAddress string
The Primary Private IP Address assigned to this Virtual Machine.
PrivateIpAddresses []string
A list of Private IP Addresses assigned to this Virtual Machine.
PublicIpAddress string
The Primary Public IP Address assigned to this Virtual Machine.
PublicIpAddresses []string
A list of the Public IP Addresses assigned to this Virtual Machine.
ResourceGroupName string
id String
The provider-assigned unique ID for this managed resource.
identities List<GetVirtualMachineIdentity>
A identity block as defined below.
location String
name String
powerState String
The power state of the virtual machine.
privateIpAddress String
The Primary Private IP Address assigned to this Virtual Machine.
privateIpAddresses List<String>
A list of Private IP Addresses assigned to this Virtual Machine.
publicIpAddress String
The Primary Public IP Address assigned to this Virtual Machine.
publicIpAddresses List<String>
A list of the Public IP Addresses assigned to this Virtual Machine.
resourceGroupName String
id string
The provider-assigned unique ID for this managed resource.
identities GetVirtualMachineIdentity[]
A identity block as defined below.
location string
name string
powerState string
The power state of the virtual machine.
privateIpAddress string
The Primary Private IP Address assigned to this Virtual Machine.
privateIpAddresses string[]
A list of Private IP Addresses assigned to this Virtual Machine.
publicIpAddress string
The Primary Public IP Address assigned to this Virtual Machine.
publicIpAddresses string[]
A list of the Public IP Addresses assigned to this Virtual Machine.
resourceGroupName string
id str
The provider-assigned unique ID for this managed resource.
identities Sequence[GetVirtualMachineIdentity]
A identity block as defined below.
location str
name str
power_state str
The power state of the virtual machine.
private_ip_address str
The Primary Private IP Address assigned to this Virtual Machine.
private_ip_addresses Sequence[str]
A list of Private IP Addresses assigned to this Virtual Machine.
public_ip_address str
The Primary Public IP Address assigned to this Virtual Machine.
public_ip_addresses Sequence[str]
A list of the Public IP Addresses assigned to this Virtual Machine.
resource_group_name str
id String
The provider-assigned unique ID for this managed resource.
identities List<Property Map>
A identity block as defined below.
location String
name String
powerState String
The power state of the virtual machine.
privateIpAddress String
The Primary Private IP Address assigned to this Virtual Machine.
privateIpAddresses List<String>
A list of Private IP Addresses assigned to this Virtual Machine.
publicIpAddress String
The Primary Public IP Address assigned to this Virtual Machine.
publicIpAddresses List<String>
A list of the Public IP Addresses assigned to this Virtual Machine.
resourceGroupName String

Supporting Types

GetVirtualMachineIdentity

IdentityIds This property is required. List<string>
The list of User Managed Identity IDs which are assigned to the Virtual Machine.
PrincipalId This property is required. string
The ID of the System Managed Service Principal assigned to the Virtual Machine.
TenantId This property is required. string
The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
Type This property is required. string
The identity type of the Managed Identity assigned to the Virtual Machine.
IdentityIds This property is required. []string
The list of User Managed Identity IDs which are assigned to the Virtual Machine.
PrincipalId This property is required. string
The ID of the System Managed Service Principal assigned to the Virtual Machine.
TenantId This property is required. string
The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
Type This property is required. string
The identity type of the Managed Identity assigned to the Virtual Machine.
identityIds This property is required. List<String>
The list of User Managed Identity IDs which are assigned to the Virtual Machine.
principalId This property is required. String
The ID of the System Managed Service Principal assigned to the Virtual Machine.
tenantId This property is required. String
The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
type This property is required. String
The identity type of the Managed Identity assigned to the Virtual Machine.
identityIds This property is required. string[]
The list of User Managed Identity IDs which are assigned to the Virtual Machine.
principalId This property is required. string
The ID of the System Managed Service Principal assigned to the Virtual Machine.
tenantId This property is required. string
The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
type This property is required. string
The identity type of the Managed Identity assigned to the Virtual Machine.
identity_ids This property is required. Sequence[str]
The list of User Managed Identity IDs which are assigned to the Virtual Machine.
principal_id This property is required. str
The ID of the System Managed Service Principal assigned to the Virtual Machine.
tenant_id This property is required. str
The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
type This property is required. str
The identity type of the Managed Identity assigned to the Virtual Machine.
identityIds This property is required. List<String>
The list of User Managed Identity IDs which are assigned to the Virtual Machine.
principalId This property is required. String
The ID of the System Managed Service Principal assigned to the Virtual Machine.
tenantId This property is required. String
The ID of the Tenant of the System Managed Service Principal assigned to the Virtual Machine.
type This property is required. 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 azurerm Terraform Provider.

We recommend using Azure Native.

Azure v6.22.0 published on Tuesday, Apr 1, 2025 by Pulumi