Skip to content

Commit

Permalink
Add additional datastore import test
Browse files Browse the repository at this point in the history
Make sure the user gets a helpful error if they only
provide a single ID when running import.

```
$ terraform import hpegl_pc_datastore.my_datastore badID
Error: import has invalid datastore id format

Provided import ID "badID" is invalid. Format
must be "<hci_cluster_uuid>,<datastore_id>". For example:
f8d3e2fd-a0e0-41a3-83b3-a8f92b21a9f3,e8beff7c-6fc8-42f4-bb9f-8e2935d69918
```
  • Loading branch information
stuart-mclaren-hpe committed Jan 17, 2025
1 parent 6873d8d commit 5d8adb7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/datastore/datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,37 @@ func TestAccDatastoreResourceMissingClusterId(t *testing.T) {
})
}

func TestAccDatastoreImportBadId(t *testing.T) {
config := providerConfig + `
resource "hpegl_pc_datastore" "test" {
name = "mclaren-ds19"
hci_cluster_uuid = "126fd201-9e6e-5e31-9ffb-a766265b1fd3"
datastore_type = "VVOL"
capacity_in_bytes = 17179869184
cluster_info = {
"name": "5305-CL"
}
}
`

expected := `import has invalid datastore id format(.|\n)*698de955-87b5-5fe6-b683-78c3948beede`
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
// Import
ExpectError: regexp.MustCompile(expected),
Config: config,
ImportState: true,
ResourceName: "hpegl_pc_datastore.test",
// Invalid id (not "<cluster id>,<datastore id>")
ImportStateId: "698de955-87b5-5fe6-b683-78c3948beede",
ImportStatePersist: true,
},
},
})
}

func TestAccDatastoreResourceMissingName(t *testing.T) {
config := providerConfig + `
resource "hpegl_pc_datastore" "test" {
Expand Down

0 comments on commit 5d8adb7

Please sign in to comment.