Skip to content

Commit

Permalink
Handle hypervisor cluster id mismatch
Browse files Browse the repository at this point in the history
Handle the corner case where a returned id may not match the id in the
current terraform state.  This should never happen because id's are
immutable.

If it does ever occur we will not overwrite any state
and will instead raise this error:

```
Error: error reading hypervisor cluster 298a299e-78f5-5acb-86ce-4e9fdc290ab7

  with hpegl_pc_hypervisor_cluster.test,
  on terraform_plugin_test.tf line 21, in resource "hpegl_pc_hypervisor_cluster" "test":
  21:   resource "hpegl_pc_hypervisor_cluster" "test" {

'id' mismatch: 298a299e-78f5-5acb-86ce-4e9fdc290ab7 !=
298a299e-78f5-5acb-86ce-4e9fdc290ab7
```
  • Loading branch information
stuart-mclaren-hpe committed Aug 27, 2024
1 parent 85f2849 commit 7796b7e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/resources/hypervisorcluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package hypervisorcluster

import (
"context"
"fmt"
"path"

"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/client"
Expand Down Expand Up @@ -68,6 +69,7 @@ func doRead(
dataP *HypervisorclusterModel,
diagsP *diag.Diagnostics,
) {

hypervisorClusterID := (*dataP).Id.ValueString()

grc := virtualization.
Expand Down Expand Up @@ -96,6 +98,25 @@ func doRead(
return
}

if getResp.GetId() == nil {
(*diagsP).AddError(
"error reading hypervisor cluster "+hypervisorClusterID,
"'id' is nil",
)

return
}

if *(getResp.GetId()) != hypervisorClusterID {
(*diagsP).AddError(
"error reading hypervisor cluster "+hypervisorClusterID,
fmt.Sprintf("'id' mismatch: %s != %s",
*(getResp.GetId()), hypervisorClusterID),
)

return
}

if getResp.GetName() == nil {
(*diagsP).AddError(
"error reading hypervisor cluster "+hypervisorClusterID,
Expand Down

0 comments on commit 7796b7e

Please sign in to comment.