1. Packages
  2. Nsxt Provider
  3. API Docs
  4. getPolicyVms
nsxt 3.8.0 published on Monday, Apr 14, 2025 by vmware

nsxt.getPolicyVms

Explore with Pulumi AI

This data source provides map of all Policy based Virtual Machines (VMs) listed in NSX inventory, and allows look-up of the VM by display_name in the map. Value of the map would provide one of VM ID types, according to value_type argument.

This data source is applicable to NSX Policy Manager and VMC.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as nsxt from "@pulumi/nsxt";

const all = nsxt.getPolicyVms({
    state: "running",
    guestOs: "ubuntu",
    valueType: "bios_id",
});
const test = new nsxt.PolicyVmTags("test", {
    instanceId: all.then(all => all.items?.["vm-1"]),
    tags: [{
        scope: "color",
        tag: "blue",
    }],
});
Copy
import pulumi
import pulumi_nsxt as nsxt

all = nsxt.get_policy_vms(state="running",
    guest_os="ubuntu",
    value_type="bios_id")
test = nsxt.PolicyVmTags("test",
    instance_id=all.items["vm-1"],
    tags=[{
        "scope": "color",
        "tag": "blue",
    }])
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/nsxt/v3/nsxt"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		all, err := nsxt.GetPolicyVms(ctx, &nsxt.GetPolicyVmsArgs{
			State:     pulumi.StringRef("running"),
			GuestOs:   pulumi.StringRef("ubuntu"),
			ValueType: pulumi.StringRef("bios_id"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = nsxt.NewPolicyVmTags(ctx, "test", &nsxt.PolicyVmTagsArgs{
			InstanceId: pulumi.String(all.Items.Vm1),
			Tags: nsxt.PolicyVmTagsTagArray{
				&nsxt.PolicyVmTagsTagArgs{
					Scope: pulumi.String("color"),
					Tag:   pulumi.String("blue"),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Nsxt = Pulumi.Nsxt;

return await Deployment.RunAsync(() => 
{
    var all = Nsxt.GetPolicyVms.Invoke(new()
    {
        State = "running",
        GuestOs = "ubuntu",
        ValueType = "bios_id",
    });

    var test = new Nsxt.PolicyVmTags("test", new()
    {
        InstanceId = all.Apply(getPolicyVmsResult => getPolicyVmsResult.Items?.Vm_1),
        Tags = new[]
        {
            new Nsxt.Inputs.PolicyVmTagsTagArgs
            {
                Scope = "color",
                Tag = "blue",
            },
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.nsxt.NsxtFunctions;
import com.pulumi.nsxt.inputs.GetPolicyVmsArgs;
import com.pulumi.nsxt.PolicyVmTags;
import com.pulumi.nsxt.PolicyVmTagsArgs;
import com.pulumi.nsxt.inputs.PolicyVmTagsTagArgs;
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 all = NsxtFunctions.getPolicyVms(GetPolicyVmsArgs.builder()
            .state("running")
            .guestOs("ubuntu")
            .valueType("bios_id")
            .build());

        var test = new PolicyVmTags("test", PolicyVmTagsArgs.builder()
            .instanceId(all.applyValue(getPolicyVmsResult -> getPolicyVmsResult.items().vm-1()))
            .tags(PolicyVmTagsTagArgs.builder()
                .scope("color")
                .tag("blue")
                .build())
            .build());

    }
}
Copy
resources:
  test:
    type: nsxt:PolicyVmTags
    properties:
      instanceId: ${all.items"vm-1"[%!s(MISSING)]}
      tags:
        - scope: color
          tag: blue
variables:
  all:
    fn::invoke:
      function: nsxt:getPolicyVms
      arguments:
        state: running
        guestOs: ubuntu
        valueType: bios_id
Copy

Multi-Tenancy

import * as pulumi from "@pulumi/pulumi";
import * as nsxt from "@pulumi/nsxt";

const demoproj = nsxt.getPolicyProject({
    displayName: "demoproj",
});
const all = demoproj.then(demoproj => nsxt.getPolicyVms({
    context: {
        projectId: demoproj.id,
    },
    state: "running",
    guestOs: "ubuntu",
    valueType: "bios_id",
}));
const test = new nsxt.PolicyVmTags("test", {
    context: {
        projectId: demoproj.then(demoproj => demoproj.id),
    },
    instanceId: all.then(all => all.items?.["vm-1"]),
    tags: [{
        scope: "color",
        tag: "blue",
    }],
});
Copy
import pulumi
import pulumi_nsxt as nsxt

demoproj = nsxt.get_policy_project(display_name="demoproj")
all = nsxt.get_policy_vms(context={
        "project_id": demoproj.id,
    },
    state="running",
    guest_os="ubuntu",
    value_type="bios_id")
test = nsxt.PolicyVmTags("test",
    context={
        "project_id": demoproj.id,
    },
    instance_id=all.items["vm-1"],
    tags=[{
        "scope": "color",
        "tag": "blue",
    }])
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/nsxt/v3/nsxt"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		demoproj, err := nsxt.LookupPolicyProject(ctx, &nsxt.LookupPolicyProjectArgs{
			DisplayName: pulumi.StringRef("demoproj"),
		}, nil)
		if err != nil {
			return err
		}
		all, err := nsxt.GetPolicyVms(ctx, &nsxt.GetPolicyVmsArgs{
			Context: nsxt.GetPolicyVmsContext{
				ProjectId: demoproj.Id,
			},
			State:     pulumi.StringRef("running"),
			GuestOs:   pulumi.StringRef("ubuntu"),
			ValueType: pulumi.StringRef("bios_id"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = nsxt.NewPolicyVmTags(ctx, "test", &nsxt.PolicyVmTagsArgs{
			Context: &nsxt.PolicyVmTagsContextArgs{
				ProjectId: pulumi.String(demoproj.Id),
			},
			InstanceId: pulumi.String(all.Items.Vm1),
			Tags: nsxt.PolicyVmTagsTagArray{
				&nsxt.PolicyVmTagsTagArgs{
					Scope: pulumi.String("color"),
					Tag:   pulumi.String("blue"),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Nsxt = Pulumi.Nsxt;

return await Deployment.RunAsync(() => 
{
    var demoproj = Nsxt.GetPolicyProject.Invoke(new()
    {
        DisplayName = "demoproj",
    });

    var all = Nsxt.GetPolicyVms.Invoke(new()
    {
        Context = new Nsxt.Inputs.GetPolicyVmsContextInputArgs
        {
            ProjectId = demoproj.Apply(getPolicyProjectResult => getPolicyProjectResult.Id),
        },
        State = "running",
        GuestOs = "ubuntu",
        ValueType = "bios_id",
    });

    var test = new Nsxt.PolicyVmTags("test", new()
    {
        Context = new Nsxt.Inputs.PolicyVmTagsContextArgs
        {
            ProjectId = demoproj.Apply(getPolicyProjectResult => getPolicyProjectResult.Id),
        },
        InstanceId = all.Apply(getPolicyVmsResult => getPolicyVmsResult.Items?.Vm_1),
        Tags = new[]
        {
            new Nsxt.Inputs.PolicyVmTagsTagArgs
            {
                Scope = "color",
                Tag = "blue",
            },
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.nsxt.NsxtFunctions;
import com.pulumi.nsxt.inputs.GetPolicyProjectArgs;
import com.pulumi.nsxt.inputs.GetPolicyVmsArgs;
import com.pulumi.nsxt.inputs.GetPolicyVmsContextArgs;
import com.pulumi.nsxt.PolicyVmTags;
import com.pulumi.nsxt.PolicyVmTagsArgs;
import com.pulumi.nsxt.inputs.PolicyVmTagsContextArgs;
import com.pulumi.nsxt.inputs.PolicyVmTagsTagArgs;
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 demoproj = NsxtFunctions.getPolicyProject(GetPolicyProjectArgs.builder()
            .displayName("demoproj")
            .build());

        final var all = NsxtFunctions.getPolicyVms(GetPolicyVmsArgs.builder()
            .context(GetPolicyVmsContextArgs.builder()
                .projectId(demoproj.applyValue(getPolicyProjectResult -> getPolicyProjectResult.id()))
                .build())
            .state("running")
            .guestOs("ubuntu")
            .valueType("bios_id")
            .build());

        var test = new PolicyVmTags("test", PolicyVmTagsArgs.builder()
            .context(PolicyVmTagsContextArgs.builder()
                .projectId(demoproj.applyValue(getPolicyProjectResult -> getPolicyProjectResult.id()))
                .build())
            .instanceId(all.applyValue(getPolicyVmsResult -> getPolicyVmsResult.items().vm-1()))
            .tags(PolicyVmTagsTagArgs.builder()
                .scope("color")
                .tag("blue")
                .build())
            .build());

    }
}
Copy
resources:
  test:
    type: nsxt:PolicyVmTags
    properties:
      context:
        projectId: ${demoproj.id}
      instanceId: ${all.items"vm-1"[%!s(MISSING)]}
      tags:
        - scope: color
          tag: blue
variables:
  demoproj:
    fn::invoke:
      function: nsxt:getPolicyProject
      arguments:
        displayName: demoproj
  all:
    fn::invoke:
      function: nsxt:getPolicyVms
      arguments:
        context:
          projectId: ${demoproj.id}
        state: running
        guestOs: ubuntu
        valueType: bios_id
Copy

Using getPolicyVms

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 getPolicyVms(args: GetPolicyVmsArgs, opts?: InvokeOptions): Promise<GetPolicyVmsResult>
function getPolicyVmsOutput(args: GetPolicyVmsOutputArgs, opts?: InvokeOptions): Output<GetPolicyVmsResult>
Copy
def get_policy_vms(context: Optional[GetPolicyVmsContext] = None,
                   guest_os: Optional[str] = None,
                   id: Optional[str] = None,
                   state: Optional[str] = None,
                   value_type: Optional[str] = None,
                   opts: Optional[InvokeOptions] = None) -> GetPolicyVmsResult
def get_policy_vms_output(context: Optional[pulumi.Input[GetPolicyVmsContextArgs]] = None,
                   guest_os: Optional[pulumi.Input[str]] = None,
                   id: Optional[pulumi.Input[str]] = None,
                   state: Optional[pulumi.Input[str]] = None,
                   value_type: Optional[pulumi.Input[str]] = None,
                   opts: Optional[InvokeOptions] = None) -> Output[GetPolicyVmsResult]
Copy
func GetPolicyVms(ctx *Context, args *GetPolicyVmsArgs, opts ...InvokeOption) (*GetPolicyVmsResult, error)
func GetPolicyVmsOutput(ctx *Context, args *GetPolicyVmsOutputArgs, opts ...InvokeOption) GetPolicyVmsResultOutput
Copy

> Note: This function is named GetPolicyVms in the Go SDK.

public static class GetPolicyVms 
{
    public static Task<GetPolicyVmsResult> InvokeAsync(GetPolicyVmsArgs args, InvokeOptions? opts = null)
    public static Output<GetPolicyVmsResult> Invoke(GetPolicyVmsInvokeArgs args, InvokeOptions? opts = null)
}
Copy
public static CompletableFuture<GetPolicyVmsResult> getPolicyVms(GetPolicyVmsArgs args, InvokeOptions options)
public static Output<GetPolicyVmsResult> getPolicyVms(GetPolicyVmsArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: nsxt:index/getPolicyVms:getPolicyVms
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Context GetPolicyVmsContext
The context which the object belongs to
GuestOs string
Filter results by operating system of the machine. The match is case insensitive and prefix-based.
Id string
State string
Filter results by power state of the machine.
ValueType string
Type of VM ID the user is interested in. Possible values are bios_id, external_id, instance_id. Default is bios_id.
Context GetPolicyVmsContext
The context which the object belongs to
GuestOs string
Filter results by operating system of the machine. The match is case insensitive and prefix-based.
Id string
State string
Filter results by power state of the machine.
ValueType string
Type of VM ID the user is interested in. Possible values are bios_id, external_id, instance_id. Default is bios_id.
context GetPolicyVmsContext
The context which the object belongs to
guestOs String
Filter results by operating system of the machine. The match is case insensitive and prefix-based.
id String
state String
Filter results by power state of the machine.
valueType String
Type of VM ID the user is interested in. Possible values are bios_id, external_id, instance_id. Default is bios_id.
context GetPolicyVmsContext
The context which the object belongs to
guestOs string
Filter results by operating system of the machine. The match is case insensitive and prefix-based.
id string
state string
Filter results by power state of the machine.
valueType string
Type of VM ID the user is interested in. Possible values are bios_id, external_id, instance_id. Default is bios_id.
context GetPolicyVmsContext
The context which the object belongs to
guest_os str
Filter results by operating system of the machine. The match is case insensitive and prefix-based.
id str
state str
Filter results by power state of the machine.
value_type str
Type of VM ID the user is interested in. Possible values are bios_id, external_id, instance_id. Default is bios_id.
context Property Map
The context which the object belongs to
guestOs String
Filter results by operating system of the machine. The match is case insensitive and prefix-based.
id String
state String
Filter results by power state of the machine.
valueType String
Type of VM ID the user is interested in. Possible values are bios_id, external_id, instance_id. Default is bios_id.

getPolicyVms Result

The following output properties are available:

Id string
Items Dictionary<string, string>
Map of IDs by Display Name.
Context GetPolicyVmsContext
GuestOs string
State string
ValueType string
Id string
Items map[string]string
Map of IDs by Display Name.
Context GetPolicyVmsContext
GuestOs string
State string
ValueType string
id String
items Map<String,String>
Map of IDs by Display Name.
context GetPolicyVmsContext
guestOs String
state String
valueType String
id string
items {[key: string]: string}
Map of IDs by Display Name.
context GetPolicyVmsContext
guestOs string
state string
valueType string
id str
items Mapping[str, str]
Map of IDs by Display Name.
context GetPolicyVmsContext
guest_os str
state str
value_type str
id String
items Map<String>
Map of IDs by Display Name.
context Property Map
guestOs String
state String
valueType String

Supporting Types

GetPolicyVmsContext

ProjectId This property is required. string
The ID of the project which the object belongs to
ProjectId This property is required. string
The ID of the project which the object belongs to
projectId This property is required. String
The ID of the project which the object belongs to
projectId This property is required. string
The ID of the project which the object belongs to
project_id This property is required. str
The ID of the project which the object belongs to
projectId This property is required. String
The ID of the project which the object belongs to

Package Details

Repository
nsxt vmware/terraform-provider-nsxt
License
Notes
This Pulumi package is based on the nsxt Terraform Provider.