Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle disabled HA admission policy #611

Merged
merged 2 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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