Skip to content

Commit

Permalink
Handle datastore id mismatch
Browse files Browse the repository at this point in the history
Handle the corner case where a returned datastore 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 datastore

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

'id' mismatch: 698de955-87b5-5fe6-b683-78c3948beede !=
698de955-87b5-5fe6-b683-78c3948beede
```
  • Loading branch information
stuart-mclaren-hpe committed Aug 27, 2024
1 parent 85f2849 commit 6d57f73
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/resources/datastore/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ func doRead(
return
}

if datastore.GetId() == nil {
(*diagsP).AddError(
"error reading datastore",
"'id' is nil",
)

return
}

if *(datastore.GetId()) != datastoreID {
(*diagsP).AddError(
"error reading datastore",
fmt.Sprintf("'id' mismatch: %s != %s",
*(datastore.GetId()), datastoreID,
),
)

return
}

datastoreName := datastore.GetName()
if datastoreName == nil {
(*diagsP).AddError(
Expand Down

0 comments on commit 6d57f73

Please sign in to comment.