vsphere_compute_cluster_vm_dependency_rule
The vsphere_compute_cluster_vm_dependency_rule
resource can be used to manage VM dependency rules in a cluster, either created by the vsphere_compute_cluster
resource or looked up by the vsphere_compute_cluster
data source.
A virtual machine dependency rule applies to vSphere HA, and allows user-defined startup orders for virtual machines in the case of host failure. Virtual machines are supplied via groups, which can be managed via the vsphere_compute_cluster_vm_group
resource.
NOTE: This resource requires vCenter and is not available on direct ESXi connections.
Example Usage
The example below creates two virtual machine in a cluster using the vsphere_virtual_machine
resource in a cluster looked up by the vsphere_compute_cluster
data source. It then creates a group with this virtual machine. Two groups are created, each with one of the created VMs. Finally, a rule is created to ensure that vm1
starts before vm2
.
Note how
dependency_vm_group_name
andvm_group_name
are sourced off of thename
attributes from thevsphere_compute_cluster_vm_group
resource. 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.
data "vsphere_datacenter" "dc" { name = "dc1" } data "vsphere_datastore" "datastore" { name = "datastore1" datacenter_id = "${data.vsphere_datacenter.dc.id}" } data "vsphere_compute_cluster" "cluster" { name = "cluster1" datacenter_id = "${data.vsphere_datacenter.dc.id}" } data "vsphere_network" "network" { name = "network1" datacenter_id = "${data.vsphere_datacenter.dc.id}" } resource "vsphere_virtual_machine" "vm1" { name = "terraform-test1" resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}" datastore_id = "${data.vsphere_datastore.datastore.id}" num_cpus = 2 memory = 2048 guest_id = "other3xLinux64Guest" network_interface { network_id = "${data.vsphere_network.network.id}" } disk { label = "disk0" size = 20 } } resource "vsphere_virtual_machine" "vm2" { name = "terraform-test2" resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}" datastore_id = "${data.vsphere_datastore.datastore.id}" num_cpus = 2 memory = 2048 guest_id = "other3xLinux64Guest" network_interface { network_id = "${data.vsphere_network.network.id}" } disk { label = "disk0" size = 20 } } resource "vsphere_compute_cluster_vm_group" "cluster_vm_group1" { name = "terraform-test-cluster-vm-group1" compute_cluster_id = "${data.vsphere_compute_cluster.cluster.id}" virtual_machine_ids = ["${vsphere_virtual_machine.vm1.id}"] } resource "vsphere_compute_cluster_vm_group" "cluster_vm_group2" { name = "terraform-test-cluster-vm-group2" compute_cluster_id = "${data.vsphere_compute_cluster.cluster.id}" virtual_machine_ids = ["${vsphere_virtual_machine.vm2.id}"] } resource "vsphere_compute_cluster_vm_dependency_rule" "cluster_vm_dependency_rule" { compute_cluster_id = "${data.vsphere_compute_cluster.cluster.id}" name = "terraform-test-cluster-vm-dependency-rule" dependency_vm_group_name = "${vsphere_compute_cluster_vm_group.cluster_vm_group1.name}" vm_group_name = "${vsphere_compute_cluster_vm_group.cluster_vm_group2.name}" }
Argument Reference
The following arguments are supported:
-
compute_cluster_id
- (Required) The managed object reference ID of the cluster to put the group in. Forces a new resource if changed. -
name
- (Required) The name of the rule. This must be unique in the cluster. -
dependency_vm_group_name
- (Required) The name of the VM group that this rule depends on. The VMs defined in the group specified byvm_group_name
will not be started until the VMs in this group are started. -
vm_group_name
- (Required) The name of the VM group that is the subject of this rule. The VMs defined in this group will not be started until the VMs in the group specified bydependency_vm_group_name
are started. -
enabled
- (Optional) Enable this rule in the cluster. Default:true
. -
mandatory
- (Optional) When this value istrue
, 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.
Attribute Reference
The only attribute this resource exports is the id
of the resource, which is a combination of the managed object reference ID of the cluster, and the rule's key within the cluster configuration.
Importing
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:
terraform import vsphere_compute_cluster_vm_dependency_rule.cluster_vm_dependency_rule \ '{"compute_cluster_path": "/dc1/host/cluster1", \ "name": "terraform-test-cluster-vm-dependency-rule"}'
© 2018 HashiCorpLicensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/vsphere/r/compute_cluster_vm_dependency_rule.html