vsphere.VmStoragePolicy
Explore with Pulumi AI
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({
name: "production",
categoryId: "data.vsphere_tag_category.environment.id",
});
const development = vsphere.getTag({
name: "development",
categoryId: "data.vsphere_tag_category.environment.id",
});
const platinum = vsphere.getTag({
name: "platinum",
categoryId: "data.vsphere_tag_category.service_level.id",
});
const gold = vsphere.getTag({
name: "platinum",
categoryId: "data.vsphere_tag_category.service_level.id",
});
const silver = vsphere.getTag({
name: "silver",
categoryId: "data.vsphere_tag_category.service_level.id",
});
const bronze = vsphere.getTag({
name: "bronze",
categoryId: "data.vsphere_tag_category.service_level.id",
});
const replicated = vsphere.getTag({
name: "replicated",
categoryId: "data.vsphere_tag_category.replication.id",
});
const nonReplicated = vsphere.getTag({
name: "non_replicated",
categoryId: "data.vsphere_tag_category.replication.id",
});
const prodDatastore = new vsphere.VmfsDatastore("prod_datastore", {tags: [
"data.vsphere_tag.production.id",
"data.vsphere_tag.platinum.id",
"data.vsphere_tag.replicated.id",
]});
const devDatastore = new vsphere.NasDatastore("dev_datastore", {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(name="production",
category_id="data.vsphere_tag_category.environment.id")
development = vsphere.get_tag(name="development",
category_id="data.vsphere_tag_category.environment.id")
platinum = vsphere.get_tag(name="platinum",
category_id="data.vsphere_tag_category.service_level.id")
gold = vsphere.get_tag(name="platinum",
category_id="data.vsphere_tag_category.service_level.id")
silver = vsphere.get_tag(name="silver",
category_id="data.vsphere_tag_category.service_level.id")
bronze = vsphere.get_tag(name="bronze",
category_id="data.vsphere_tag_category.service_level.id")
replicated = vsphere.get_tag(name="replicated",
category_id="data.vsphere_tag_category.replication.id")
non_replicated = vsphere.get_tag(name="non_replicated",
category_id="data.vsphere_tag_category.replication.id")
prod_datastore = vsphere.VmfsDatastore("prod_datastore", tags=[
"data.vsphere_tag.production.id",
"data.vsphere_tag.platinum.id",
"data.vsphere_tag.replicated.id",
])
dev_datastore = vsphere.NasDatastore("dev_datastore", 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{
Name: "production",
CategoryId: "data.vsphere_tag_category.environment.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
Name: "development",
CategoryId: "data.vsphere_tag_category.environment.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
Name: "platinum",
CategoryId: "data.vsphere_tag_category.service_level.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
Name: "platinum",
CategoryId: "data.vsphere_tag_category.service_level.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
Name: "silver",
CategoryId: "data.vsphere_tag_category.service_level.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
Name: "bronze",
CategoryId: "data.vsphere_tag_category.service_level.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
Name: "replicated",
CategoryId: "data.vsphere_tag_category.replication.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.LookupTag(ctx, &vsphere.LookupTagArgs{
Name: "non_replicated",
CategoryId: "data.vsphere_tag_category.replication.id",
}, nil)
if err != nil {
return err
}
_, err = vsphere.NewVmfsDatastore(ctx, "prod_datastore", &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, "dev_datastore", &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()
{
Name = "production",
CategoryId = "data.vsphere_tag_category.environment.id",
});
var development = VSphere.GetTag.Invoke(new()
{
Name = "development",
CategoryId = "data.vsphere_tag_category.environment.id",
});
var platinum = VSphere.GetTag.Invoke(new()
{
Name = "platinum",
CategoryId = "data.vsphere_tag_category.service_level.id",
});
var gold = VSphere.GetTag.Invoke(new()
{
Name = "platinum",
CategoryId = "data.vsphere_tag_category.service_level.id",
});
var silver = VSphere.GetTag.Invoke(new()
{
Name = "silver",
CategoryId = "data.vsphere_tag_category.service_level.id",
});
var bronze = VSphere.GetTag.Invoke(new()
{
Name = "bronze",
CategoryId = "data.vsphere_tag_category.service_level.id",
});
var replicated = VSphere.GetTag.Invoke(new()
{
Name = "replicated",
CategoryId = "data.vsphere_tag_category.replication.id",
});
var nonReplicated = VSphere.GetTag.Invoke(new()
{
Name = "non_replicated",
CategoryId = "data.vsphere_tag_category.replication.id",
});
var prodDatastore = new VSphere.VmfsDatastore("prod_datastore", new()
{
Tags = new[]
{
"data.vsphere_tag.production.id",
"data.vsphere_tag.platinum.id",
"data.vsphere_tag.replicated.id",
},
});
var devDatastore = new VSphere.NasDatastore("dev_datastore", 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()
.name("production")
.categoryId("data.vsphere_tag_category.environment.id")
.build());
final var development = VsphereFunctions.getTag(GetTagArgs.builder()
.name("development")
.categoryId("data.vsphere_tag_category.environment.id")
.build());
final var platinum = VsphereFunctions.getTag(GetTagArgs.builder()
.name("platinum")
.categoryId("data.vsphere_tag_category.service_level.id")
.build());
final var gold = VsphereFunctions.getTag(GetTagArgs.builder()
.name("platinum")
.categoryId("data.vsphere_tag_category.service_level.id")
.build());
final var silver = VsphereFunctions.getTag(GetTagArgs.builder()
.name("silver")
.categoryId("data.vsphere_tag_category.service_level.id")
.build());
final var bronze = VsphereFunctions.getTag(GetTagArgs.builder()
.name("bronze")
.categoryId("data.vsphere_tag_category.service_level.id")
.build());
final var replicated = VsphereFunctions.getTag(GetTagArgs.builder()
.name("replicated")
.categoryId("data.vsphere_tag_category.replication.id")
.build());
final var nonReplicated = VsphereFunctions.getTag(GetTagArgs.builder()
.name("non_replicated")
.categoryId("data.vsphere_tag_category.replication.id")
.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
name: prod_datastore
properties:
tags: # ... other configuration ...
- data.vsphere_tag.production.id
- data.vsphere_tag.platinum.id
- data.vsphere_tag.replicated.id
devDatastore:
type: vsphere:NasDatastore
name: dev_datastore
properties:
tags: # ... other configuration ...
- 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:
name: production
categoryId: data.vsphere_tag_category.environment.id
development:
fn::invoke:
Function: vsphere:getTag
Arguments:
name: development
categoryId: data.vsphere_tag_category.environment.id
platinum:
fn::invoke:
Function: vsphere:getTag
Arguments:
name: platinum
categoryId: data.vsphere_tag_category.service_level.id
gold:
fn::invoke:
Function: vsphere:getTag
Arguments:
name: platinum
categoryId: data.vsphere_tag_category.service_level.id
silver:
fn::invoke:
Function: vsphere:getTag
Arguments:
name: silver
categoryId: data.vsphere_tag_category.service_level.id
bronze:
fn::invoke:
Function: vsphere:getTag
Arguments:
name: bronze
categoryId: data.vsphere_tag_category.service_level.id
replicated:
fn::invoke:
Function: vsphere:getTag
Arguments:
name: replicated
categoryId: data.vsphere_tag_category.replication.id
nonReplicated:
fn::invoke:
Function: vsphere:getTag
Arguments:
name: non_replicated
categoryId: data.vsphere_tag_category.replication.id
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("prod_platinum_replicated", {
name: "prod_platinum_replicated",
description: "prod_platinum_replicated",
tagRules: [
{
tagCategory: environment.name,
tags: [production.name],
includeDatastoresWithTags: true,
},
{
tagCategory: serviceLevel.name,
tags: [platinum.name],
includeDatastoresWithTags: true,
},
{
tagCategory: replication.name,
tags: [replicated.name],
includeDatastoresWithTags: true,
},
],
});
const devSilverNonreplicated = new vsphere.VmStoragePolicy("dev_silver_nonreplicated", {
name: "dev_silver_nonreplicated",
description: "dev_silver_nonreplicated",
tagRules: [
{
tagCategory: environment.name,
tags: [development.name],
includeDatastoresWithTags: true,
},
{
tagCategory: serviceLevel.name,
tags: [silver.name],
includeDatastoresWithTags: true,
},
{
tagCategory: replication.name,
tags: [nonReplicated.name],
includeDatastoresWithTags: true,
},
],
});
import pulumi
import pulumi_vsphere as vsphere
prod_platinum_replicated = vsphere.VmStoragePolicy("prod_platinum_replicated",
name="prod_platinum_replicated",
description="prod_platinum_replicated",
tag_rules=[
{
"tag_category": environment["name"],
"tags": [production["name"]],
"include_datastores_with_tags": True,
},
{
"tag_category": service_level["name"],
"tags": [platinum["name"]],
"include_datastores_with_tags": True,
},
{
"tag_category": replication["name"],
"tags": [replicated["name"]],
"include_datastores_with_tags": True,
},
])
dev_silver_nonreplicated = vsphere.VmStoragePolicy("dev_silver_nonreplicated",
name="dev_silver_nonreplicated",
description="dev_silver_nonreplicated",
tag_rules=[
{
"tag_category": environment["name"],
"tags": [development["name"]],
"include_datastores_with_tags": True,
},
{
"tag_category": service_level["name"],
"tags": [silver["name"]],
"include_datastores_with_tags": True,
},
{
"tag_category": replication["name"],
"tags": [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, "prod_platinum_replicated", &vsphere.VmStoragePolicyArgs{
Name: pulumi.String("prod_platinum_replicated"),
Description: pulumi.String("prod_platinum_replicated"),
TagRules: vsphere.VmStoragePolicyTagRuleArray{
&vsphere.VmStoragePolicyTagRuleArgs{
TagCategory: pulumi.Any(environment.Name),
Tags: pulumi.StringArray{
production.Name,
},
IncludeDatastoresWithTags: pulumi.Bool(true),
},
&vsphere.VmStoragePolicyTagRuleArgs{
TagCategory: pulumi.Any(serviceLevel.Name),
Tags: pulumi.StringArray{
platinum.Name,
},
IncludeDatastoresWithTags: pulumi.Bool(true),
},
&vsphere.VmStoragePolicyTagRuleArgs{
TagCategory: pulumi.Any(replication.Name),
Tags: pulumi.StringArray{
replicated.Name,
},
IncludeDatastoresWithTags: pulumi.Bool(true),
},
},
})
if err != nil {
return err
}
_, err = vsphere.NewVmStoragePolicy(ctx, "dev_silver_nonreplicated", &vsphere.VmStoragePolicyArgs{
Name: pulumi.String("dev_silver_nonreplicated"),
Description: pulumi.String("dev_silver_nonreplicated"),
TagRules: vsphere.VmStoragePolicyTagRuleArray{
&vsphere.VmStoragePolicyTagRuleArgs{
TagCategory: pulumi.Any(environment.Name),
Tags: pulumi.StringArray{
development.Name,
},
IncludeDatastoresWithTags: pulumi.Bool(true),
},
&vsphere.VmStoragePolicyTagRuleArgs{
TagCategory: pulumi.Any(serviceLevel.Name),
Tags: pulumi.StringArray{
silver.Name,
},
IncludeDatastoresWithTags: pulumi.Bool(true),
},
&vsphere.VmStoragePolicyTagRuleArgs{
TagCategory: pulumi.Any(replication.Name),
Tags: pulumi.StringArray{
nonReplicated.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("prod_platinum_replicated", new()
{
Name = "prod_platinum_replicated",
Description = "prod_platinum_replicated",
TagRules = new[]
{
new VSphere.Inputs.VmStoragePolicyTagRuleArgs
{
TagCategory = environment.Name,
Tags = new[]
{
production.Name,
},
IncludeDatastoresWithTags = true,
},
new VSphere.Inputs.VmStoragePolicyTagRuleArgs
{
TagCategory = serviceLevel.Name,
Tags = new[]
{
platinum.Name,
},
IncludeDatastoresWithTags = true,
},
new VSphere.Inputs.VmStoragePolicyTagRuleArgs
{
TagCategory = replication.Name,
Tags = new[]
{
replicated.Name,
},
IncludeDatastoresWithTags = true,
},
},
});
var devSilverNonreplicated = new VSphere.VmStoragePolicy("dev_silver_nonreplicated", new()
{
Name = "dev_silver_nonreplicated",
Description = "dev_silver_nonreplicated",
TagRules = new[]
{
new VSphere.Inputs.VmStoragePolicyTagRuleArgs
{
TagCategory = environment.Name,
Tags = new[]
{
development.Name,
},
IncludeDatastoresWithTags = true,
},
new VSphere.Inputs.VmStoragePolicyTagRuleArgs
{
TagCategory = serviceLevel.Name,
Tags = new[]
{
silver.Name,
},
IncludeDatastoresWithTags = true,
},
new VSphere.Inputs.VmStoragePolicyTagRuleArgs
{
TagCategory = replication.Name,
Tags = new[]
{
nonReplicated.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()
.name("prod_platinum_replicated")
.description("prod_platinum_replicated")
.tagRules(
VmStoragePolicyTagRuleArgs.builder()
.tagCategory(environment.name())
.tags(production.name())
.includeDatastoresWithTags(true)
.build(),
VmStoragePolicyTagRuleArgs.builder()
.tagCategory(serviceLevel.name())
.tags(platinum.name())
.includeDatastoresWithTags(true)
.build(),
VmStoragePolicyTagRuleArgs.builder()
.tagCategory(replication.name())
.tags(replicated.name())
.includeDatastoresWithTags(true)
.build())
.build());
var devSilverNonreplicated = new VmStoragePolicy("devSilverNonreplicated", VmStoragePolicyArgs.builder()
.name("dev_silver_nonreplicated")
.description("dev_silver_nonreplicated")
.tagRules(
VmStoragePolicyTagRuleArgs.builder()
.tagCategory(environment.name())
.tags(development.name())
.includeDatastoresWithTags(true)
.build(),
VmStoragePolicyTagRuleArgs.builder()
.tagCategory(serviceLevel.name())
.tags(silver.name())
.includeDatastoresWithTags(true)
.build(),
VmStoragePolicyTagRuleArgs.builder()
.tagCategory(replication.name())
.tags(nonReplicated.name())
.includeDatastoresWithTags(true)
.build())
.build());
}
}
resources:
prodPlatinumReplicated:
type: vsphere:VmStoragePolicy
name: prod_platinum_replicated
properties:
name: prod_platinum_replicated
description: prod_platinum_replicated
tagRules:
- tagCategory: ${environment.name}
tags:
- ${production.name}
includeDatastoresWithTags: true
- tagCategory: ${serviceLevel.name}
tags:
- ${platinum.name}
includeDatastoresWithTags: true
- tagCategory: ${replication.name}
tags:
- ${replicated.name}
includeDatastoresWithTags: true
devSilverNonreplicated:
type: vsphere:VmStoragePolicy
name: dev_silver_nonreplicated
properties:
name: dev_silver_nonreplicated
description: dev_silver_nonreplicated
tagRules:
- tagCategory: ${environment.name}
tags:
- ${development.name}
includeDatastoresWithTags: true
- tagCategory: ${serviceLevel.name}
tags:
- ${silver.name}
includeDatastoresWithTags: true
- tagCategory: ${replication.name}
tags:
- ${nonReplicated.name}
includeDatastoresWithTags: true
Lastly, when creating a virtual machine resource, a storage policy can be specified 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("prod_vm", {storagePolicyId: storagePolicy.prodPlatinumReplicated.id});
const devVm = new vsphere.VirtualMachine("dev_vm", {storagePolicyId: storagePolicy.devSilverNonreplicated.id});
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("prod_vm", storage_policy_id=storage_policy["prodPlatinumReplicated"]["id"])
dev_vm = vsphere.VirtualMachine("dev_vm", storage_policy_id=storage_policy["devSilverNonreplicated"]["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.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, "prod_vm", &vsphere.VirtualMachineArgs{
StoragePolicyId: pulumi.Any(storagePolicy.ProdPlatinumReplicated.Id),
})
if err != nil {
return err
}
_, err = vsphere.NewVirtualMachine(ctx, "dev_vm", &vsphere.VirtualMachineArgs{
StoragePolicyId: pulumi.Any(storagePolicy.DevSilverNonreplicated.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("prod_vm", new()
{
StoragePolicyId = storagePolicy.ProdPlatinumReplicated.Id,
});
var devVm = new VSphere.VirtualMachine("dev_vm", new()
{
StoragePolicyId = storagePolicy.DevSilverNonreplicated.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.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(storagePolicy.prodPlatinumReplicated().id())
.build());
var devVm = new VirtualMachine("devVm", VirtualMachineArgs.builder()
.storagePolicyId(storagePolicy.devSilverNonreplicated().id())
.build());
}
}
resources:
prodVm:
type: vsphere:VirtualMachine
name: prod_vm
properties:
storagePolicyId: ${storagePolicy.prodPlatinumReplicated.id}
devVm:
type: vsphere:VirtualMachine
name: dev_vm
properties:
storagePolicyId: ${storagePolicy.devSilverNonreplicated.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
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new VmStoragePolicy(name: string, args: VmStoragePolicyArgs, opts?: CustomResourceOptions);
@overload
def VmStoragePolicy(resource_name: str,
args: VmStoragePolicyArgs,
opts: Optional[ResourceOptions] = None)
@overload
def VmStoragePolicy(resource_name: str,
opts: Optional[ResourceOptions] = None,
tag_rules: Optional[Sequence[VmStoragePolicyTagRuleArgs]] = None,
description: Optional[str] = None,
name: Optional[str] = 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.
Parameters
- 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.
Constructor example
The following reference example uses placeholder values for all input properties.
var vmStoragePolicyResource = new VSphere.VmStoragePolicy("vmStoragePolicyResource", new()
{
TagRules = new[]
{
new VSphere.Inputs.VmStoragePolicyTagRuleArgs
{
TagCategory = "string",
Tags = new[]
{
"string",
},
IncludeDatastoresWithTags = false,
},
},
Description = "string",
Name = "string",
});
example, err := vsphere.NewVmStoragePolicy(ctx, "vmStoragePolicyResource", &vsphere.VmStoragePolicyArgs{
TagRules: vsphere.VmStoragePolicyTagRuleArray{
&vsphere.VmStoragePolicyTagRuleArgs{
TagCategory: pulumi.String("string"),
Tags: pulumi.StringArray{
pulumi.String("string"),
},
IncludeDatastoresWithTags: pulumi.Bool(false),
},
},
Description: pulumi.String("string"),
Name: pulumi.String("string"),
})
var vmStoragePolicyResource = new VmStoragePolicy("vmStoragePolicyResource", VmStoragePolicyArgs.builder()
.tagRules(VmStoragePolicyTagRuleArgs.builder()
.tagCategory("string")
.tags("string")
.includeDatastoresWithTags(false)
.build())
.description("string")
.name("string")
.build());
vm_storage_policy_resource = vsphere.VmStoragePolicy("vmStoragePolicyResource",
tag_rules=[{
"tag_category": "string",
"tags": ["string"],
"include_datastores_with_tags": False,
}],
description="string",
name="string")
const vmStoragePolicyResource = new vsphere.VmStoragePolicy("vmStoragePolicyResource", {
tagRules: [{
tagCategory: "string",
tags: ["string"],
includeDatastoresWithTags: false,
}],
description: "string",
name: "string",
});
type: vsphere:VmStoragePolicy
properties:
description: string
name: string
tagRules:
- includeDatastoresWithTags: false
tagCategory: string
tags:
- string
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
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The VmStoragePolicy resource accepts the following input properties:
- Tag
Rules List<Pulumi.VSphere. Inputs. Vm Storage Policy Tag Rule> - 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 []VmStorage Policy Tag Rule Args - 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 List<VmStorage Policy Tag Rule> - 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 VmStorage Policy Tag Rule[] - 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[VmStorage Policy Tag Rule Args] - 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 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.
- Description string
- Description of the storage policy.
- Name string
- The name of the storage policy.
- Tag
Rules List<Pulumi.VSphere. Inputs. Vm Storage Policy Tag Rule> - 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 []VmStorage Policy Tag Rule Args - 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 List<VmStorage Policy Tag Rule> - 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 VmStorage Policy Tag Rule[] - 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[VmStorage Policy Tag Rule Args] - 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 List<Property Map> - List of tag rules. The tag category and tags to be associated to this storage policy.
Supporting Types
VmStoragePolicyTagRule, VmStoragePolicyTagRuleArgs
- Tag
Category string - Name of the tag category.
- List<string>
- List of Name of tags to select from the given category.
- bool
- Include datastores with the given tags or exclude. Default
true
.
- Tag
Category string - Name of the tag category.
- []string
- List of Name of tags to select from the given category.
- bool
- Include datastores with the given tags or exclude. Default
true
.
- tag
Category String - Name of the tag category.
- List<String>
- List of Name of tags to select from the given category.
- Boolean
- Include datastores with the given tags or exclude. Default
true
.
- tag
Category string - Name of the tag category.
- string[]
- List of Name of tags to select from the given category.
- boolean
- Include datastores with the given tags or exclude. Default
true
.
- tag_
category str - Name of the tag category.
- Sequence[str]
- List of Name of tags to select from the given category.
- bool
- Include datastores with the given tags or exclude. Default
true
.
- tag
Category String - Name of the tag category.
- List<String>
- List of Name of tags to select from the given category.
- 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.