Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

resource/aws_main_route_table_association: Crash during creation #16593

Closed
ghost opened this issue Dec 4, 2020 · 8 comments · Fixed by #16680
Closed

resource/aws_main_route_table_association: Crash during creation #16593

ghost opened this issue Dec 4, 2020 · 8 comments · Fixed by #16680
Assignees
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@ghost
Copy link

ghost commented Dec 4, 2020

This issue was originally opened by @paschalidi as hashicorp/terraform#27142. It was migrated here as a result of the provider split. The original body of the issue is below.


Version

Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/aws v3.19.0

https://gist.github.com/paschalidi/acdf7d52afbe0e415a5a26dca96e2478

@ghost ghost added the bug Addresses a defect in current functionality. label Dec 4, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 4, 2020
@bflad bflad added crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 4, 2020
@bflad
Copy link
Contributor

bflad commented Dec 4, 2020

Relevant snippet of log:

2020-12-04T14:18:21.552Z [DEBUG] plugin.terraform-provider-aws_v3.19.0_x5: panic: runtime error: invalid memory address or nil pointer dereference
2020-12-04T14:18:21.552Z [DEBUG] plugin.terraform-provider-aws_v3.19.0_x5: [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x50f1174]
2020-12-04T14:18:21.552Z [DEBUG] plugin.terraform-provider-aws_v3.19.0_x5: 
2020-12-04T14:18:21.552Z [DEBUG] plugin.terraform-provider-aws_v3.19.0_x5: goroutine 133 [running]:
2020-12-04T14:18:21.552Z [DEBUG] plugin.terraform-provider-aws_v3.19.0_x5: github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsMainRouteTableAssociationCreate(0xc0019c9280, 0x6259600, 0xc0016fc100, 0x0, 0xffffffffffffffff)
2020-12-04T14:18:21.552Z [DEBUG] plugin.terraform-provider-aws_v3.19.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_main_route_table_association.go:55 +0x244

Given the code:

mainAssociation, err := findMainRouteTableAssociation(conn, vpcId)
if err != nil {
return err
}
resp, err := conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{
AssociationId: mainAssociation.RouteTableAssociationId,

The mainAssociation needs a nil check to return an error before dereferencing, e.g.

	mainAssociation, err := findMainRouteTableAssociation(conn, vpcId)

	if err != nil {
		return fmt.Errorf("error finding EC2 VPC (%s) main route table association: %w", vpcId, err)
	}

	if mainAssociation == nil {
		return fmt.Errorf("error finding EC2 VPC (%s) main route table association: not found", vpcId)
	}

	resp, err := conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{

This won't prevent whatever caused the issue to begin with, but it will at least return a proper error instead of the crash.

@bflad bflad changed the title Reporting a Terraform crash resource/aws_main_route_table_association: Crash during creation Dec 4, 2020
@bflad
Copy link
Contributor

bflad commented Dec 4, 2020

@paschalidi do you have any additional information about what may have caused this crash? e.g. what you were trying to do, an example configuration, etc.

@paschalidi
Copy link

paschalidi commented Dec 4, 2020

hey well, I was trying to set up a vpc with some ec2 instances. I dont know if that helps but I run many time the apply command without planning first. I did the same with the destroy.

After a while things were out of sync and terraform was crashing.

I hope this helps a little @bdoepf. Cant say more than that unfortunately, but I hope I can help

@bflad bflad self-assigned this Dec 9, 2020
bflad added a commit that referenced this issue Dec 9, 2020
…when VPC main route table association is not found

Reference: #16593

This is quick fix to replace the crash behavior with an actual error message. Additional information is needed to determine why this issue occurs (e.g. EC2 eventual consistency, problematic configurations, etc.) but this at least gives operators a better chance to continue other parts of the apply successfully and potentially just rerun the errant resource.

Output from acceptance testing:

```
--- PASS: TestAccAWSMainRouteTableAssociation_basic (62.60s)
```
@bflad
Copy link
Contributor

bflad commented Dec 9, 2020

Fix submitted to return an error instead of crash in this situation: #16680

@paschalidi
Copy link

Thanks for looking into this @bflad.

@bflad bflad added this to the v3.22.0 milestone Dec 16, 2020
bflad added a commit that referenced this issue Dec 16, 2020
…when VPC main route table association is not found (#16680)

Reference: #16593

This is quick fix to replace the crash behavior with an actual error message. Additional information is needed to determine why this issue occurs (e.g. EC2 eventual consistency, problematic configurations, etc.) but this at least gives operators a better chance to continue other parts of the apply successfully and potentially just rerun the errant resource.

Output from acceptance testing:

```
--- PASS: TestAccAWSMainRouteTableAssociation_basic (62.60s)
```
@bflad
Copy link
Contributor

bflad commented Dec 16, 2020

The fix to prevent the crash (and instead return an error) has been merged and will release with version 3.22.0 of the Terraform AWS Provider, likely tomorrow. Please note that this fix is not intended to prevent any potentially underlying problem that might be causing the association to be non-existent when the code is executed. If the new error is being thrown in a reproducible way after this adjustment, it is best to submit a new bug report following the issue template so we have further details for troubleshooting. 👍

@ghost
Copy link
Author

ghost commented Dec 18, 2020

This has been released in version 3.22.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link
Author

ghost commented Jan 16, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Jan 16, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
2 participants