nsxt 3.8.1 published on Wednesday, Apr 30, 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",
}],
});
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",
}])
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
})
}
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",
},
},
});
});
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());
}
}
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
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",
}],
});
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",
}])
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
})
}
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",
},
},
});
});
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());
}
}
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
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>
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]
func GetPolicyVms(ctx *Context, args *GetPolicyVmsArgs, opts ...InvokeOption) (*GetPolicyVmsResult, error)
func GetPolicyVmsOutput(ctx *Context, args *GetPolicyVmsOutputArgs, opts ...InvokeOption) GetPolicyVmsResultOutput
> 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)
}
public static CompletableFuture<GetPolicyVmsResult> getPolicyVms(GetPolicyVmsArgs args, InvokeOptions options)
public static Output<GetPolicyVmsResult> getPolicyVms(GetPolicyVmsArgs args, InvokeOptions options)
fn::invoke:
function: nsxt:index/getPolicyVms:getPolicyVms
arguments:
# arguments dictionary
The following arguments are supported:
- Context
Get
Policy Vms Context - The context which the object belongs to
- Guest
Os 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.
- Value
Type string - Type of VM ID the user is interested in. Possible values are
bios_id
,external_id
,instance_id
. Default isbios_id
.
- Context
Get
Policy Vms Context - The context which the object belongs to
- Guest
Os 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.
- Value
Type string - Type of VM ID the user is interested in. Possible values are
bios_id
,external_id
,instance_id
. Default isbios_id
.
- context
Get
Policy Vms Context - The context which the object belongs to
- guest
Os 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.
- value
Type String - Type of VM ID the user is interested in. Possible values are
bios_id
,external_id
,instance_id
. Default isbios_id
.
- context
Get
Policy Vms Context - The context which the object belongs to
- guest
Os 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.
- value
Type string - Type of VM ID the user is interested in. Possible values are
bios_id
,external_id
,instance_id
. Default isbios_id
.
- context
Get
Policy Vms Context - 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 isbios_id
.
- context Property Map
- The context which the object belongs to
- guest
Os 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.
- value
Type String - Type of VM ID the user is interested in. Possible values are
bios_id
,external_id
,instance_id
. Default isbios_id
.
getPolicyVms Result
The following output properties are available:
- id str
- items Mapping[str, str]
- Map of IDs by Display Name.
- context
Get
Policy Vms Context - guest_
os str - state str
- value_
type str
Supporting Types
GetPolicyVmsContext
- Project
Id string - The ID of the project which the object belongs to
- Project
Id string - The ID of the project which the object belongs to
- project
Id String - The ID of the project which the object belongs to
- project
Id string - The ID of the project which the object belongs to
- project_
id str - The ID of the project which the object belongs to
- project
Id 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.