1. Packages
  2. Vsphere Provider
  3. API Docs
  4. Tag
vSphere v4.12.1 published on Tuesday, Oct 22, 2024 by Pulumi

vsphere.Tag

Explore with Pulumi AI

vsphere logo
vSphere v4.12.1 published on Tuesday, Oct 22, 2024 by Pulumi

    The vsphere.Tag resource can be used to create and manage tags, which allow you to attach metadata to objects in the vSphere inventory to make these objects more sortable and searchable.

    For more information about tags, click here.

    Example Usage

    This example creates a tag named test-tag. This tag is assigned the test-category category, which was created by the vsphere.TagCategory resource. The resulting tag can be assigned to VMs and datastores only, and can be the only value in the category that can be assigned, as per the restrictions defined by the category.

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const category = new vsphere.TagCategory("category", {
        name: "test-category",
        cardinality: "SINGLE",
        description: "Managed by Pulumi",
        associableTypes: [
            "VirtualMachine",
            "Datastore",
        ],
    });
    const tag = new vsphere.Tag("tag", {
        name: "test-tag",
        categoryId: category.id,
        description: "Managed by Pulumi",
    });
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    category = vsphere.TagCategory("category",
        name="test-category",
        cardinality="SINGLE",
        description="Managed by Pulumi",
        associable_types=[
            "VirtualMachine",
            "Datastore",
        ])
    tag = vsphere.Tag("tag",
        name="test-tag",
        category_id=category.id,
        description="Managed by Pulumi")
    
    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.NewTagCategory(ctx, "category", &vsphere.TagCategoryArgs{
    			Name:        pulumi.String("test-category"),
    			Cardinality: pulumi.String("SINGLE"),
    			Description: pulumi.String("Managed by Pulumi"),
    			AssociableTypes: pulumi.StringArray{
    				pulumi.String("VirtualMachine"),
    				pulumi.String("Datastore"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.NewTag(ctx, "tag", &vsphere.TagArgs{
    			Name:        pulumi.String("test-tag"),
    			CategoryId:  category.ID(),
    			Description: pulumi.String("Managed by Pulumi"),
    		})
    		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 = new VSphere.TagCategory("category", new()
        {
            Name = "test-category",
            Cardinality = "SINGLE",
            Description = "Managed by Pulumi",
            AssociableTypes = new[]
            {
                "VirtualMachine",
                "Datastore",
            },
        });
    
        var tag = new VSphere.Tag("tag", new()
        {
            Name = "test-tag",
            CategoryId = category.Id,
            Description = "Managed by Pulumi",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.vsphere.TagCategory;
    import com.pulumi.vsphere.TagCategoryArgs;
    import com.pulumi.vsphere.Tag;
    import com.pulumi.vsphere.TagArgs;
    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) {
            var category = new TagCategory("category", TagCategoryArgs.builder()
                .name("test-category")
                .cardinality("SINGLE")
                .description("Managed by Pulumi")
                .associableTypes(            
                    "VirtualMachine",
                    "Datastore")
                .build());
    
            var tag = new Tag("tag", TagArgs.builder()
                .name("test-tag")
                .categoryId(category.id())
                .description("Managed by Pulumi")
                .build());
    
        }
    }
    
    resources:
      category:
        type: vsphere:TagCategory
        properties:
          name: test-category
          cardinality: SINGLE
          description: Managed by Pulumi
          associableTypes:
            - VirtualMachine
            - Datastore
      tag:
        type: vsphere:Tag
        properties:
          name: test-tag
          categoryId: ${category.id}
          description: Managed by Pulumi
    

    Using Tags in a Supported Resource

    Tags can be applied to vSphere resources via the tags argument in any supported resource.

    The following example builds on the above example by creating a vsphere.VirtualMachine and applying the created tag to it:

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const category = new vsphere.TagCategory("category", {
        name: "test-category",
        cardinality: "SINGLE",
        description: "Managed by Pulumi",
        associableTypes: [
            "VirtualMachine",
            "Datastore",
        ],
    });
    const tag = new vsphere.Tag("tag", {
        name: "test-tag",
        categoryId: category.id,
        description: "Managed by Pulumi",
    });
    const web = new vsphere.VirtualMachine("web", {tags: [tag.id]});
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    category = vsphere.TagCategory("category",
        name="test-category",
        cardinality="SINGLE",
        description="Managed by Pulumi",
        associable_types=[
            "VirtualMachine",
            "Datastore",
        ])
    tag = vsphere.Tag("tag",
        name="test-tag",
        category_id=category.id,
        description="Managed by Pulumi")
    web = vsphere.VirtualMachine("web", tags=[tag.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.NewTagCategory(ctx, "category", &vsphere.TagCategoryArgs{
    			Name:        pulumi.String("test-category"),
    			Cardinality: pulumi.String("SINGLE"),
    			Description: pulumi.String("Managed by Pulumi"),
    			AssociableTypes: pulumi.StringArray{
    				pulumi.String("VirtualMachine"),
    				pulumi.String("Datastore"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		tag, err := vsphere.NewTag(ctx, "tag", &vsphere.TagArgs{
    			Name:        pulumi.String("test-tag"),
    			CategoryId:  category.ID(),
    			Description: pulumi.String("Managed by Pulumi"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.NewVirtualMachine(ctx, "web", &vsphere.VirtualMachineArgs{
    			Tags: pulumi.StringArray{
    				tag.ID(),
    			},
    		})
    		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 = new VSphere.TagCategory("category", new()
        {
            Name = "test-category",
            Cardinality = "SINGLE",
            Description = "Managed by Pulumi",
            AssociableTypes = new[]
            {
                "VirtualMachine",
                "Datastore",
            },
        });
    
        var tag = new VSphere.Tag("tag", new()
        {
            Name = "test-tag",
            CategoryId = category.Id,
            Description = "Managed by Pulumi",
        });
    
        var web = new VSphere.VirtualMachine("web", new()
        {
            Tags = new[]
            {
                tag.Id,
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.vsphere.TagCategory;
    import com.pulumi.vsphere.TagCategoryArgs;
    import com.pulumi.vsphere.Tag;
    import com.pulumi.vsphere.TagArgs;
    import com.pulumi.vsphere.VirtualMachine;
    import com.pulumi.vsphere.VirtualMachineArgs;
    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) {
            var category = new TagCategory("category", TagCategoryArgs.builder()
                .name("test-category")
                .cardinality("SINGLE")
                .description("Managed by Pulumi")
                .associableTypes(            
                    "VirtualMachine",
                    "Datastore")
                .build());
    
            var tag = new Tag("tag", TagArgs.builder()
                .name("test-tag")
                .categoryId(category.id())
                .description("Managed by Pulumi")
                .build());
    
            var web = new VirtualMachine("web", VirtualMachineArgs.builder()
                .tags(tag.id())
                .build());
    
        }
    }
    
    resources:
      category:
        type: vsphere:TagCategory
        properties:
          name: test-category
          cardinality: SINGLE
          description: Managed by Pulumi
          associableTypes:
            - VirtualMachine
            - Datastore
      tag:
        type: vsphere:Tag
        properties:
          name: test-tag
          categoryId: ${category.id}
          description: Managed by Pulumi
      web:
        type: vsphere:VirtualMachine
        properties:
          tags:
            - ${tag.id}
    

    Create Tag Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new Tag(name: string, args: TagArgs, opts?: CustomResourceOptions);
    @overload
    def Tag(resource_name: str,
            args: TagArgs,
            opts: Optional[ResourceOptions] = None)
    
    @overload
    def Tag(resource_name: str,
            opts: Optional[ResourceOptions] = None,
            category_id: Optional[str] = None,
            description: Optional[str] = None,
            name: Optional[str] = None)
    func NewTag(ctx *Context, name string, args TagArgs, opts ...ResourceOption) (*Tag, error)
    public Tag(string name, TagArgs args, CustomResourceOptions? opts = null)
    public Tag(String name, TagArgs args)
    public Tag(String name, TagArgs args, CustomResourceOptions options)
    
    type: vsphere:Tag
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args TagArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args TagArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args TagArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args TagArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args TagArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var tagResource = new VSphere.Tag("tagResource", new()
    {
        CategoryId = "string",
        Description = "string",
        Name = "string",
    });
    
    example, err := vsphere.NewTag(ctx, "tagResource", &vsphere.TagArgs{
    	CategoryId:  pulumi.String("string"),
    	Description: pulumi.String("string"),
    	Name:        pulumi.String("string"),
    })
    
    var tagResource = new Tag("tagResource", TagArgs.builder()
        .categoryId("string")
        .description("string")
        .name("string")
        .build());
    
    tag_resource = vsphere.Tag("tagResource",
        category_id="string",
        description="string",
        name="string")
    
    const tagResource = new vsphere.Tag("tagResource", {
        categoryId: "string",
        description: "string",
        name: "string",
    });
    
    type: vsphere:Tag
    properties:
        categoryId: string
        description: string
        name: string
    

    Tag Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The Tag resource accepts the following input properties:

    CategoryId string
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    Description string
    A description for the tag.
    Name string
    The display name of the tag. The name must be unique within its category.
    CategoryId string
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    Description string
    A description for the tag.
    Name string
    The display name of the tag. The name must be unique within its category.
    categoryId String
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description String
    A description for the tag.
    name String
    The display name of the tag. The name must be unique within its category.
    categoryId string
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description string
    A description for the tag.
    name string
    The display name of the tag. The name must be unique within its category.
    category_id str
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description str
    A description for the tag.
    name str
    The display name of the tag. The name must be unique within its category.
    categoryId String
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description String
    A description for the tag.
    name String
    The display name of the tag. The name must be unique within its category.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the Tag resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing Tag Resource

    Get an existing Tag resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: TagState, opts?: CustomResourceOptions): Tag
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            category_id: Optional[str] = None,
            description: Optional[str] = None,
            name: Optional[str] = None) -> Tag
    func GetTag(ctx *Context, name string, id IDInput, state *TagState, opts ...ResourceOption) (*Tag, error)
    public static Tag Get(string name, Input<string> id, TagState? state, CustomResourceOptions? opts = null)
    public static Tag get(String name, Output<String> id, TagState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    CategoryId string
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    Description string
    A description for the tag.
    Name string
    The display name of the tag. The name must be unique within its category.
    CategoryId string
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    Description string
    A description for the tag.
    Name string
    The display name of the tag. The name must be unique within its category.
    categoryId String
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description String
    A description for the tag.
    name String
    The display name of the tag. The name must be unique within its category.
    categoryId string
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description string
    A description for the tag.
    name string
    The display name of the tag. The name must be unique within its category.
    category_id str
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description str
    A description for the tag.
    name str
    The display name of the tag. The name must be unique within its category.
    categoryId String
    The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed.
    description String
    A description for the tag.
    name String
    The display name of the tag. The name must be unique within its category.

    Import

    An existing tag can be imported into this resource by supplying

    both the tag’s category name and the name of the tag as a JSON string to

    pulumi import, as per the example below:

    $ pulumi import vsphere:index/tag:Tag tag \
    

    ‘{“category_name”: “pulumi-test-category”, “tag_name”: “pulumi-test-tag”}’

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    vSphere pulumi/pulumi-vsphere
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the vsphere Terraform Provider.
    vsphere logo
    vSphere v4.12.1 published on Tuesday, Oct 22, 2024 by Pulumi