Skip to content

Commit

Permalink
fix(status_reasons): fixed status reasons in instance and baremetalse…
Browse files Browse the repository at this point in the history
…rver service
  • Loading branch information
ujjwal-ibm committed Apr 18, 2022
1 parent 8721546 commit e223c28
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 6 deletions.
9 changes: 9 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ func DataSourceIBMIsBareMetalServer() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},

isBareMetalServerStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -648,6 +654,9 @@ func dataSourceIBMISBareMetalServerRead(context context.Context, d *schema.Resou
if sr.Code != nil && sr.Message != nil {
currentSR[isBareMetalServerStatusReasonsCode] = *sr.Code
currentSR[isBareMetalServerStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isBareMetalServerStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down
9 changes: 9 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ func DataSourceIBMIsBareMetalServers() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},

isBareMetalServerStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -594,6 +600,9 @@ func dataSourceIBMISBareMetalServersRead(context context.Context, d *schema.Reso
if sr.Code != nil && sr.Message != nil {
currentSR[isBareMetalServerStatusReasonsCode] = *sr.Code
currentSR[isBareMetalServerStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isBareMetalServerStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down
9 changes: 9 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ func DataSourceIBMISInstance() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},

isInstanceStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -898,6 +904,9 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er
if sr.Code != nil && sr.Message != nil {
currentSR[isInstanceStatusReasonsCode] = *sr.Code
currentSR[isInstanceStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isInstanceStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down
9 changes: 9 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ func DataSourceIBMISInstances() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},

isInstanceStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -779,6 +785,9 @@ func instancesList(d *schema.ResourceData, meta interface{}) error {
if sr.Code != nil && sr.Message != nil {
currentSR[isInstanceStatusReasonsCode] = *sr.Code
currentSR[isInstanceStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isInstanceStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down
45 changes: 39 additions & 6 deletions ibm/service/vpc/resource_ibm_is_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vpc

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -51,6 +52,7 @@ const (
isBareMetalServerZone = "zone"
isBareMetalServerStatusReasonsCode = "code"
isBareMetalServerStatusReasonsMessage = "message"
isBareMetalServerStatusReasonsMoreInfo = "more_info"
isBareMetalServerDeleteType = "delete_type"
isBareMetalServerImage = "image"
isBareMetalServerKeys = "keys"
Expand Down Expand Up @@ -531,6 +533,11 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},
isBareMetalServerStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -591,7 +598,7 @@ func resourceIBMISBareMetalServerCreate(context context.Context, d *schema.Resou
if image, ok := d.GetOk(isBareMetalServerImage); ok {
imageStr = image.(string)
}
keySet := d.Get(isInstanceKeys).(*schema.Set)
keySet := d.Get(isBareMetalServerKeys).(*schema.Set)
if keySet.Len() != 0 {
keyobjs := make([]vpcv1.KeyIdentityIntf, keySet.Len())
for i, key := range keySet.List() {
Expand Down Expand Up @@ -1051,15 +1058,15 @@ func bareMetalServerGet(context context.Context, d *schema.ResourceData, meta in
case "*vpcv1.BareMetalServerNetworkInterfaceByPci":
{
primNic := bmsnic.(*vpcv1.BareMetalServerNetworkInterfaceByPci)
currentPrimNic[isInstanceNicAllowIPSpoofing] = *primNic.AllowIPSpoofing
currentPrimNic[isBareMetalServerNicAllowIPSpoofing] = *primNic.AllowIPSpoofing
currentPrimNic[isBareMetalServerNicEnableInfraNAT] = *primNic.EnableInfrastructureNat
currentPrimNic[isBareMetalServerNicPortSpeed] = *primNic.PortSpeed
if len(primNic.SecurityGroups) != 0 {
secgrpList := []string{}
for i := 0; i < len(primNic.SecurityGroups); i++ {
secgrpList = append(secgrpList, string(*(primNic.SecurityGroups[i].ID)))
}
currentPrimNic[isInstanceNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList)
currentPrimNic[isBareMetalServerNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList)
}

if primNic.AllowedVlans != nil {
Expand All @@ -1073,15 +1080,15 @@ func bareMetalServerGet(context context.Context, d *schema.ResourceData, meta in
case "*vpcv1.BareMetalServerNetworkInterfaceByVlan":
{
primNic := bmsnic.(*vpcv1.BareMetalServerNetworkInterfaceByVlan)
currentPrimNic[isInstanceNicAllowIPSpoofing] = *primNic.AllowIPSpoofing
currentPrimNic[isBareMetalServerNicAllowIPSpoofing] = *primNic.AllowIPSpoofing
currentPrimNic[isBareMetalServerNicEnableInfraNAT] = *primNic.EnableInfrastructureNat

if len(primNic.SecurityGroups) != 0 {
secgrpList := []string{}
for i := 0; i < len(primNic.SecurityGroups); i++ {
secgrpList = append(secgrpList, string(*(primNic.SecurityGroups[i].ID)))
}
currentPrimNic[isInstanceNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList)
currentPrimNic[isBareMetalServerNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList)
}
}
}
Expand Down Expand Up @@ -1191,6 +1198,9 @@ func bareMetalServerGet(context context.Context, d *schema.ResourceData, meta in
if sr.Code != nil && sr.Message != nil {
currentSR[isBareMetalServerStatusReasonsCode] = *sr.Code
currentSR[isBareMetalServerStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isBareMetalServerStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down Expand Up @@ -1502,7 +1512,30 @@ func isBareMetalServerRefreshFunc(client *vpcv1.VpcV1, id string, d *schema.Reso
// let know the isRestartStartAction() to stop
close(communicator)
if *bms.Status == "failed" {
return bms, *bms.Status, fmt.Errorf("The Bare Metal Server went into failed state")
bmsStatusReason := bms.StatusReasons

//set the status reasons
if bms.StatusReasons != nil {
statusReasonsList := make([]map[string]interface{}, 0)
for _, sr := range bms.StatusReasons {
currentSR := map[string]interface{}{}
if sr.Code != nil && sr.Message != nil {
currentSR[isBareMetalServerStatusReasonsCode] = *sr.Code
currentSR[isBareMetalServerStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isBareMetalServerStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
d.Set(isBareMetalServerStatusReasons, statusReasonsList)
}

out, err := json.MarshalIndent(bmsStatusReason, "", " ")
if err != nil {
return bms, *bms.Status, fmt.Errorf("[ERROR] The Bare Metal Server (%s) went into failed state during the operation \n [WARNING] Running terraform apply again will remove the tainted bare metal server and attempt to create the bare metal server again replacing the previous configuration", *bms.ID)
}
return bms, *bms.Status, fmt.Errorf("[ERROR] Bare Metal Server (%s) went into failed state during the operation \n (%+v) \n [WARNING] Running terraform apply again will remove the tainted Bare Metal Server and attempt to create the Bare Metal Server again replacing the previous configuration", *bms.ID, string(out))
}
return bms, *bms.Status, nil

Expand Down
8 changes: 8 additions & 0 deletions ibm/service/vpc/resource_ibm_is_bare_metal_server_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func ResourceIBMIsBareMetalServerAction() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},
isBareMetalServerStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -214,6 +219,9 @@ func bareMetalServerActionGet(context context.Context, sess *vpcv1.VpcV1, id str
if sr.Code != nil && sr.Message != nil {
currentSR[isBareMetalServerStatusReasonsCode] = *sr.Code
currentSR[isBareMetalServerStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isBareMetalServerStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down
13 changes: 13 additions & 0 deletions ibm/service/vpc/resource_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (
isInstanceStatusReasons = "status_reasons"
isInstanceStatusReasonsCode = "code"
isInstanceStatusReasonsMessage = "message"
isInstanceStatusReasonsMoreInfo = "more_info"
isEnableCleanDelete = "wait_before_delete"
isInstanceProvisioning = "provisioning"
isInstanceProvisioningDone = "done"
Expand Down Expand Up @@ -700,6 +701,12 @@ func ResourceIBMISInstance() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},

isInstanceStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -2045,6 +2052,9 @@ func isInstanceRefreshFunc(instanceC *vpcv1.VpcV1, id string, d *schema.Resource
if sr.Code != nil && sr.Message != nil {
currentSR[isInstanceStatusReasonsCode] = *sr.Code
currentSR[isInstanceStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isInstanceStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down Expand Up @@ -2327,6 +2337,9 @@ func instanceGet(d *schema.ResourceData, meta interface{}, id string) error {
if sr.Code != nil && sr.Message != nil {
currentSR[isInstanceStatusReasonsCode] = *sr.Code
currentSR[isInstanceStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isInstanceStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down
9 changes: 9 additions & 0 deletions ibm/service/vpc/resource_ibm_is_instance_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func ResourceIBMISInstanceAction() *schema.Resource {
Computed: true,
Description: "An explanation of the status reason",
},

isInstanceStatusReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason",
},
},
},
},
Expand Down Expand Up @@ -187,6 +193,9 @@ func resourceIBMISInstanceActionRead(context context.Context, d *schema.Resource
if sr.Code != nil && sr.Message != nil {
currentSR[isInstanceStatusReasonsCode] = *sr.Code
currentSR[isInstanceStatusReasonsMessage] = *sr.Message
if sr.MoreInfo != nil {
currentSR[isInstanceStatusReasonsMoreInfo] = *sr.MoreInfo
}
statusReasonsList = append(statusReasonsList, currentSR)
}
}
Expand Down

0 comments on commit e223c28

Please sign in to comment.