1. Packages
  2. vSphere
  3. API Docs
  4. VmStoragePolicy
vSphere v4.10.0 published on Tuesday, Mar 12, 2024 by Pulumi

vsphere.VmStoragePolicy

Explore with Pulumi AI

vsphere logo
vSphere v4.10.0 published on Tuesday, Mar 12, 2024 by Pulumi

    The vsphere.VmStoragePolicy resource can be used to create and manage storage policies. Using this resource, tag based placement rules can be created to place virtual machines on a datastore with matching tags. If storage requirements for the applications on the virtual machine change, you can modify the storage policy that was originally applied to the virtual machine.

    Example Usage

    The following example creates storage policies with tag_rules base on sets of environment, service level, and replication attributes.

    In this example, tags are first applied to datastores.

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const environment = vsphere.getTagCategory({
        name: "environment",
    });
    const serviceLevel = vsphere.getTagCategory({
        name: "service_level",
    });
    const replication = vsphere.getTagCategory({
        name: "replication",
    });
    const production = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.environment.id",
        name: "production",
    });
    const development = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.environment.id",
        name: "development",
    });
    const platinum = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.service_level.id",
        name: "platinum",
    });
    const gold = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.service_level.id",
        name: "platinum",
    });
    const silver = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.service_level.id",
        name: "silver",
    });
    const bronze = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.service_level.id",
        name: "bronze",
    });
    const replicated = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.replication.id",
        name: "replicated",
    });
    const nonReplicated = vsphere.getTag({
        categoryId: "data.vsphere_tag_category.replication.id",
        name: "non_replicated",
    });
    const prodDatastore = new vsphere.VmfsDatastore("prodDatastore", {tags: [
        "data.vsphere_tag.production.id",
        "data.vsphere_tag.platinum.id",
        "data.vsphere_tag.replicated.id",
    ]});
    const devDatastore = new vsphere.NasDatastore("devDatastore", {tags: [
        "data.vsphere_tag.development.id",
        "data.vsphere_tag.silver.id",
        "data.vsphere_tag.non_replicated.id",
    ]});
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    environment = vsphere.get_tag_category(name="environment")
    service_level = vsphere.get_tag_category(name="service_level")
    replication = vsphere.get_tag_category(name="replication")
    production = vsphere.get_tag(category_id="data.vsphere_tag_category.environment.id",
        name="production")
    development = vsphere.get_tag(category_id="data.vsphere_tag_category.environment.id",
        name="development")
    platinum = vsphere.get_tag(category_id="data.vsphere_tag_category.service_level.id",
        name="platinum")
    gold = vsphere.get_tag(category_id="data.vsphere_tag_category.service_level.id",
        name="platinum")
    silver = vsphere.get_tag(category_id="data.vsphere_tag_category.service_level.id",
        name="silver")
    bronze = vsphere.get_tag(category_id="data.vsphere_tag_category.service_level.id",
        name="bronze")
    replicated = vsphere.get_tag(category_id="data.vsphere_tag_category.replication.id",
        name="replicated")
    non_replicated = vsphere.get_tag(category_id="data.vsphere_tag_category.replication.id",
        name="non_replicated")
    prod_datastore = vsphere.VmfsDatastore("prodDatastore", tags=[
        "data.vsphere_tag.production.id",
        "data.vsphere_tag.platinum.id",
        "data.vsphere_tag.replicated.id",
    ])
    dev_datastore = vsphere.NasDatastore("devDatastore", tags=[
        "data.vsphere_tag.development.id",
        "data.vsphere_tag.silver.id",
        "data.vsphere_tag.non_replicated.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 {
    		_, err := vsphere.LookupTagCategory(ctx, &vsphere.LookupTagCategoryArgs{
    			Name: "environment",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTagCategory(ctx, &vsphere.LookupTagCategoryArgs{
    			Name: "service_level",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTagCategory(ctx, &vsphere.LookupTagCategoryArgs{
    			Name: "replication",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.environment.id",
    			Name:       "production",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.environment.id",
    			Name:       "development",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.service_level.id",
    			Name:       "platinum",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.service_level.id",
    			Name:       "platinum",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.service_level.id",
    			Name:       "silver",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.service_level.id",
    			Name:       "bronze",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.replication.id",
    			Name:       "replicated",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
    			CategoryId: "data.vsphere_tag_category.replication.id",
    			Name:       "non_replicated",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.NewVmfsDatastore(ctx, "prodDatastore", &vsphere.VmfsDatastoreArgs{
    			Tags: pulumi.StringArray{
    				pulumi.String("data.vsphere_tag.production.id"),
    				pulumi.String("data.vsphere_tag.platinum.id"),
    				pulumi.String("data.vsphere_tag.replicated.id"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.NewNasDatastore(ctx, "devDatastore", &vsphere.NasDatastoreArgs{
    			Tags: pulumi.StringArray{
    				pulumi.String("data.vsphere_tag.development.id"),
    				pulumi.String("data.vsphere_tag.silver.id"),
    				pulumi.String("data.vsphere_tag.non_replicated.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 environment = VSphere.GetTagCategory.Invoke(new()
        {
            Name = "environment",
        });
    
        var serviceLevel = VSphere.GetTagCategory.Invoke(new()
        {
            Name = "service_level",
        });
    
        var replication = VSphere.GetTagCategory.Invoke(new()
        {
            Name = "replication",
        });
    
        var production = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.environment.id",
            Name = "production",
        });
    
        var development = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.environment.id",
            Name = "development",
        });
    
        var platinum = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.service_level.id",
            Name = "platinum",
        });
    
        var gold = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.service_level.id",
            Name = "platinum",
        });
    
        var silver = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.service_level.id",
            Name = "silver",
        });
    
        var bronze = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.service_level.id",
            Name = "bronze",
        });
    
        var replicated = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.replication.id",
            Name = "replicated",
        });
    
        var nonReplicated = VSphere.GetTag.Invoke(new()
        {
            CategoryId = "data.vsphere_tag_category.replication.id",
            Name = "non_replicated",
        });
    
        var prodDatastore = new VSphere.VmfsDatastore("prodDatastore", new()
        {
            Tags = new[]
            {
                "data.vsphere_tag.production.id",
                "data.vsphere_tag.platinum.id",
                "data.vsphere_tag.replicated.id",
            },
        });
    
        var devDatastore = new VSphere.NasDatastore("devDatastore", new()
        {
            Tags = new[]
            {
                "data.vsphere_tag.development.id",
                "data.vsphere_tag.silver.id",
                "data.vsphere_tag.non_replicated.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 com.pulumi.vsphere.VmfsDatastore;
    import com.pulumi.vsphere.VmfsDatastoreArgs;
    import com.pulumi.vsphere.NasDatastore;
    import com.pulumi.vsphere.NasDatastoreArgs;
    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 environment = VsphereFunctions.getTagCategory(GetTagCategoryArgs.builder()
                .name("environment")
                .build());
    
            final var serviceLevel = VsphereFunctions.getTagCategory(GetTagCategoryArgs.builder()
                .name("service_level")
                .build());
    
            final var replication = VsphereFunctions.getTagCategory(GetTagCategoryArgs.builder()
                .name("replication")
                .build());
    
            final var production = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.environment.id")
                .name("production")
                .build());
    
            final var development = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.environment.id")
                .name("development")
                .build());
    
            final var platinum = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.service_level.id")
                .name("platinum")
                .build());
    
            final var gold = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.service_level.id")
                .name("platinum")
                .build());
    
            final var silver = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.service_level.id")
                .name("silver")
                .build());
    
            final var bronze = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.service_level.id")
                .name("bronze")
                .build());
    
            final var replicated = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.replication.id")
                .name("replicated")
                .build());
    
            final var nonReplicated = VsphereFunctions.getTag(GetTagArgs.builder()
                .categoryId("data.vsphere_tag_category.replication.id")
                .name("non_replicated")
                .build());
    
            var prodDatastore = new VmfsDatastore("prodDatastore", VmfsDatastoreArgs.builder()        
                .tags(            
                    "data.vsphere_tag.production.id",
                    "data.vsphere_tag.platinum.id",
                    "data.vsphere_tag.replicated.id")
                .build());
    
            var devDatastore = new NasDatastore("devDatastore", NasDatastoreArgs.builder()        
                .tags(            
                    "data.vsphere_tag.development.id",
                    "data.vsphere_tag.silver.id",
                    "data.vsphere_tag.non_replicated.id")
                .build());
    
        }
    }
    
    resources:
      prodDatastore:
        type: vsphere:VmfsDatastore
        properties:
          # ... other configuration ...
          tags:
            - data.vsphere_tag.production.id
            - data.vsphere_tag.platinum.id
            - data.vsphere_tag.replicated.id
      devDatastore:
        type: vsphere:NasDatastore
        properties:
          # ... other configuration ...
          tags:
            - data.vsphere_tag.development.id
            - data.vsphere_tag.silver.id
            - data.vsphere_tag.non_replicated.id
    variables:
      environment:
        fn::invoke:
          Function: vsphere:getTagCategory
          Arguments:
            name: environment
      serviceLevel:
        fn::invoke:
          Function: vsphere:getTagCategory
          Arguments:
            name: service_level
      replication:
        fn::invoke:
          Function: vsphere:getTagCategory
          Arguments:
            name: replication
      production:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.environment.id
            name: production
      development:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.environment.id
            name: development
      platinum:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.service_level.id
            name: platinum
      gold:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.service_level.id
            name: platinum
      silver:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.service_level.id
            name: silver
      bronze:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.service_level.id
            name: bronze
      replicated:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.replication.id
            name: replicated
      nonReplicated:
        fn::invoke:
          Function: vsphere:getTag
          Arguments:
            categoryId: data.vsphere_tag_category.replication.id
            name: non_replicated
    

    Next, storage policies are created and tag_rules are applied.

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const prodPlatinumReplicated = new vsphere.VmStoragePolicy("prodPlatinumReplicated", {
        description: "prod_platinum_replicated",
        tagRules: [
            {
                tagCategory: data.vsphere_tag_category.environment.name,
                tags: [data.vsphere_tag.production.name],
                includeDatastoresWithTags: true,
            },
            {
                tagCategory: data.vsphere_tag_category.service_level.name,
                tags: [data.vsphere_tag.platinum.name],
                includeDatastoresWithTags: true,
            },
            {
                tagCategory: data.vsphere_tag_category.replication.name,
                tags: [data.vsphere_tag.replicated.name],
                includeDatastoresWithTags: true,
            },
        ],
    });
    const devSilverNonreplicated = new vsphere.VmStoragePolicy("devSilverNonreplicated", {
        description: "dev_silver_nonreplicated",
        tagRules: [
            {
                tagCategory: data.vsphere_tag_category.environment.name,
                tags: [data.vsphere_tag.development.name],
                includeDatastoresWithTags: true,
            },
            {
                tagCategory: data.vsphere_tag_category.service_level.name,
                tags: [data.vsphere_tag.silver.name],
                includeDatastoresWithTags: true,
            },
            {
                tagCategory: data.vsphere_tag_category.replication.name,
                tags: [data.vsphere_tag.non_replicated.name],
                includeDatastoresWithTags: true,
            },
        ],
    });
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    prod_platinum_replicated = vsphere.VmStoragePolicy("prodPlatinumReplicated",
        description="prod_platinum_replicated",
        tag_rules=[
            vsphere.VmStoragePolicyTagRuleArgs(
                tag_category=data["vsphere_tag_category"]["environment"]["name"],
                tags=[data["vsphere_tag"]["production"]["name"]],
                include_datastores_with_tags=True,
            ),
            vsphere.VmStoragePolicyTagRuleArgs(
                tag_category=data["vsphere_tag_category"]["service_level"]["name"],
                tags=[data["vsphere_tag"]["platinum"]["name"]],
                include_datastores_with_tags=True,
            ),
            vsphere.VmStoragePolicyTagRuleArgs(
                tag_category=data["vsphere_tag_category"]["replication"]["name"],
                tags=[data["vsphere_tag"]["replicated"]["name"]],
                include_datastores_with_tags=True,
            ),
        ])
    dev_silver_nonreplicated = vsphere.VmStoragePolicy("devSilverNonreplicated",
        description="dev_silver_nonreplicated",
        tag_rules=[
            vsphere.VmStoragePolicyTagRuleArgs(
                tag_category=data["vsphere_tag_category"]["environment"]["name"],
                tags=[data["vsphere_tag"]["development"]["name"]],
                include_datastores_with_tags=True,
            ),
            vsphere.VmStoragePolicyTagRuleArgs(
                tag_category=data["vsphere_tag_category"]["service_level"]["name"],
                tags=[data["vsphere_tag"]["silver"]["name"]],
                include_datastores_with_tags=True,
            ),
            vsphere.VmStoragePolicyTagRuleArgs(
                tag_category=data["vsphere_tag_category"]["replication"]["name"],
                tags=[data["vsphere_tag"]["non_replicated"]["name"]],
                include_datastores_with_tags=True,
            ),
        ])
    
    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.NewVmStoragePolicy(ctx, "prodPlatinumReplicated", &vsphere.VmStoragePolicyArgs{
    			Description: pulumi.String("prod_platinum_replicated"),
    			TagRules: vsphere.VmStoragePolicyTagRuleArray{
    				&vsphere.VmStoragePolicyTagRuleArgs{
    					TagCategory: pulumi.Any(data.Vsphere_tag_category.Environment.Name),
    					Tags: pulumi.StringArray{
    						data.Vsphere_tag.Production.Name,
    					},
    					IncludeDatastoresWithTags: pulumi.Bool(true),
    				},
    				&vsphere.VmStoragePolicyTagRuleArgs{
    					TagCategory: pulumi.Any(data.Vsphere_tag_category.Service_level.Name),
    					Tags: pulumi.StringArray{
    						data.Vsphere_tag.Platinum.Name,
    					},
    					IncludeDatastoresWithTags: pulumi.Bool(true),
    				},
    				&vsphere.VmStoragePolicyTagRuleArgs{
    					TagCategory: pulumi.Any(data.Vsphere_tag_category.Replication.Name),
    					Tags: pulumi.StringArray{
    						data.Vsphere_tag.Replicated.Name,
    					},
    					IncludeDatastoresWithTags: pulumi.Bool(true),
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.NewVmStoragePolicy(ctx, "devSilverNonreplicated", &vsphere.VmStoragePolicyArgs{
    			Description: pulumi.String("dev_silver_nonreplicated"),
    			TagRules: vsphere.VmStoragePolicyTagRuleArray{
    				&vsphere.VmStoragePolicyTagRuleArgs{
    					TagCategory: pulumi.Any(data.Vsphere_tag_category.Environment.Name),
    					Tags: pulumi.StringArray{
    						data.Vsphere_tag.Development.Name,
    					},
    					IncludeDatastoresWithTags: pulumi.Bool(true),
    				},
    				&vsphere.VmStoragePolicyTagRuleArgs{
    					TagCategory: pulumi.Any(data.Vsphere_tag_category.Service_level.Name),
    					Tags: pulumi.StringArray{
    						data.Vsphere_tag.Silver.Name,
    					},
    					IncludeDatastoresWithTags: pulumi.Bool(true),
    				},
    				&vsphere.VmStoragePolicyTagRuleArgs{
    					TagCategory: pulumi.Any(data.Vsphere_tag_category.Replication.Name),
    					Tags: pulumi.StringArray{
    						data.Vsphere_tag.Non_replicated.Name,
    					},
    					IncludeDatastoresWithTags: pulumi.Bool(true),
    				},
    			},
    		})
    		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 prodPlatinumReplicated = new VSphere.VmStoragePolicy("prodPlatinumReplicated", new()
        {
            Description = "prod_platinum_replicated",
            TagRules = new[]
            {
                new VSphere.Inputs.VmStoragePolicyTagRuleArgs
                {
                    TagCategory = data.Vsphere_tag_category.Environment.Name,
                    Tags = new[]
                    {
                        data.Vsphere_tag.Production.Name,
                    },
                    IncludeDatastoresWithTags = true,
                },
                new VSphere.Inputs.VmStoragePolicyTagRuleArgs
                {
                    TagCategory = data.Vsphere_tag_category.Service_level.Name,
                    Tags = new[]
                    {
                        data.Vsphere_tag.Platinum.Name,
                    },
                    IncludeDatastoresWithTags = true,
                },
                new VSphere.Inputs.VmStoragePolicyTagRuleArgs
                {
                    TagCategory = data.Vsphere_tag_category.Replication.Name,
                    Tags = new[]
                    {
                        data.Vsphere_tag.Replicated.Name,
                    },
                    IncludeDatastoresWithTags = true,
                },
            },
        });
    
        var devSilverNonreplicated = new VSphere.VmStoragePolicy("devSilverNonreplicated", new()
        {
            Description = "dev_silver_nonreplicated",
            TagRules = new[]
            {
                new VSphere.Inputs.VmStoragePolicyTagRuleArgs
                {
                    TagCategory = data.Vsphere_tag_category.Environment.Name,
                    Tags = new[]
                    {
                        data.Vsphere_tag.Development.Name,
                    },
                    IncludeDatastoresWithTags = true,
                },
                new VSphere.Inputs.VmStoragePolicyTagRuleArgs
                {
                    TagCategory = data.Vsphere_tag_category.Service_level.Name,
                    Tags = new[]
                    {
                        data.Vsphere_tag.Silver.Name,
                    },
                    IncludeDatastoresWithTags = true,
                },
                new VSphere.Inputs.VmStoragePolicyTagRuleArgs
                {
                    TagCategory = data.Vsphere_tag_category.Replication.Name,
                    Tags = new[]
                    {
                        data.Vsphere_tag.Non_replicated.Name,
                    },
                    IncludeDatastoresWithTags = true,
                },
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.vsphere.VmStoragePolicy;
    import com.pulumi.vsphere.VmStoragePolicyArgs;
    import com.pulumi.vsphere.inputs.VmStoragePolicyTagRuleArgs;
    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 prodPlatinumReplicated = new VmStoragePolicy("prodPlatinumReplicated", VmStoragePolicyArgs.builder()        
                .description("prod_platinum_replicated")
                .tagRules(            
                    VmStoragePolicyTagRuleArgs.builder()
                        .tagCategory(data.vsphere_tag_category().environment().name())
                        .tags(data.vsphere_tag().production().name())
                        .includeDatastoresWithTags(true)
                        .build(),
                    VmStoragePolicyTagRuleArgs.builder()
                        .tagCategory(data.vsphere_tag_category().service_level().name())
                        .tags(data.vsphere_tag().platinum().name())
                        .includeDatastoresWithTags(true)
                        .build(),
                    VmStoragePolicyTagRuleArgs.builder()
                        .tagCategory(data.vsphere_tag_category().replication().name())
                        .tags(data.vsphere_tag().replicated().name())
                        .includeDatastoresWithTags(true)
                        .build())
                .build());
    
            var devSilverNonreplicated = new VmStoragePolicy("devSilverNonreplicated", VmStoragePolicyArgs.builder()        
                .description("dev_silver_nonreplicated")
                .tagRules(            
                    VmStoragePolicyTagRuleArgs.builder()
                        .tagCategory(data.vsphere_tag_category().environment().name())
                        .tags(data.vsphere_tag().development().name())
                        .includeDatastoresWithTags(true)
                        .build(),
                    VmStoragePolicyTagRuleArgs.builder()
                        .tagCategory(data.vsphere_tag_category().service_level().name())
                        .tags(data.vsphere_tag().silver().name())
                        .includeDatastoresWithTags(true)
                        .build(),
                    VmStoragePolicyTagRuleArgs.builder()
                        .tagCategory(data.vsphere_tag_category().replication().name())
                        .tags(data.vsphere_tag().non_replicated().name())
                        .includeDatastoresWithTags(true)
                        .build())
                .build());
    
        }
    }
    
    resources:
      prodPlatinumReplicated:
        type: vsphere:VmStoragePolicy
        properties:
          description: prod_platinum_replicated
          tagRules:
            - tagCategory: ${data.vsphere_tag_category.environment.name}
              tags:
                - ${data.vsphere_tag.production.name}
              includeDatastoresWithTags: true
            - tagCategory: ${data.vsphere_tag_category.service_level.name}
              tags:
                - ${data.vsphere_tag.platinum.name}
              includeDatastoresWithTags: true
            - tagCategory: ${data.vsphere_tag_category.replication.name}
              tags:
                - ${data.vsphere_tag.replicated.name}
              includeDatastoresWithTags: true
      devSilverNonreplicated:
        type: vsphere:VmStoragePolicy
        properties:
          description: dev_silver_nonreplicated
          tagRules:
            - tagCategory: ${data.vsphere_tag_category.environment.name}
              tags:
                - ${data.vsphere_tag.development.name}
              includeDatastoresWithTags: true
            - tagCategory: ${data.vsphere_tag_category.service_level.name}
              tags:
                - ${data.vsphere_tag.silver.name}
              includeDatastoresWithTags: true
            - tagCategory: ${data.vsphere_tag_category.replication.name}
              tags:
                - ${data.vsphere_tag.non_replicated.name}
              includeDatastoresWithTags: true
    

    Lasttly, when creating a virtual machine resource, a storage policy can be specificed to direct virtual machine placement to a datastore which matches the policy’s tags_rules.

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const prodPlatinumReplicated = vsphere.getPolicy({
        name: "prod_platinum_replicated",
    });
    const devSilverNonreplicated = vsphere.getPolicy({
        name: "dev_silver_nonreplicated",
    });
    const prodVm = new vsphere.VirtualMachine("prodVm", {storagePolicyId: data.vsphere_storage_policy.storage_policy.prod_platinum_replicated.id});
    // ... other configuration ...
    const devVm = new vsphere.VirtualMachine("devVm", {storagePolicyId: data.vsphere_storage_policy.storage_policy.dev_silver_nonreplicated.id});
    // ... other configuration ...
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    prod_platinum_replicated = vsphere.get_policy(name="prod_platinum_replicated")
    dev_silver_nonreplicated = vsphere.get_policy(name="dev_silver_nonreplicated")
    prod_vm = vsphere.VirtualMachine("prodVm", storage_policy_id=data["vsphere_storage_policy"]["storage_policy"]["prod_platinum_replicated"]["id"])
    # ... other configuration ...
    dev_vm = vsphere.VirtualMachine("devVm", storage_policy_id=data["vsphere_storage_policy"]["storage_policy"]["dev_silver_nonreplicated"]["id"])
    # ... other configuration ...
    
    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.GetPolicy(ctx, &vsphere.GetPolicyArgs{
    			Name: "prod_platinum_replicated",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.GetPolicy(ctx, &vsphere.GetPolicyArgs{
    			Name: "dev_silver_nonreplicated",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.NewVirtualMachine(ctx, "prodVm", &vsphere.VirtualMachineArgs{
    			StoragePolicyId: pulumi.Any(data.Vsphere_storage_policy.Storage_policy.Prod_platinum_replicated.Id),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.NewVirtualMachine(ctx, "devVm", &vsphere.VirtualMachineArgs{
    			StoragePolicyId: pulumi.Any(data.Vsphere_storage_policy.Storage_policy.Dev_silver_nonreplicated.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 prodPlatinumReplicated = VSphere.GetPolicy.Invoke(new()
        {
            Name = "prod_platinum_replicated",
        });
    
        var devSilverNonreplicated = VSphere.GetPolicy.Invoke(new()
        {
            Name = "dev_silver_nonreplicated",
        });
    
        var prodVm = new VSphere.VirtualMachine("prodVm", new()
        {
            StoragePolicyId = data.Vsphere_storage_policy.Storage_policy.Prod_platinum_replicated.Id,
        });
    
        // ... other configuration ...
        var devVm = new VSphere.VirtualMachine("devVm", new()
        {
            StoragePolicyId = data.Vsphere_storage_policy.Storage_policy.Dev_silver_nonreplicated.Id,
        });
    
        // ... other configuration ...
    });
    
    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.GetPolicyArgs;
    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) {
            final var prodPlatinumReplicated = VsphereFunctions.getPolicy(GetPolicyArgs.builder()
                .name("prod_platinum_replicated")
                .build());
    
            final var devSilverNonreplicated = VsphereFunctions.getPolicy(GetPolicyArgs.builder()
                .name("dev_silver_nonreplicated")
                .build());
    
            var prodVm = new VirtualMachine("prodVm", VirtualMachineArgs.builder()        
                .storagePolicyId(data.vsphere_storage_policy().storage_policy().prod_platinum_replicated().id())
                .build());
    
            var devVm = new VirtualMachine("devVm", VirtualMachineArgs.builder()        
                .storagePolicyId(data.vsphere_storage_policy().storage_policy().dev_silver_nonreplicated().id())
                .build());
    
        }
    }
    
    resources:
      prodVm:
        type: vsphere:VirtualMachine
        properties:
          # ... other configuration ...
          storagePolicyId: ${data.vsphere_storage_policy.storage_policy.prod_platinum_replicated.id}
      devVm:
        type: vsphere:VirtualMachine
        properties:
          # ... other configuration ...
          storagePolicyId: ${data.vsphere_storage_policy.storage_policy.dev_silver_nonreplicated.id}
    variables:
      prodPlatinumReplicated:
        fn::invoke:
          Function: vsphere:getPolicy
          Arguments:
            name: prod_platinum_replicated
      devSilverNonreplicated:
        fn::invoke:
          Function: vsphere:getPolicy
          Arguments:
            name: dev_silver_nonreplicated
    

    Create VmStoragePolicy Resource

    new VmStoragePolicy(name: string, args: VmStoragePolicyArgs, opts?: CustomResourceOptions);
    @overload
    def VmStoragePolicy(resource_name: str,
                        opts: Optional[ResourceOptions] = None,
                        description: Optional[str] = None,
                        name: Optional[str] = None,
                        tag_rules: Optional[Sequence[VmStoragePolicyTagRuleArgs]] = None)
    @overload
    def VmStoragePolicy(resource_name: str,
                        args: VmStoragePolicyArgs,
                        opts: Optional[ResourceOptions] = None)
    func NewVmStoragePolicy(ctx *Context, name string, args VmStoragePolicyArgs, opts ...ResourceOption) (*VmStoragePolicy, error)
    public VmStoragePolicy(string name, VmStoragePolicyArgs args, CustomResourceOptions? opts = null)
    public VmStoragePolicy(String name, VmStoragePolicyArgs args)
    public VmStoragePolicy(String name, VmStoragePolicyArgs args, CustomResourceOptions options)
    
    type: vsphere:VmStoragePolicy
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args VmStoragePolicyArgs
    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 VmStoragePolicyArgs
    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 VmStoragePolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args VmStoragePolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args VmStoragePolicyArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    VmStoragePolicy Resource Properties

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

    Inputs

    The VmStoragePolicy resource accepts the following input properties:

    TagRules List<Pulumi.VSphere.Inputs.VmStoragePolicyTagRule>
    List of tag rules. The tag category and tags to be associated to this storage policy.
    Description string
    Description of the storage policy.
    Name string
    The name of the storage policy.
    TagRules []VmStoragePolicyTagRuleArgs
    List of tag rules. The tag category and tags to be associated to this storage policy.
    Description string
    Description of the storage policy.
    Name string
    The name of the storage policy.
    tagRules List<VmStoragePolicyTagRule>
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description String
    Description of the storage policy.
    name String
    The name of the storage policy.
    tagRules VmStoragePolicyTagRule[]
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description string
    Description of the storage policy.
    name string
    The name of the storage policy.
    tag_rules Sequence[VmStoragePolicyTagRuleArgs]
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description str
    Description of the storage policy.
    name str
    The name of the storage policy.
    tagRules List<Property Map>
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description String
    Description of the storage policy.
    name String
    The name of the storage policy.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the VmStoragePolicy 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 VmStoragePolicy Resource

    Get an existing VmStoragePolicy 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?: VmStoragePolicyState, opts?: CustomResourceOptions): VmStoragePolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            description: Optional[str] = None,
            name: Optional[str] = None,
            tag_rules: Optional[Sequence[VmStoragePolicyTagRuleArgs]] = None) -> VmStoragePolicy
    func GetVmStoragePolicy(ctx *Context, name string, id IDInput, state *VmStoragePolicyState, opts ...ResourceOption) (*VmStoragePolicy, error)
    public static VmStoragePolicy Get(string name, Input<string> id, VmStoragePolicyState? state, CustomResourceOptions? opts = null)
    public static VmStoragePolicy get(String name, Output<String> id, VmStoragePolicyState 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:
    Description string
    Description of the storage policy.
    Name string
    The name of the storage policy.
    TagRules List<Pulumi.VSphere.Inputs.VmStoragePolicyTagRule>
    List of tag rules. The tag category and tags to be associated to this storage policy.
    Description string
    Description of the storage policy.
    Name string
    The name of the storage policy.
    TagRules []VmStoragePolicyTagRuleArgs
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description String
    Description of the storage policy.
    name String
    The name of the storage policy.
    tagRules List<VmStoragePolicyTagRule>
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description string
    Description of the storage policy.
    name string
    The name of the storage policy.
    tagRules VmStoragePolicyTagRule[]
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description str
    Description of the storage policy.
    name str
    The name of the storage policy.
    tag_rules Sequence[VmStoragePolicyTagRuleArgs]
    List of tag rules. The tag category and tags to be associated to this storage policy.
    description String
    Description of the storage policy.
    name String
    The name of the storage policy.
    tagRules List<Property Map>
    List of tag rules. The tag category and tags to be associated to this storage policy.

    Supporting Types

    VmStoragePolicyTagRule, VmStoragePolicyTagRuleArgs

    TagCategory string
    Name of the tag category.
    Tags List<string>
    List of Name of tags to select from the given category.
    IncludeDatastoresWithTags bool
    Include datastores with the given tags or exclude. Default true.
    TagCategory string
    Name of the tag category.
    Tags []string
    List of Name of tags to select from the given category.
    IncludeDatastoresWithTags bool
    Include datastores with the given tags or exclude. Default true.
    tagCategory String
    Name of the tag category.
    tags List<String>
    List of Name of tags to select from the given category.
    includeDatastoresWithTags Boolean
    Include datastores with the given tags or exclude. Default true.
    tagCategory string
    Name of the tag category.
    tags string[]
    List of Name of tags to select from the given category.
    includeDatastoresWithTags boolean
    Include datastores with the given tags or exclude. Default true.
    tag_category str
    Name of the tag category.
    tags Sequence[str]
    List of Name of tags to select from the given category.
    include_datastores_with_tags bool
    Include datastores with the given tags or exclude. Default true.
    tagCategory String
    Name of the tag category.
    tags List<String>
    List of Name of tags to select from the given category.
    includeDatastoresWithTags Boolean
    Include datastores with the given tags or exclude. Default true.

    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.10.0 published on Tuesday, Mar 12, 2024 by Pulumi