UNPKG

@pulumi/vsphere

Version:

A Pulumi package for creating vsphere resources

186 lines 7.54 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.ComputeClusterVmAffinityRule = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("./utilities"); /** * The `vsphere.ComputeClusterVmAffinityRule` resource can be used to * manage virtual machine affinity rules in a cluster, either created by the * `vsphere.ComputeCluster` resource or looked up * by the `vsphere.ComputeCluster` data source. * * This rule can be used to tell a set of virtual machines to run together on the * same host within a cluster. When configured, DRS will make a best effort to * ensure that the virtual machines run on the same host, or prevent any operation * that would keep that from happening, depending on the value of the * `mandatory` flag. * * > An affinity rule can only be used to place virtual machines on the same * _non-specific_ hosts. It cannot be used to pin virtual machines to a host. * To enable this capability, use the * `vsphere.ComputeClusterVmHostRule` * resource. * * > **NOTE:** This resource requires vCenter Server and is not available on * direct ESXi host connections. * * ## Example Usage * * The following example creates two virtual machines in a cluster using the * `vsphere.VirtualMachine` resource, creating the * virtual machines in the cluster looked up by the * `vsphere.ComputeCluster` data source. It * then creates an affinity rule for these two virtual machines, ensuring they * will run on the same host whenever possible. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as vsphere from "@pulumi/vsphere"; * * const datacenter = vsphere.getDatacenter({ * name: "dc-01", * }); * const datastore = datacenter.then(datacenter => vsphere.getDatastore({ * name: "datastore-01", * datacenterId: datacenter.id, * })); * const cluster = datacenter.then(datacenter => vsphere.getComputeCluster({ * name: "cluster-01", * datacenterId: datacenter.id, * })); * const network = datacenter.then(datacenter => vsphere.getNetwork({ * name: "VM Network", * datacenterId: datacenter.id, * })); * const vm: vsphere.VirtualMachine[] = []; * for (const range = {value: 0}; range.value < 2; range.value++) { * vm.push(new vsphere.VirtualMachine(`vm-${range.value}`, { * name: `foo-${range.value}`, * resourcePoolId: cluster.then(cluster => cluster.resourcePoolId), * datastoreId: datastore.then(datastore => datastore.id), * numCpus: 1, * memory: 1024, * guestId: "otherLinux64Guest", * networkInterfaces: [{ * networkId: network.then(network => network.id), * }], * disks: [{ * label: "disk0", * size: 20, * }], * })); * } * const vmAffinityRule = new vsphere.ComputeClusterVmAffinityRule("vm_affinity_rule", { * name: "vm-affinity-rule", * computeClusterId: cluster.then(cluster => cluster.id), * virtualMachineIds: vm.map((v, k) => [k, v]).map(([k, v]) => (v.id)), * }); * ``` * * The following example creates an affinity rule for a set of virtual machines * in the cluster by looking up the virtual machine UUIDs from the * `vsphere.VirtualMachine` data source. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as vsphere from "@pulumi/vsphere"; * * const vms = [ * "foo-0", * "foo-1", * ]; * const datacenter = vsphere.getDatacenter({ * name: "dc-01", * }); * const cluster = datacenter.then(datacenter => vsphere.getComputeCluster({ * name: "cluster-01", * datacenterId: datacenter.id, * })); * const vmsGetVirtualMachine = (new Array(vms.length)).map((_, i) => i).map(__index => (vsphere.getVirtualMachine({ * name: vms[__index], * datacenterId: _arg0_.id, * }))); * const vmAffinityRule = new vsphere.ComputeClusterVmAffinityRule("vm_affinity_rule", { * name: "vm-affinity-rule", * enabled: true, * computeClusterId: cluster.then(cluster => cluster.id), * virtualMachineIds: vmsGetVirtualMachine.map(__item => __item.id), * }); * ``` * * ## Import * * An existing rule can be imported into this resource by supplying * * both the path to the cluster, and the name the rule. If the name or cluster is * * not found, or if the rule is of a different type, an error will be returned. An * * example is below: * * ```sh * $ pulumi import vsphere:index/computeClusterVmAffinityRule:ComputeClusterVmAffinityRule vm_affinity_rule \ * ``` * * '{"compute_cluster_path": "/dc-01/host/cluster-01", \ * * "name": "vm-affinity-rule"}' */ class ComputeClusterVmAffinityRule extends pulumi.CustomResource { /** * Get an existing ComputeClusterVmAffinityRule resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new ComputeClusterVmAffinityRule(name, state, { ...opts, id: id }); } /** * Returns true if the given object is an instance of ComputeClusterVmAffinityRule. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === ComputeClusterVmAffinityRule.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["computeClusterId"] = state?.computeClusterId; resourceInputs["enabled"] = state?.enabled; resourceInputs["mandatory"] = state?.mandatory; resourceInputs["name"] = state?.name; resourceInputs["virtualMachineIds"] = state?.virtualMachineIds; } else { const args = argsOrState; if (args?.computeClusterId === undefined && !opts.urn) { throw new Error("Missing required property 'computeClusterId'"); } if (args?.virtualMachineIds === undefined && !opts.urn) { throw new Error("Missing required property 'virtualMachineIds'"); } resourceInputs["computeClusterId"] = args?.computeClusterId; resourceInputs["enabled"] = args?.enabled; resourceInputs["mandatory"] = args?.mandatory; resourceInputs["name"] = args?.name; resourceInputs["virtualMachineIds"] = args?.virtualMachineIds; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(ComputeClusterVmAffinityRule.__pulumiType, name, resourceInputs, opts); } } exports.ComputeClusterVmAffinityRule = ComputeClusterVmAffinityRule; /** @internal */ ComputeClusterVmAffinityRule.__pulumiType = 'vsphere:index/computeClusterVmAffinityRule:ComputeClusterVmAffinityRule'; //# sourceMappingURL=computeClusterVmAffinityRule.js.map