@pulumi/vsphere
Version:
A Pulumi package for creating vsphere resources
180 lines • 7.86 kB
JavaScript
;
// *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComputeClusterVmHostRule = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("./utilities");
/**
* The `vsphere.ComputeClusterVmHostRule` resource can be used to manage
* VM-to-host rules in a cluster, either created by the
* `vsphere.ComputeCluster` resource or looked up
* by the `vsphere.ComputeCluster` data source.
*
* This resource can create both _affinity rules_, where virtual machines run on
* specified hosts, or _anti-affinity_ rules, where virtual machines run on hosts
* outside of the ones specified in the rule. Virtual machines and hosts are
* supplied via groups, which can be managed via the
* `vsphere.ComputeClusterVmGroup` and
* `vsphere.ComputeClusterHostGroup`
* resources.
*
* > **NOTE:** This resource requires vCenter and is not available on direct ESXi
* connections.
*
* ## Example Usage
*
* The example below creates a virtual machine in a cluster using the
* `vsphere.VirtualMachine` resource in a cluster
* looked up by the `vsphere.ComputeCluster`
* data source. It then creates a group with this virtual machine. It also creates
* a host group off of the host looked up via the
* `vsphere.Host` data source. Finally, this
* virtual machine is configured to run specifically on that host via a
* `vsphere.ComputeClusterVmHostRule` resource.
*
* > Note how `vmGroupName` and
* `affinityHostGroupName` are sourced off of the
* `name` attributes from the
* `vsphere.ComputeClusterVmGroup` and
* `vsphere.ComputeClusterHostGroup`
* resources. This is to ensure that the rule is not created before the groups
* exist, which may not possibly happen in the event that the names came from a
* "static" source such as a variable.
*
* ```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: "datastore1",
* datacenterId: datacenter.id,
* }));
* const cluster = datacenter.then(datacenter => vsphere.getComputeCluster({
* name: "cluster-01",
* datacenterId: datacenter.id,
* }));
* const host = datacenter.then(datacenter => vsphere.getHost({
* name: "esxi-01.example.com",
* datacenterId: datacenter.id,
* }));
* const network = datacenter.then(datacenter => vsphere.getNetwork({
* name: "network1",
* datacenterId: datacenter.id,
* }));
* const vm = new vsphere.VirtualMachine("vm", {
* name: "test",
* resourcePoolId: cluster.then(cluster => cluster.resourcePoolId),
* datastoreId: datastore.then(datastore => datastore.id),
* numCpus: 2,
* memory: 2048,
* guestId: "otherLinux64Guest",
* networkInterfaces: [{
* networkId: network.then(network => network.id),
* }],
* disks: [{
* label: "disk0",
* size: 20,
* }],
* });
* const clusterVmGroup = new vsphere.ComputeClusterVmGroup("cluster_vm_group", {
* name: "test-cluster-vm-group",
* computeClusterId: cluster.then(cluster => cluster.id),
* virtualMachineIds: [vm.id],
* });
* const clusterHostGroup = new vsphere.ComputeClusterHostGroup("cluster_host_group", {
* name: "test-cluster-vm-group",
* computeClusterId: cluster.then(cluster => cluster.id),
* hostSystemIds: [host.then(host => host.id)],
* });
* const clusterVmHostRule = new vsphere.ComputeClusterVmHostRule("cluster_vm_host_rule", {
* computeClusterId: cluster.then(cluster => cluster.id),
* name: "test-cluster-vm-host-rule",
* vmGroupName: clusterVmGroup.name,
* affinityHostGroupName: clusterHostGroup.name,
* });
* ```
*
* ## 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
* $ pulumi import vsphere:index/computeClusterVmHostRule:ComputeClusterVmHostRule cluster_vm_host_rule \
* ```
*
* '{"compute_cluster_path": "/dc1/host/cluster1", \
*
* "name": "pulumi-test-cluster-vm-host-rule"}'
*/
class ComputeClusterVmHostRule extends pulumi.CustomResource {
/**
* Get an existing ComputeClusterVmHostRule 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 ComputeClusterVmHostRule(name, state, Object.assign(Object.assign({}, opts), { id: id }));
}
/**
* Returns true if the given object is an instance of ComputeClusterVmHostRule. 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'] === ComputeClusterVmHostRule.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["affinityHostGroupName"] = state ? state.affinityHostGroupName : undefined;
resourceInputs["antiAffinityHostGroupName"] = state ? state.antiAffinityHostGroupName : undefined;
resourceInputs["computeClusterId"] = state ? state.computeClusterId : undefined;
resourceInputs["enabled"] = state ? state.enabled : undefined;
resourceInputs["mandatory"] = state ? state.mandatory : undefined;
resourceInputs["name"] = state ? state.name : undefined;
resourceInputs["vmGroupName"] = state ? state.vmGroupName : undefined;
}
else {
const args = argsOrState;
if ((!args || args.computeClusterId === undefined) && !opts.urn) {
throw new Error("Missing required property 'computeClusterId'");
}
if ((!args || args.vmGroupName === undefined) && !opts.urn) {
throw new Error("Missing required property 'vmGroupName'");
}
resourceInputs["affinityHostGroupName"] = args ? args.affinityHostGroupName : undefined;
resourceInputs["antiAffinityHostGroupName"] = args ? args.antiAffinityHostGroupName : undefined;
resourceInputs["computeClusterId"] = args ? args.computeClusterId : undefined;
resourceInputs["enabled"] = args ? args.enabled : undefined;
resourceInputs["mandatory"] = args ? args.mandatory : undefined;
resourceInputs["name"] = args ? args.name : undefined;
resourceInputs["vmGroupName"] = args ? args.vmGroupName : undefined;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(ComputeClusterVmHostRule.__pulumiType, name, resourceInputs, opts);
}
}
exports.ComputeClusterVmHostRule = ComputeClusterVmHostRule;
/** @internal */
ComputeClusterVmHostRule.__pulumiType = 'vsphere:index/computeClusterVmHostRule:ComputeClusterVmHostRule';
//# sourceMappingURL=computeClusterVmHostRule.js.map