Skip to content

Commit

Permalink
Merge pull request #611 from terraform-providers/b-handle-disabled-ha…
Browse files Browse the repository at this point in the history
…-admission

Handle disabled HA admission policy
  • Loading branch information
bill-rich authored Sep 7, 2018
2 parents a5d9118 + 5fe95ce commit 59e715d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vsphere/resource_vsphere_compute_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,13 @@ func flattenClusterDasConfigInfo(d *schema.ResourceData, obj types.ClusterDasCon
}
}

// If AdmissionControlEnabled is false, AdmissionControlPolicy is still
// configured. Set ha_admission_control_policy to disabled before
// flattenBaseClusterDasAdmissionControlPolicy, so AdmissionControlEnabled
// can still be checked.
if *obj.AdmissionControlEnabled == false {
return d.Set("ha_admission_control_policy", clusterAdmissionControlTypeDisabled)
}
return flattenBaseClusterDasAdmissionControlPolicy(d, obj.AdmissionControlPolicy, version)
}

Expand All @@ -1259,6 +1266,8 @@ func expandBaseClusterDasAdmissionControlPolicy(
obj = expandClusterFailoverLevelAdmissionControlPolicy(d)
case clusterAdmissionControlTypeFailoverHosts:
obj = expandClusterFailoverHostAdmissionControlPolicy(d, version)
case clusterAdmissionControlTypeDisabled:
return nil
}

if version.Newer(viapi.VSphereVersion{Product: version.Product, Major: 6, Minor: 5}) {
Expand Down
61 changes: 61 additions & 0 deletions vsphere/resource_vsphere_compute_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ func TestAccResourceVSphereComputeCluster_basic(t *testing.T) {
})
}

func TestAccResourceVSphereComputeCluster_haAdmissionControlPolicyDisabled(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccResourceVSphereComputeClusterPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccResourceVSphereComputeClusterCheckExists(false),
Steps: []resource.TestStep{
{
Config: testAccResourceVSphereComputeClusterConfigHAAdmissionControlPolicyDisabled(),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereComputeClusterCheckExists(true),
testAccResourceVSphereComputeClusterCheckDRSEnabled(false),
),
},
},
})
}

func TestAccResourceVSphereComputeCluster_drsHAEnabled(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -576,6 +596,47 @@ resource "vsphere_compute_cluster" "compute_cluster" {
)
}

func testAccResourceVSphereComputeClusterConfigHAAdmissionControlPolicyDisabled() string {
return fmt.Sprintf(`
variable "datacenter" {
default = "%s"
}
variable "hosts" {
default = [
"%s",
"%s",
"%s",
]
}
data "vsphere_datacenter" "dc" {
name = "${var.datacenter}"
}
data "vsphere_host" "hosts" {
count = "${length(var.hosts)}"
name = "${var.hosts[count.index]}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
resource "vsphere_compute_cluster" "compute_cluster" {
name = "terraform-compute-cluster-test"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
host_system_ids = ["${data.vsphere_host.hosts.*.id}"]
ha_enabled = true
ha_admission_control_policy = "disabled"
force_evacuate_on_destroy = true
}
`,
os.Getenv("VSPHERE_DATACENTER"),
os.Getenv("VSPHERE_ESXI_HOST5"),
os.Getenv("VSPHERE_ESXI_HOST6"),
os.Getenv("VSPHERE_ESXI_HOST7"),
)
}

func testAccResourceVSphereComputeClusterConfigBasic() string {
return fmt.Sprintf(`
variable "datacenter" {
Expand Down

0 comments on commit 59e715d

Please # to comment.