import * as pulumi from "@pulumi/pulumi"; /** * The `vsphere.ComputeClusterVmAffinityRule` resource can be used to * manage virtual machine affinity rules in a cluster, either created by the * [`vsphere.ComputeCluster`][tf-vsphere-cluster-resource] resource or looked up * by the [`vsphere.ComputeCluster`][tf-vsphere-cluster-data-source] data source. * * [tf-vsphere-cluster-resource]: /docs/providers/vsphere/r/compute_cluster.html * [tf-vsphere-cluster-data-source]: /docs/providers/vsphere/d/compute_cluster.html * * 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`][tf-vsphere-cluster-vm-host-rule-resource] * resource. * * [tf-vsphere-cluster-vm-host-rule-resource]: /docs/providers/vsphere/r/compute_cluster_vm_host_rule.html * * > **NOTE:** This resource requires vCenter 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`][tf-vsphere-vm-resource] resource, creating the * virtual machines in the cluster looked up by the * [`vsphere.ComputeCluster`][tf-vsphere-cluster-data-source] data source. It * then creates an affinity rule for these two virtual machines, ensuring they * will run on the same host whenever possible. * * [tf-vsphere-vm-resource]: /docs/providers/vsphere/r/virtual_machine.html * * ```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`][tf-vsphere-vm-data-source] data source. * * [tf-vsphere-vm-data-source]: /docs/providers/vsphere/d/virtual_machine.html * * ```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: * * [docs-import]: https://developer.hashicorp.com/terraform/cli/import * * ```sh * terraform import vsphere_compute_cluster_vm_affinity_rule.vm_affinity_rule \ * '{"compute_cluster_path": "/dc-01/host/cluster-01", \ * "name": "vm-affinity-rule"}' * ``` */ export declare 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: string, id: pulumi.Input, state?: ComputeClusterVmAffinityRuleState, opts?: pulumi.CustomResourceOptions): ComputeClusterVmAffinityRule; /** * 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: any): obj is ComputeClusterVmAffinityRule; /** * The [managed object reference * ID][docs-about-morefs] of the cluster to put the group in. Forces a new * resource if changed. * * [docs-about-morefs]: /docs/providers/vsphere/index.html#use-of-managed-object-references-by-the-vsphere-provider */ readonly computeClusterId: pulumi.Output; /** * Enable this rule in the cluster. Default: `true`. */ readonly enabled: pulumi.Output; /** * When this value is `true`, prevents any virtual * machine operations that may violate this rule. Default: `false`. * * > **NOTE:** The namespace for rule names on this resource (defined by the * `name` argument) is shared with all rules in the cluster - consider * this when naming your rules. */ readonly mandatory: pulumi.Output; /** * The name of the rule. This must be unique in the cluster. */ readonly name: pulumi.Output; /** * The UUIDs of the virtual machines to run * on the same host together. */ readonly virtualMachineIds: pulumi.Output; /** * Create a ComputeClusterVmAffinityRule resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name: string, args: ComputeClusterVmAffinityRuleArgs, opts?: pulumi.CustomResourceOptions); } /** * Input properties used for looking up and filtering ComputeClusterVmAffinityRule resources. */ export interface ComputeClusterVmAffinityRuleState { /** * The [managed object reference * ID][docs-about-morefs] of the cluster to put the group in. Forces a new * resource if changed. * * [docs-about-morefs]: /docs/providers/vsphere/index.html#use-of-managed-object-references-by-the-vsphere-provider */ computeClusterId?: pulumi.Input; /** * Enable this rule in the cluster. Default: `true`. */ enabled?: pulumi.Input; /** * When this value is `true`, prevents any virtual * machine operations that may violate this rule. Default: `false`. * * > **NOTE:** The namespace for rule names on this resource (defined by the * `name` argument) is shared with all rules in the cluster - consider * this when naming your rules. */ mandatory?: pulumi.Input; /** * The name of the rule. This must be unique in the cluster. */ name?: pulumi.Input; /** * The UUIDs of the virtual machines to run * on the same host together. */ virtualMachineIds?: pulumi.Input[]>; } /** * The set of arguments for constructing a ComputeClusterVmAffinityRule resource. */ export interface ComputeClusterVmAffinityRuleArgs { /** * The [managed object reference * ID][docs-about-morefs] of the cluster to put the group in. Forces a new * resource if changed. * * [docs-about-morefs]: /docs/providers/vsphere/index.html#use-of-managed-object-references-by-the-vsphere-provider */ computeClusterId: pulumi.Input; /** * Enable this rule in the cluster. Default: `true`. */ enabled?: pulumi.Input; /** * When this value is `true`, prevents any virtual * machine operations that may violate this rule. Default: `false`. * * > **NOTE:** The namespace for rule names on this resource (defined by the * `name` argument) is shared with all rules in the cluster - consider * this when naming your rules. */ mandatory?: pulumi.Input; /** * The name of the rule. This must be unique in the cluster. */ name?: pulumi.Input; /** * The UUIDs of the virtual machines to run * on the same host together. */ virtualMachineIds: pulumi.Input[]>; }