Skip to content
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

Fix for #664, crashed due to ig.Attachements being 0 #665

Merged
merged 2 commits into from
Dec 15, 2014

Conversation

gosuri
Copy link

@gosuri gosuri commented Dec 14, 2014

This is a fix for #664

@@ -60,7 +60,11 @@ func resourceAwsInternetGatewayRead(d *schema.ResourceData, meta interface{}) er
}

ig := igRaw.(*ec2.InternetGateway)
d.Set("vpc_id", ig.Attachments[0].VpcId)
if len(ig.Attachments) == 0 {
d.SetId("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By setting the ID of this resource to an empty string, you will create a dangling resource. The Internet Gateway will still exist, but after resetting the ID Terraform will think it doesn't and will drop any references to this resource from it's state file.

What you actually want to do here is clear the vpc_id. If you set the vpc_id to an empty string, the resource will understand that the Internet Gateway still exists, but is not attached to a VPC. This way you can keep managing the Internet Gateway and attach it to another VPC (or choose to properly delete the resource) if you want/need to.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying, makes total sense. Updated the PR!

armon added a commit that referenced this pull request Dec 15, 2014
Fix for #664, crashed due to ig.Attachements being 0
@armon armon merged commit 6098809 into hashicorp:master Dec 15, 2014
@armon
Copy link
Member

armon commented Dec 15, 2014

Thanks!

@spyrospph spyrospph mentioned this pull request Dec 19, 2014
@ryanuber ryanuber mentioned this pull request Jan 27, 2015
@ghost ghost locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants