Skip to content

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

@jlestrada

Description

@jlestrada

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions