rover: runtime error: invalid memory address or nil pointer dereference (Mislabeled Resource Type)

Posting this for now as I continue to debug, but maybe others are seeing similar issues.

Overview: Runtime error when attempting to generate graph from provided plan that points to an invalid memory address reference. Upon further debugging, it appears to be related to a Data source type being labeled as a Resource source type. At the moment I am unsure of how to reproduce.

Release Version: 3.0

ERROR Message:

> rover -planPath plan.out
2022/01/31 09:48:08 Starting Rover...
2022/01/31 09:48:08 Using provided plan...
2022/01/31 09:48:12 Generating resource overview...
2022/01/31 09:48:12 Generating resource map...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x174c28e]

goroutine 1 [running]:
main.(*rover).GenerateModuleMap(0xc000187680, 0xc00009fdd0, 0xc00036ac40, 0x38)
	/Users/joseestrada/rover/map.go:225 +0x1dae
main.(*rover).GenerateModuleMap(0xc000187680, 0xc00009e5a0, 0xc0003a8cf0, 0x25)
	/Users/joseestrada/rover/map.go:253 +0x2357
main.(*rover).GenerateModuleMap(0xc000187680, 0xc00050e750, 0xc000399170, 0x12)
	/Users/joseestrada/rover/map.go:253 +0x2357
main.(*rover).GenerateModuleMap(0xc000187680, 0xc000535b88, 0x0, 0x0)
	/Users/joseestrada/rover/map.go:253 +0x2357
main.(*rover).GenerateMap(0xc000187680, 0x0, 0x0)
	/Users/joseestrada/rover/map.go:335 +0x1ee
main.(*rover).generateAssets(0xc000187680, 0xc000187680, 0x2)
	/Users/joseestrada/rover/main.go:193 +0x130
main.main()
	/Users/joseestrada/rover/main.go:138 +0xea5

Additional Context: From what I gather and understand, it appears that my generated Terraform Plan is causing a runtime error due to a resource being mislabeled. I believe that a Data source is being labeled as a Resource type and thus causing the error.

This error is happening during the generating of the resource map where it appears to be setting the file Name of the resource as well as its line number (code link). To help deep dive into the issue a bit more I modified the code locally which is described by the following code block.

note: forgive my naming of things in advance. I am somewhat confused still about the difference between states and configs.

			if configured {
				var fname string
				ind := fmt.Sprintf("%s.%s", re.ResourceType, re.Name)

				log.Printf("Resource State Type: %s",rs.Type)

				if rs.Type == ResourceTypeData {
					
					log.Println("Resource State Type is Data")
					
					ind = fmt.Sprintf("data.%s", ind)
					fname = filepath.Base(configs[parentConfig].Module.DataResources[ind].Pos.Filename)
					re.Line = &configs[parentConfig].Module.DataResources[ind].Pos.Line
				} else if rs.Type == ResourceTypeResource {
					
					log.Printf("Resource Name: %s",re.Name)
					log.Printf("Resource Type: %s",re.ResourceType)
					for key := range configs[parentConfig].Module.ManagedResources {
						log.Printf("Parent Module Configs Managed Resource Key: %s",key)
					}

					fname = filepath.Base(configs[parentConfig].Module.ManagedResources[ind].Pos.Filename)
					re.Line = &configs[parentConfig].Module.ManagedResources[ind].Pos.Line
				}

				r.AddFileIfNotExists(parent, parentModule, fname)

				parent.Children[fname].Children[id] = re

			}

The following output here shows a bit more whats going on.

2022/01/31 09:48:12 Parent Module State Child Resource: module.atlantis_v2.module.ecs_service.module.alb_routing.data.aws_route53_zone.private
2022/01/31 09:48:12 Resource State Type: data
2022/01/31 09:48:12 Resource State Type is Data
2022/01/31 09:48:12 Parent Module State Child Resource: module.atlantis_v2.module.ecs_service.module.alb_routing.data.aws_route53_zone.public
2022/01/31 09:48:12 Resource State Type: resource
2022/01/31 09:48:12 Resource Name: public
2022/01/31 09:48:12 Resource Type: aws_route53_zone
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_lb_listener_rule.this
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_route53_record.public_record_prevent_destroy
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_route53_record.public_record
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_route53_record.private_record_prevent_destroy
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_route53_record.private_record
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_lb_target_group.this_prevent_destroy
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_lb_target_group.this
2022/01/31 09:48:12 Parent Module Configs Managed Resource Key: aws_lb_listener_rule.this_prevent_destroy

First thing to note here that is worth calling out, there is a 3 depth module call in play. I don’t think that matters but maybe it does. It can be seen here at the resource address module.atlantis_v2.module.ecs_service.module.alb_routing.data.aws_route53_zone.public is being labeled as a Resource as opposed to Data. The log further down confirms that the Parent module does not contain a resource for hosted zone. The odd thing here is that the resource prior is very similar, but is treated correctly as a Data type. It has an almost identical path to the impacted resource address.

At the moment I cannot immediately tell how this type is being set because I assume that is where the problem is located or will at least tell us more information about it. FWIW this is a runtime error that is happening when allowing rover to execute the Terraform Plan as well.

I will keep digging into this but if others see anything similar or have some tips help is appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 28 (11 by maintainers)

Most upvoted comments

Experiencing the same issue with a fairly large AWS-based TF state. Hopefully similar issue:

2022/02/09 16:10:46 Starting Rover...
2022/02/09 16:10:46 Initializing Terraform...
2022/02/09 16:11:01 Generating plan...
2022/02/09 16:29:07 Generating resource overview...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x165e1fb]

goroutine 1 [running]:
main.(*rover).PopulateModuleState(0x16e2680, 0xc029172ed0, 0xc0002348c0, 0x0)
	rover/rso.go:219 +0x19b
main.(*rover).GenerateResourceOverview(0xc0000f7320)
	rover/rso.go:319 +0x413
main.(*rover).generateAssets(0x0)
	rover/main.go:188 +0xc5
main.main()
	rover/main.go:138 +0xcbb

@nonbeing Oh this is very helpful, I’ll have a fix later today. 🙂

@Yashfork I’ll have a look in more detail tomorrow, thanks for reporting!

Hey @jlestrada , I’ll check this out a bit later. Thanks for the thorough documentation 😃 .

image

P.S. this is the visualization for our rather complex AWS setup (if I may say so myself) … I guess this is a mini stress test of sorts for Rover perhaps, and it’s passing this with flying colors! 😄

@JackFlukinger It’s working now! 🎉🎊 I’m even able to see the visualizations in the web app on localhost:9000 Thank you and well done! 👍

Hey @nonbeing , make sure you’re on the most recent 3.0 version. I’m pretty sure this is something on your end – the thrown line in your stacktrace (rso.go:219) is blank. Also @jlestrada , I believe @im2nguyen merged your PR and re-released rover with the modified block. I think this issue should probably be closed.

I’m also getting a stack trace but it looks quite different from the one posted here.

rover -planPath tfplan.out
2022/02/08 18:04:36 Starting Rover...
2022/02/08 18:04:36 Using provided plan...
2022/02/08 18:04:51 Generating resource overview...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x165e1fb]

goroutine 1 [running]:
main.(*rover).PopulateModuleState(0x16e2740, 0xc000333398, 0xc00020e640, 0x0)
	rover/rso.go:219 +0x19b
main.(*rover).PopulateModuleState(0x16e2680, 0xc000333398, 0xc00020e400, 0x0)
	rover/rso.go:267 +0x927
main.(*rover).GenerateResourceOverview(0xc000113320)
	rover/rso.go:319 +0x413
main.(*rover).generateAssets(0xc0000e9e38)
	rover/main.go:188 +0xc5
main.main()
	rover/main.go:138 +0xcbb

I’m on Rover version v0.3.0

The above crash is also happening when I run just rover without any commandline args.

Oh wait I got it… but not exactly sure of the details or if I am breaking anything else. To clarify, I added the following line here

if configured && childIndex.MatchString(id)

If i understand correctly, this is a conditional statement that matches Resources and Data Types that are Index types. If that is true, then I dont know why all id that are no Index types still seem to process okay. At this point the graph did generate successfully. Maybe someone with more knowledge can look into what the proper solution could be as I am sure I am breaking many use cases.