Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible types using embed.FS type in LoadModuleFromFilesystem #68

Open
heyealex opened this issue Nov 8, 2021 · 2 comments
Open

Comments

@heyealex
Copy link

heyealex commented Nov 8, 2021

I'm trying to use LoadModuleFromFilesystem on an FS object obtained from the embed package, but since that function uses a custom FS module I get the following error that the FS i supplied does not implement the custom FS:

cannot use fs (type fs.FS) as type tfconfig.FS in assignment:
	fs.FS does not implement tfconfig.FS (wrong type for Open method)
		have Open(string) (fs.File, error)
		want Open(string) (tfconfig.File, error)

I wrote up a simple example showing what I'm trying to do. I also tested against an afero.FS and got the same result.

package main

import (
	"embed"
	"fmt"
	"github.com/hashicorp/terraform-config-inspect/tfconfig"
)

//go.embed ./*
var dotFS embed.FS

func main() {
	fmt.Printf("%T\n", dotFS) // embed.FS
	mod, _ := tfconfig.LoadModuleFromFilesystem(dotFS, "module/test")
	fmt.Println(mod)
}
@valentindeaconu
Copy link

valentindeaconu commented Nov 7, 2022

I think this helps to explain why it does not work.

To workaround this issue, you should try the following:

mod, _ := tfconfig.LoadModuleFromFilesystem(tfconfig.WrapFS(dotFS), "module/test")

@heyealex
Copy link
Author

heyealex commented Nov 7, 2022

Thank you for your response! I've added a task to update our current workaround to use WrapFS instead. I will let you know if I run into any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants