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

bug: AWS EIP (dis)association fails on non-EC2-Classic accounts #1598

Closed
wants to merge 3 commits into from

Conversation

radeksimko
Copy link
Member

As @pmoust mentioned in #1596

Test plan

All tested in a fresh new account (no EC2 Classic), it may need some testing in EC2 Classic too, but I don't have access to any.

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=EIP' 2>/dev/null
go generate ./...
TF_ACC=1 go test ./builtin/providers/aws -v -run=EIP -timeout 45m
=== RUN TestAccAWSEIP_normal
--- PASS: TestAccAWSEIP_normal (2.25s)
=== RUN TestAccAWSEIP_instance
--- PASS: TestAccAWSEIP_instance (256.66s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    258.929s

15b68fe

I'm happy to send 15b68fe as a separate PR, but it depends on the other commits as it's changing the same file.

How to replicate

resource "aws_vpc" "default" {
  cidr_block = "10.10.0.0/16"
}

resource "aws_subnet" "public" {
  vpc_id = "${aws_vpc.default.id}"
  cidr_block = "10.10.1.0/24"
  availability_zone = "us-east-1c"
}

resource "aws_instance" "web" {
  ami = "ami-323b195a"
  availability_zone = "us-east-1c"
  instance_type = "t2.small"
  key_name = "coreos-test"
  subnet_id = "${aws_subnet.public.id}"
  associate_public_ip_address = true
}

resource "aws_eip" "lb" {
  instance = "${aws_instance.web.id}"
  vpc = true
}

Output (that's still valid):

* Failure associating instances: Gateway.NotAttached: Network vpc-7c9abd19 is not attached to any internet gateway

destroy:

* MissingParameter: Either public IP or association id must be specified

The instance ID is saved to state file even though the API request ends up in error, which then results in trying to remove association which doesn't actually exist = corrupted state.

@radeksimko
Copy link
Member Author

Looking at #1555 ...
@fatih if you're free to test this, it would help too.

@radeksimko radeksimko changed the title bug: EIP (dis)association fails on non-EC2-Classic accounts bug: AWS EIP (dis)association fails on non-EC2-Classic accounts Apr 20, 2015
Radek Simko and others added 3 commits April 21, 2015 17:33
@catsby
Copy link
Contributor

catsby commented Apr 21, 2015

I just hit this and solved it another way:

-       assocIds := []*string{}
-       publicIps := []*string{}
+       var publicIps []*string
+       var assocIds []*string
        if domain == "vpc" {
                assocIds = []*string{aws.String(id)}
        } else {

the correct one is still populated via the domain == "vpc" check, and the other remains []*string(nil) instead of []*string{}, which AWS draws a clear distinction.

I did not test your scenario, I just recall seeing it. Does my attempt fix yours as well (at least in this context), and it one way better? Thanks 😄

@radeksimko
Copy link
Member Author

@catsby Just left a comment in your PR. I can remove two commits and just leave the bugfix for the IGW issue, but I will need you to merge your fix first, then I can rebase and do all the git magic. 🏄

@catsby
Copy link
Contributor

catsby commented Apr 29, 2015

Sorry for the delay – we'll get this sorted today

@catsby
Copy link
Contributor

catsby commented Apr 29, 2015

@radeksimko I just merged #1618

@radeksimko
Copy link
Member Author

Bugfix separated into #1776

@radeksimko radeksimko closed this May 1, 2015
@radeksimko radeksimko deleted the fix-eip-describe branch May 1, 2015 23:02
@ghost
Copy link

ghost commented May 3, 2020

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.

@ghost ghost locked and limited conversation to collaborators May 3, 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