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

panic: interface conversion: interface {} is string, not []interface {} #153

Open
dvmorris opened this issue Jul 21, 2021 · 8 comments
Open
Assignees
Labels
bug Something isn't working Provider: Google

Comments

@dvmorris
Copy link

I'm trying to generate a graph from a GCP HCL configuration, and I'm receiving this error. I installed inframap on MacOS via homebrew today, inframap--0.6.7.big_sur.bottle.tar.gz

panic: interface conversion: interface {} is string, not []interface {}

goroutine 1 [running]:
github.com/cycloidio/inframap/provider/google.Provider.PreProcess(0xc00009a2a0, 0x0, 0x0, 0x38)
	github.com/cycloidio/inframap/provider/google/google.go:192 +0xaa5
github.com/cycloidio/inframap/generate.preprocess(0xc000c00180, 0xc00009a2a0, 0xc001010100, 0xe, 0x22acba0)
	github.com/cycloidio/inframap/generate/state.go:841 +0x1b4
github.com/cycloidio/inframap/generate.FromHCL(0x1d36420, 0xc000b46c90, 0x169bb64, 0x9, 0x1010100, 0x0, 0x0, 0x2f78)
	github.com/cycloidio/inframap/generate/hcl.go:156 +0x100f
github.com/cycloidio/inframap/cmd.glob..func1(0x21b6b40, 0xc000b91b70, 0x1, 0x1, 0x0, 0x0)
	github.com/cycloidio/inframap/cmd/generate.go:69 +0x2f0
github.com/spf13/cobra.(*Command).execute(0x21b6b40, 0xc000b91b50, 0x1, 0x1, 0x21b6b40, 0xc000b91b50)
	github.com/spf13/cobra@v1.1.3/command.go:852 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0x21b7040, 0x0, 0xffffffff, 0xc00007c058)
	github.com/spf13/cobra@v1.1.3/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.1.3/command.go:897
github.com/cycloidio/inframap/cmd.Execute(...)
	github.com/cycloidio/inframap/cmd/root.go:27
main.main()
	github.com/cycloidio/inframap/main.go:10 +0x2e
@xescugc
Copy link
Member

xescugc commented Jul 27, 2021

Ok I see the error, it has an easy fix but I would like to be sure.

For what I see you used an HCL an input, could you check that one of the tags attribute instead of being tags = ["tag1", "tag2"] is something like tags = "tag1" which should be invalid no?

I want to be sure because we are assuming tags is always a list of strings which from the documentation https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#tags it should be. So I'll just ignore the error as it's invalid configuration on this case.

@dvmorris
Copy link
Author

I do have this in my main.tf:

  tags = var.tags

And this in my .tfvars file:

tags = ["tag1", "tag2"]

@xescugc xescugc self-assigned this Jul 27, 2021
@xescugc xescugc added the bug Something isn't working label Jul 27, 2021
@xescugc
Copy link
Member

xescugc commented Jul 27, 2021

Ok IDK why I thought that we where already interpolating the variables, we are not, so we are reading the tags as var.tags and not as ["tag1", "tag2"].

I'll take a look to check if there is an internal function to do this or if I have to manually do the interpolation.

I see that you are using the .tfvars file, I'll check if it's read by default by Terraform (for what I see https://www.terraform.io/docs/language/values/variables.html#variable-definitions-tfvars-files there are some that maybe) but I'll most likely also add a --var-file like Terraform to specify any custom var file.

I cannot tell you an estimation on when this will be solved but I'll work on it as it's a big missing feature to interpolate variables on HCL generation.

@dvmorris
Copy link
Author

Thanks, I'm looking forward to trying out the fix whenever it's available.

@kayahk
Copy link

kayahk commented Aug 16, 2022

@dvmorris any progress on this issue?

@dvmorris
Copy link
Author

I haven't tried this in a while, have any changes been made that might make it worth trying again?

@matheusraz
Copy link

Is there any fix for this? Im facing the same issue here

@andreineculau
Copy link

Facing a similar issue

panic: interface conversion: interface {} is map[string]interface {}, not []interface {}

goroutine 1 [running]:
github.com/cycloidio/inframap/provider/google.Provider.PreProcess({{}}, 0x14000a5b920)
        github.com/cycloidio/inframap/provider/google/google.go:191 +0x440
github.com/cycloidio/inframap/generate.preprocess(0x14000aeec60, 0x14000a5b920, {0x70?, 0x54?, 0xac?, 0x0?})
        github.com/cycloidio/inframap/generate/state.go:869 +0x110
github.com/cycloidio/inframap/generate.FromState({0x14000480000, 0x2b3ed, 0x2b3ee}, {0x0?, 0x0?, 0x0?, 0x0?})
        github.com/cycloidio/inframap/generate/state.go:185 +0x48c
github.com/cycloidio/inframap/cmd.init.func1(0x1400025ef00?, {0x14000383f60?, 0x4?, 0x100572a25?})
        github.com/cycloidio/inframap/cmd/generate.go:50 +0x1e4
github.com/spf13/cobra.(*Command).execute(0x10159b880, {0x14000383f40, 0x1, 0x1})
        github.com/spf13/cobra@v1.5.0/command.go:872 +0x574
github.com/spf13/cobra.(*Command).ExecuteC(0x10159bd80)
        github.com/spf13/cobra@v1.5.0/command.go:990 +0x318
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.5.0/command.go:918
github.com/cycloidio/inframap/cmd.Execute(...)
        github.com/cycloidio/inframap/cmd/root.go:27
main.main()
        github.com/cycloidio/inframap/main.go:10 +0x24

which points to https://github.com/cycloidio/inframap/blob/b90d6ec/provider/google/google.go#L191

but I can't spot any issues with the tags in the tfstate, and I can't see how tags would be a list, rather than a map

$ cat terraform.tfstate | grep 'tags'
            "tags": {
            "tags_all": {
            "tags": {
            "tags_all": {
            "tags": {
            "tags_all": {
            "tags": {
            "tags_all": {
                "tags": {},
            "tags": {
            "tags_all": {
            "tags": {
            "tags_all": {
            "tags": {
            "tags_all": {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Provider: Google
Projects
None yet
Development

No branches or pull requests

5 participants