Skip to content

Commit

Permalink
Support terraform import.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenjun Shen committed Nov 30, 2023
1 parent ee4b87c commit c2d2b94
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/provider/storage_volume_snapshot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package provider
import (
"context"
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -181,7 +183,7 @@ func (r *StorageVolumeSnapshotResource) Create(ctx context.Context, req resource
// Read refreshes the Terraform state with the latest data.
func (r *StorageVolumeSnapshotResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var data *StorageVolumeSnapshotResourceModel

log.Printf("why why")
// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
Expand Down Expand Up @@ -316,5 +318,16 @@ func (r *StorageVolumeSnapshotResource) Delete(ctx context.Context, req resource

// ImportState imports a resource using ID from terraform import command by calling the Read method.
func (r *StorageVolumeSnapshotResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
// resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
idParts := strings.Split(req.ID, ",")
log.Printf("here here")
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
resp.Diagnostics.AddError(
"Unexpected Import Identifier",
fmt.Sprintf("Expected import identifier with format: name,svm_name,cx_profile_name. Got: %q", req.ID),
)
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("cx_profile_name"), idParts[1])...)
}

0 comments on commit c2d2b94

Please sign in to comment.