Skip to content

Commit

Permalink
misc: migrated to use filepath dir
Browse files Browse the repository at this point in the history
  • Loading branch information
sheensantoscapadngan committed Oct 23, 2024
1 parent 74dbb7f commit 1e75384
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions internal/provider/resource/project_secret_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resource
import (
"context"
"fmt"
"path/filepath"
"strings"
infisical "terraform-provider-infisical/internal/client"
infisicalclient "terraform-provider-infisical/internal/client"
Expand Down Expand Up @@ -293,20 +294,18 @@ func (r *projectSecretFolderResource) ImportState(ctx context.Context, req resou
return
}

// At the moment, the folder path returned by GetByID includes the folder being queried.
// We want to be consistent with the create conventions, so we remove the last part
parentFolderPath := filepath.Dir(folder.Folder.Path)

// Remove leading and trailing slashes.
trimmedPath := strings.Trim(folder.Folder.Path, "/")
var name string
parentFolderPath := "/"

if trimmedPath != "" {
// Split the path and get the last element as the name.
pathParts := strings.Split(trimmedPath, "/")
name = pathParts[len(pathParts)-1]
if len(pathParts) > 1 {
// At the moment, the folder path returned by GetByID includes the folder being queried.
// We want to be consistent with the create conventions, so we remove the last part
parentFolderPath += strings.Join(pathParts[:len(pathParts)-1], "/")
}
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("folder_path"), parentFolderPath)...)
Expand Down

0 comments on commit 1e75384

Please sign in to comment.