Skip to content

Commit

Permalink
Merge pull request #66 from Infisical/fix/address-secret-folder-impor…
Browse files Browse the repository at this point in the history
…t-path-issue

fix: address secret folder path issue during import
  • Loading branch information
maidul98 authored Oct 23, 2024
2 parents 4501337 + 1e75384 commit 28756d6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion 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,6 +294,10 @@ 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
Expand All @@ -303,7 +308,7 @@ func (r *projectSecretFolderResource) ImportState(ctx context.Context, req resou
name = pathParts[len(pathParts)-1]
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("folder_path"), folder.Folder.Path)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("folder_path"), parentFolderPath)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), name)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), folder.Folder.ID)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("environment_slug"), folder.Folder.Environment.EnvSlug)...)
Expand Down

0 comments on commit 28756d6

Please sign in to comment.