jrhouston / tfk8s

A tool for converting Kubernetes YAML manifests to Terraform HCL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

panic: value is null during converting files from Prometheus stack, no clue for further yaml debug

k2m30 opened this issue · comments

I try to convert files from well-known repo for Prometheus stack

It mostly works fine, however three files raise an error. It would be nice to know at least, which line or tag in YAML file causes t. I will convert these files manually, no big deal, but probably you would like to have a look:

prometheus-roleBindingSpecificNamespaces.yaml:

panic: value is null

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.LengthInt(0x0, 0x0, 0x0, 0x0, 0xc00014e801)
	/Users/k2m30/go/pkg/mod/github.com/zclconf/go-cty@v1.8.0/cty/value_ops.go:1058 +0x28b
github.com/zclconf/go-cty/cty.Value.AsValueMap(0x0, 0x0, 0x0, 0x0, 0x13627e0)
	/Users/k2m30/go/pkg/mod/github.com/zclconf/go-cty@v1.8.0/cty/value_ops.go:1315 +0x9d
main.yamlToHCL(0x1236b48, 0xc0001376a0, 0x11c5e20, 0xc00016a120, 0x0, 0x0, 0x0, 0x0, 0x1236b48, 0xc0001376a0, ...)
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:90 +0x151
main.YAMLToTerraformResources(0x12340d0, 0xc0000b0680, 0x0, 0x0, 0xc0000b0000, 0x0, 0x0, 0xc0000ae9ba, 0xc000099cd0)
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:162 +0x409
main.main()
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:204 +0x331

prometheus-roleSpecificNamespaces.yaml:

panic: value is null

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.LengthInt(0x0, 0x0, 0x0, 0x0, 0xc000195901)
	/Users/k2m30/go/pkg/mod/github.com/zclconf/go-cty@v1.8.0/cty/value_ops.go:1058 +0x28b
github.com/zclconf/go-cty/cty.Value.AsValueMap(0x0, 0x0, 0x0, 0x0, 0x13627e0)
	/Users/k2m30/go/pkg/mod/github.com/zclconf/go-cty@v1.8.0/cty/value_ops.go:1315 +0x9d
main.yamlToHCL(0x1236b48, 0xc0001c2fd0, 0x11c5e20, 0xc0001e2d20, 0x0, 0x0, 0x0, 0x0, 0x1236b48, 0xc0001c2fd0, ...)
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:90 +0x151
main.YAMLToTerraformResources(0x12340d0, 0xc000010690, 0x0, 0x0, 0xc000010000, 0x0, 0x0, 0xc00001cb4a, 0xc00005fce0)
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:162 +0x409
main.main()
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:204 +0x331

grafana-dashboardDefinitions.yaml:

panic: value is null

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.LengthInt(0x0, 0x0, 0x0, 0x0, 0xc000128f01)
	/Users/k2m30/go/pkg/mod/github.com/zclconf/go-cty@v1.8.0/cty/value_ops.go:1058 +0x28b
github.com/zclconf/go-cty/cty.Value.AsValueMap(0x0, 0x0, 0x0, 0x0, 0x13627e0)
	/Users/k2m30/go/pkg/mod/github.com/zclconf/go-cty@v1.8.0/cty/value_ops.go:1315 +0x9d
main.yamlToHCL(0x1236b48, 0xc00027d0a0, 0x11c5e20, 0xc000ff0ff0, 0x0, 0x0, 0x0, 0x0, 0x1236b48, 0xc00027d0a0, ...)
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:90 +0x151
main.YAMLToTerraformResources(0x12340d0, 0xc00012a680, 0x0, 0x0, 0xc000120000, 0x0, 0x0, 0xc0001289ba, 0xc000111cd0)
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:162 +0x409
main.main()
	/Users/k2m30/go/pkg/mod/github.com/jrhouston/tfk8s@v0.1.5/tfk8s.go:204 +0x331

Thanks

Ah, I see what the problem is. These manifests are lists of multiple resources, and the tool is crashing when it tires to grab the metadata to generate the resource name because there is no metadata field on a list.

The kubernetes_manifest resource only operates on individual resources so I need to add some code here to split the list and spit out individual Terraform resources.