-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected nil variable on terraform destroy #7993
Comments
I also tried adding a null_resource right after the security group (see below) and got the same error. So it doesn't look like it is related to aws_security_group specifically, but perhaps the order in which dependencies are being "destroyed"?
|
I'm also running into this issue on destroy. Could be security group related as well.
|
Running into this as well, can provide logs if needed |
I just ran into this issue. I did a destroy, it waited ~4 minutes for the igw to destroy, and then moved on. Later on it said it couldn't find the igw, crashed, and after that I get the nil variable error.
|
Has anybody found a workaround for this? I seem to have trouble with internet gateways like @dmikalova, and it is making it impossible to cleanly destroy infrastructure. |
Yah, its often an internet gateway issue for me too. FWIW it looks like the internet gateway issue will be addressed in 0.7.1 |
@danielnbarbosa I think the fix in 0.7.1 is related to igw creation, not deletion. I've done the following change locally, we'll see if things improve: diff --git a/builtin/providers/aws/resource_aws_internet_gateway.go b/builtin/providers/aws/resource_aws_internet_gateway.go
index fe9ed3e..d4505a1 100644
--- a/builtin/providers/aws/resource_aws_internet_gateway.go
+++ b/builtin/providers/aws/resource_aws_internet_gateway.go
@@ -237,24 +237,28 @@ func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{})
// InstanceStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// an EC2 instance.
-func detachIGStateRefreshFunc(conn *ec2.EC2, instanceID, vpcID string) resource.StateRefreshFunc {
+func detachIGStateRefreshFunc(conn *ec2.EC2, gatewayID, vpcID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
_, err := conn.DetachInternetGateway(&ec2.DetachInternetGatewayInput{
- InternetGatewayId: aws.String(instanceID),
+ InternetGatewayId: aws.String(gatewayID),
VpcId: aws.String(vpcID),
})
if err != nil {
- ec2err, ok := err.(awserr.Error)
- if ok {
- if ec2err.Code() == "InvalidInternetGatewayID.NotFound" {
- return nil, "Not Found", err
- } else if ec2err.Code() == "Gateway.NotAttached" {
+ if ec2err, ok := err.(awserr.Error); ok {
+ switch ec2err.Code() {
+ case "InvalidInternetGatewayID.NotFound":
+ log.Printf("[TRACE] Error detaching Internet Gateway '%s' from VPC '%s': %s", gatewayID, vpcID, err)
+ return nil, "Not Found", nil
+
+ case "Gateway.NotAttached":
return "detached", "detached", nil
- } else if ec2err.Code() == "DependencyViolation" {
+
+ case "DependencyViolation":
return nil, "detaching", nil
}
}
}
+
// DetachInternetGateway only returns an error, so if it's nil, assume we're
// detached
return "detached", "detached", nil |
dang. you're right. thanks for the code snippet. i'm surprised that more people aren't having this issue. i wonder what's so unique about our setup. maybe most people don't do destroy very often. i'm currently in the middle of testing a new setup so i'm often doing a full create/destroy cycle. |
I'm running a scaled down version of my setup in CI, so it gets built and torn down very frequently, which may be why I run into this more often |
I've confirmed that this is related to |
We are running into this issue as well. Indeed related in some way to aws_security_group and/or aws_vpc. Tried to reproduce this with a small testcase but haven't been able to trigger it yet and don't have the time right now. Given the previous descriptions I don't think we are seeing a different issue. Also running TF 0.7.0. Let me know if I can help debug this issue. |
I've noticed that this gets triggered a lot when the internet gateway fails to delete. I dug into the logs, and the gateway was failing to delete because there were still some public IPs mapped in the VPC. I added some dependencies between the NAT gateways and the internet gateway (which causes the NAT gateways to be deleted first) and that seems to have improved the issue |
Same issue here, but not with security groups. Instead, as far as I can tell, it is with Network ACLs:
The only resources or variables in my templates with those IDs are Network ACLs, such as: resource "aws_network_acl" "private_persistence_subnets" {
vpc_id = "${var.vpc_id}"
subnet_ids = ["${var.private_persistence_subnet_ids}"]
tags {
Name = "${var.vpc_name}-private-persistence-subnets"
}
} |
Getting this as well on TF 0.7.2
|
Can anyone on the team comment on this? We're thinking of reverting to |
Getting this similar issue during destroy and on subsiquent destroy plans. |
Still seeing this on 0.7.2 |
Reproduced this issue with much simpler config file. Submitted as #8918. |
Still seeing this almost every day. I've noticed that this happens almost 100% of the time when terraform exits with an error due to a transient AWS failure. I think that the problem is the following:
I've managed to get past the errors by replacing the problematic references with hardcoded values & calling destroy again |
I'm also seeing this when calling destroy a second time after the first destroy succeeds in removing the resources. |
I also encountered this one today while performing a The following code appeared to be the cause in my case but I haven't managed to find a workaround or similar:
Any help would be greatly appreciated |
👍 |
Just tested this with the new destroy graph that we have coming in Terraform 0.8 and this is fixed. You can get this starting in the next version of Terraform by running destroy with the |
@mitchellh when is that new version coming out? |
@Bowbaq we average a release every 2 weeks or so so I'd imagine within a couple weeks |
Mitchell, that sounds great! Could you please drop a line or two about why this thing was happening in Thanks a lot! On Tuesday, 25 October 2016, Mitchell Hashimoto [email protected]
|
Huge huge thanks for this guys, you are awesome! 😄 |
@mitchellh I am still having issues - even with
|
@chiefy Huh, I don't have a repro anymore that can get this interestingly. Can you please post a repro if you get a chance? Please open a new issue when you do so so it gets more visibility. This may be a case where some cases are fixed but some aren't. |
@mitchellh - interesting, we're doing a lot of specification with |
@chiefy Yeah that looks like the key, the targeting. All the cases I had before didn't have targeting (but did contain modules). Any repro would help immensely and I can look into getting it fixed ASAP. |
Building terraform from latest git
|
Same behavior as @akranga with -Xnew-destroy flag (Terraform v0.7.10). |
Hey, can one of you get me a reproduction? Happy to fix with that, hard to without. :) |
@mitchellh I tried to create a test-case, but could not get it to reproduce - is it possible it only happens with |
@chiefy It is possible, but the state version last changed in 0.7.0. Between then and now the format hasn't changed. |
How may I help? Do you need the state? Tfplan? |
@mitchellh Sorry for the delay. It took a few tries, but I was able to get it to reproduce on 0.7.10 while removing a redis cluster. By the way, are you the Hashi in Hashicorp? |
@jdblack Thanks! I took a look and unfortunately don't see anything obvious in that log. I know you had some trouble getting that to reproduce so I apologize but if you can get that log with And yep, I am the H in HashiCorp. :P |
Good news! I was able to get it with a trace. I replaced the sensitive information that I could find. I would recommend breaking it up over more than one sitting if you intend to read the whole thing, as it's 838,498 lines. =) I'll have a chat with our powers that be to get permissio nto share our terraform repo with you. =) |
@jdblack Thanks, feel free to email me privately. I'm surprisingly nimble at parsing that 800,000 line log with my eyes. :) |
I still see this issue in Terraform v0.11.10 work around. ##Fix : #16681 Code inside submodule Fix output "vpc_id" { After the above change I ran terraform destroy it will without any issue. |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
0.7.0
Affected Resource(s)
aws_security_group
Terraform Configuration Files
Debug Output
https://gist.github.com/kglee79/111d61658e700ad40d1ad367497f4d66
Expected Behavior
Expected aws_security_group nat-sg to not be nil during terraform destroy. Prior to 0.7.0 there was no issue with the configuration above. After installing 0.7.0, only on destroy the issue occurs.
Actual Behavior
nat-sg is nil on destroy.
The error pasted below:
Steps to Reproduce
Could not reproduce in a simplified example.
The text was updated successfully, but these errors were encountered: