hashicorp / terraform-config-inspect

A helper library for shallow inspection of Terraform configurations
Mozilla Public License 2.0
376 stars 76 forks source link

Incompatible types using embed.FS type in LoadModuleFromFilesystem #68

Open heyealex opened 2 years ago

heyealex commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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.