inframap icon indicating copy to clipboard operation
inframap copied to clipboard

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

Open dvmorris opened this issue 3 years ago • 8 comments

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/[email protected]/command.go:852 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0x21b7040, 0x0, 0xffffffff, 0xc00007c058)
	github.com/spf13/[email protected]/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/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

dvmorris avatar Jul 21 '21 13:07 dvmorris

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.

xescugc avatar Jul 27 '21 20:07 xescugc

I do have this in my main.tf:

  tags = var.tags

And this in my .tfvars file:

tags = ["tag1", "tag2"]

dvmorris avatar Jul 27 '21 20:07 dvmorris

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.

xescugc avatar Jul 27 '21 20:07 xescugc

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

dvmorris avatar Jul 27 '21 21:07 dvmorris

@dvmorris any progress on this issue?

kayahk avatar Aug 16 '22 09:08 kayahk

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

dvmorris avatar Aug 16 '22 11:08 dvmorris

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

matheusraz avatar Dec 07 '23 20:12 matheusraz