Skip to content

Commit

Permalink
fixed system resource bugs (#192)
Browse files Browse the repository at this point in the history
Signed-off-by: Shendge <[email protected]>
  • Loading branch information
shenda1 committed Jun 14, 2024
1 parent da21f45 commit 6716757
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/resources/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,7 @@ Import is supported using the following syntax:

# import system
terraform import powerflex_system.test ""

# Another way to import system using system ID
terraform import powerflex_system.test "system_id"
```
5 changes: 4 additions & 1 deletion examples/resources/powerflex_system/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
# */

# import system
terraform import powerflex_system.test ""
terraform import powerflex_system.test ""

# Another way to import system using system ID
terraform import powerflex_system.test "system_id"
30 changes: 30 additions & 0 deletions powerflex/provider/system_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,24 @@ func (r *systemResource) Delete(ctx context.Context, req resource.DeleteRequest,

func (r *systemResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
// Retrieve import ID and save to id attribute
if req.ID != "" {
systems, err := r.client.GetInstance("")
if err != nil {
resp.Diagnostics.AddError(
"Error in getting system instance on the PowerFlex cluster",
"Could not get system instance, unexpected err: "+err.Error(),
)
return
}

if req.ID != systems[0].ID {
resp.Diagnostics.AddError(
"Error in importing system",
"Could not import system with ID: "+req.ID,
)
return
}
}
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

Expand Down Expand Up @@ -500,6 +518,18 @@ func (r *systemResource) PopulateSDCDetails(ctx context.Context, plan *models.Sy
SdcGuids = append(SdcGuids, sdc.Sdc.SdcGUID)
}
plan.SdcGuids, _ = types.ListValueFrom(ctx, types.StringType, SdcGuids)
} else {
diags.Append(plan.SdcGuids.ElementsAs(ctx, &SdcGuids, true)...)
for _, guid := range SdcGuids {
_, err := r.system.FindSdc("SdcGUID", guid)
if err != nil {
diags.AddError(
"Error getting SDC with GUID: ",
"unexpected error: "+err.Error(),
)
return
}
}
}
return
}
Expand Down
10 changes: 10 additions & 0 deletions powerflex/provider/system_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func TestAccSystemResource(t *testing.T) {
Config: ProviderConfigForTesting + SystemResourceConfig6,
ExpectError: regexp.MustCompile(".*Error getting SDC with ID.*"),
},
{
Config: ProviderConfigForTesting + SystemResourceConfig9,
ExpectError: regexp.MustCompile(".*Error getting SDC with GUID.*"),
},
{
Config: ProviderConfigForTesting + SystemResourceConfig1,
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down Expand Up @@ -190,3 +194,9 @@ resource "powerflex_system" "test" {
sdc_ids = [data.powerflex_sdc.selected.id]
}
`
var SystemResourceConfig9 = `
resource "powerflex_system" "test" {
restricted_mode = "Guid"
sdc_guids = ["invalid_guid"]
}
`

0 comments on commit 6716757

Please sign in to comment.