1. Packages
  2. Packages
  3. Vsphere Provider
  4. API Docs
  5. getTag
Viewing docs for vSphere v4.17.0
published on Thursday, Jun 25, 2026 by Pulumi
vsphere logo
Viewing docs for vSphere v4.17.0
published on Thursday, Jun 25, 2026 by Pulumi

    The vsphere.Tag data source can be used to reference tags that are not managed by Terraform. Its attributes are exactly the same as the vsphere.Tag resource, and, like importing, the data source uses a name and category as search criteria. The id and other attributes are populated with the data found by the search.

    NOTE: Tagging is not supported on direct ESXi hosts connections and requires vCenter Server.

    Example Usage

    Lookup by Name and Category

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const category = vsphere.getTagCategory({
        name: "example-category",
    });
    const tag = category.then(category => vsphere.getTag({
        name: "example-tag",
        categoryId: category.id,
    }));
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    category = vsphere.get_tag_category(name="example-category")
    tag = vsphere.get_tag(name="example-tag",
        category_id=category.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-vsphere/sdk/v4/go/vsphere"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		category, err := vsphere.GetTagCategory(ctx, &vsphere.LookupTagCategoryArgs{
    			Name: pulumi.StringRef("example-category"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.GetTag(ctx, &vsphere.LookupTagArgs{
    			Name:       pulumi.StringRef("example-tag"),
    			CategoryId: pulumi.StringRef(category.Id),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using VSphere = Pulumi.VSphere;
    
    return await Deployment.RunAsync(() => 
    {
        var category = VSphere.GetTagCategory.Invoke(new()
        {
            Name = "example-category",
        });
    
        var tag = VSphere.GetTag.Invoke(new()
        {
            Name = "example-tag",
            CategoryId = category.Apply(getTagCategoryResult => getTagCategoryResult.Id),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.vsphere.VsphereFunctions;
    import com.pulumi.vsphere.inputs.GetTagCategoryArgs;
    import com.pulumi.vsphere.inputs.GetTagArgs;
    import java.util.ArrayList;
    import java.util.Arrays;
    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 category = VsphereFunctions.getTagCategory(GetTagCategoryArgs.builder()
                .name("example-category")
                .build());
    
            final var tag = VsphereFunctions.getTag(GetTagArgs.builder()
                .name("example-tag")
                .categoryId(category.id())
                .build());
    
        }
    }
    
    variables:
      category:
        fn::invoke:
          function: vsphere:getTagCategory
          arguments:
            name: example-category
      tag:
        fn::invoke:
          function: vsphere:getTag
          arguments:
            name: example-tag
            categoryId: ${category.id}
    
    pulumi {
      required_providers {
        vsphere = {
          source = "pulumi/vsphere"
        }
      }
    }
    
    data "vsphere_gettagcategory" "category" {
      name = "example-category"
    }
    data "vsphere_gettag" "tag" {
      name        = "example-tag"
      category_id = data.vsphere_gettagcategory.category.id
    }
    

    Lookup by ID

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const byId = vsphere.getTag({
        id: "urn:vmomi:InventoryServiceTag:xxxx",
    });
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    by_id = vsphere.get_tag(id="urn:vmomi:InventoryServiceTag:xxxx")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-vsphere/sdk/v4/go/vsphere"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := vsphere.GetTag(ctx, &vsphere.LookupTagArgs{
    			Id: pulumi.StringRef("urn:vmomi:InventoryServiceTag:xxxx"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using VSphere = Pulumi.VSphere;
    
    return await Deployment.RunAsync(() => 
    {
        var byId = VSphere.GetTag.Invoke(new()
        {
            Id = "urn:vmomi:InventoryServiceTag:xxxx",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.vsphere.VsphereFunctions;
    import com.pulumi.vsphere.inputs.GetTagArgs;
    import java.util.ArrayList;
    import java.util.Arrays;
    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 byId = VsphereFunctions.getTag(GetTagArgs.builder()
                .id("urn:vmomi:InventoryServiceTag:xxxx")
                .build());
    
        }
    }
    
    variables:
      byId:
        fn::invoke:
          function: vsphere:getTag
          arguments:
            id: urn:vmomi:InventoryServiceTag:xxxx
    
    pulumi {
      required_providers {
        vsphere = {
          source = "pulumi/vsphere"
        }
      }
    }
    
    data "vsphere_gettag" "byId" {
      id = "urn:vmomi:InventoryServiceTag:xxxx"
    }
    

    Using getTag

    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 getTag(args: GetTagArgs, opts?: InvokeOptions): Promise<GetTagResult>
    function getTagOutput(args: GetTagOutputArgs, opts?: InvokeOptions): Output<GetTagResult>
    def get_tag(category_id: Optional[str] = None,
                id: Optional[str] = None,
                name: Optional[str] = None,
                opts: Optional[InvokeOptions] = None) -> GetTagResult
    def get_tag_output(category_id: pulumi.Input[Optional[str]] = None,
                id: pulumi.Input[Optional[str]] = None,
                name: pulumi.Input[Optional[str]] = None,
                opts: Optional[InvokeOptions] = None) -> Output[GetTagResult]
    func LookupTag(ctx *Context, args *LookupTagArgs, opts ...InvokeOption) (*LookupTagResult, error)
    func LookupTagOutput(ctx *Context, args *LookupTagOutputArgs, opts ...InvokeOption) LookupTagResultOutput

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

    public static class GetTag 
    {
        public static Task<GetTagResult> InvokeAsync(GetTagArgs args, InvokeOptions? opts = null)
        public static Output<GetTagResult> Invoke(GetTagInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetTagResult> getTag(GetTagArgs args, InvokeOptions options)
    public static Output<GetTagResult> getTag(GetTagArgs args, InvokeOptions options)
    
    fn::invoke:
      function: vsphere:index/getTag:getTag
      arguments:
        # arguments dictionary
    data "vsphere_get_tag" "name" {
        # arguments
    }

    The following arguments are supported:

    CategoryId string
    The ID of the tag category in which the tag is located. Required when name is used.
    Id string
    The unique identifier of the tag. If specified, name and categoryId must not be set.
    Name string
    The name of the tag. If specified, categoryId must also be provided.
    CategoryId string
    The ID of the tag category in which the tag is located. Required when name is used.
    Id string
    The unique identifier of the tag. If specified, name and categoryId must not be set.
    Name string
    The name of the tag. If specified, categoryId must also be provided.
    category_id string
    The ID of the tag category in which the tag is located. Required when name is used.
    id string
    The unique identifier of the tag. If specified, name and categoryId must not be set.
    name string
    The name of the tag. If specified, categoryId must also be provided.
    categoryId String
    The ID of the tag category in which the tag is located. Required when name is used.
    id String
    The unique identifier of the tag. If specified, name and categoryId must not be set.
    name String
    The name of the tag. If specified, categoryId must also be provided.
    categoryId string
    The ID of the tag category in which the tag is located. Required when name is used.
    id string
    The unique identifier of the tag. If specified, name and categoryId must not be set.
    name string
    The name of the tag. If specified, categoryId must also be provided.
    category_id str
    The ID of the tag category in which the tag is located. Required when name is used.
    id str
    The unique identifier of the tag. If specified, name and categoryId must not be set.
    name str
    The name of the tag. If specified, categoryId must also be provided.
    categoryId String
    The ID of the tag category in which the tag is located. Required when name is used.
    id String
    The unique identifier of the tag. If specified, name and categoryId must not be set.
    name String
    The name of the tag. If specified, categoryId must also be provided.

    getTag Result

    The following output properties are available:

    Description string
    CategoryId string
    Id string
    Name string
    Description string
    CategoryId string
    Id string
    Name string
    description string
    category_id string
    id string
    name string
    description String
    categoryId String
    id String
    name String
    description string
    categoryId string
    id string
    name string
    description String
    categoryId String
    id String
    name String

    Package Details

    Repository
    vSphere pulumi/pulumi-vsphere
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the vsphere Terraform Provider.
    vsphere logo
    Viewing docs for vSphere v4.17.0
    published on Thursday, Jun 25, 2026 by Pulumi

      Try Pulumi Cloud free.
      Your team will thank you.

      Start free trial