Skip to content

Commit

Permalink
Add missing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkad committed Dec 8, 2023
1 parent ca04a8e commit 9aea64a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
11 changes: 7 additions & 4 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta
}
d.Set("min_processors", powervmdata.Minproc)
d.Set(helpers.PIInstanceProgress, powervmdata.Progress)
if powervmdata.StorageType != nil {
if powervmdata.StorageType != nil && *powervmdata.StorageType != "" {
d.Set(helpers.PIInstanceStorageType, powervmdata.StorageType)
}
d.Set(PIInstanceStoragePool, powervmdata.StoragePool)
Expand Down Expand Up @@ -502,7 +502,10 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta
d.Set("min_virtual_cores", powervmdata.VirtualCores.Min)
}
d.Set(helpers.PIInstanceLicenseRepositoryCapacity, powervmdata.LicenseRepositoryCapacity)
d.Set(PIInstanceDeploymentType, powervmdata.DeploymentType)
if powervmdata.DeploymentType != "" {
d.Set(PIInstanceDeploymentType, powervmdata.DeploymentType)
}

return nil
}

Expand Down Expand Up @@ -843,7 +846,7 @@ func isWaitForPIInstanceAvailable(ctx context.Context, client *st.IBMPIInstanceC

stateConf := &resource.StateChangeConf{
Pending: []string{"PENDING", helpers.PIInstanceBuilding, helpers.PIInstanceHealthWarning},
Target: []string{helpers.PIInstanceAvailable, helpers.PIInstanceHealthOk, "ERROR", ""},
Target: []string{helpers.PIInstanceAvailable, helpers.PIInstanceHealthOk, "ERROR", "", "SHUTOFF"},
Refresh: isPIInstanceRefreshFunc(client, id, instanceReadyStatus),
Delay: 30 * time.Second,
MinTimeout: queryTimeOut,
Expand All @@ -861,7 +864,7 @@ func isPIInstanceRefreshFunc(client *st.IBMPIInstanceClient, id, instanceReadySt
return nil, "", err
}
// Check for `instanceReadyStatus` health status and also the final health status "OK"
if *pvm.Status == helpers.PIInstanceAvailable && (pvm.Health.Status == instanceReadyStatus || pvm.Health.Status == helpers.PIInstanceHealthOk) {
if (*pvm.Status == helpers.PIInstanceAvailable || *pvm.Status == "SHUTOFF") && (pvm.Health.Status == instanceReadyStatus || pvm.Health.Status == helpers.PIInstanceHealthOk) {
return pvm, helpers.PIInstanceAvailable, nil
}
if *pvm.Status == "ERROR" {
Expand Down
31 changes: 25 additions & 6 deletions ibm/service/power/resource_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func testAccCheckIBMPIInstanceConfig(name, instanceHealthStatus string) string {
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus)
}

func testAccCheckIBMPIInstanceDeploymentTypeConfig(name, instanceHealthStatus string) string {
func testAccCheckIBMPIInstanceDeploymentTypeConfig(name, instanceHealthStatus, epic, systype string) string {
return fmt.Sprintf(`
resource "ibm_pi_key" "key" {
pi_cloud_instance_id = "%[1]s"
Expand All @@ -84,16 +84,16 @@ func testAccCheckIBMPIInstanceDeploymentTypeConfig(name, instanceHealthStatus st
pi_proc_type = "dedicated"
pi_image_id = data.ibm_pi_image.power_image.id
pi_key_pair_name = ibm_pi_key.key.key_id
pi_sys_type = "e980"
pi_sys_type = "%[7]s"
pi_cloud_instance_id = "%[1]s"
pi_storage_type = "tier1"
pi_storage_type = "%[8]s"
pi_health_status = "%[5]s"
pi_network {
network_id = data.ibm_pi_network.power_networks.id
}
pi_deployment_type = "EPIC"
pi_deployment_type = "%[6]s"
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus)
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus, epic, systype, acc.PiStorageType)
}

func testAccIBMPIInstanceNetworkConfig(name, privateNetIP string) string {
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestAccIBMPIInstanceDeploymentType(t *testing.T) {
CheckDestroy: testAccCheckIBMPIInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIInstanceDeploymentTypeConfig(name, helpers.PIInstanceHealthWarning),
Config: testAccCheckIBMPIInstanceDeploymentTypeConfig(name, "OK", "EPIC", "e980"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPIInstanceExists(instanceRes),
resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name),
Expand Down Expand Up @@ -584,3 +584,22 @@ func testAccCheckIBMPIInstanceStatus(n, status string) resource.TestCheckFunc {
return nil
}
}

func TestAccIBMPIInstanceDeploymentTypeNoStorage(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMPIInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIInstanceDeploymentTypeConfig(name, "OK", "VMNoStorage", "s922"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPIInstanceExists(instanceRes),
resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name),
),
},
},
})
}

0 comments on commit 9aea64a

Please sign in to comment.