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

resource/aws_eip_association: fix eventual consistency issue when associating EIP #16808

Merged
merged 2 commits into from
Dec 18, 2020
Merged

resource/aws_eip_association: fix eventual consistency issue when associating EIP #16808

merged 2 commits into from
Dec 18, 2020

Conversation

dohoangkhiem
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #11617
Relates #12449

Terraform Version

$ terraform -v
Terraform v0.12.16
+ provider.aws v2.39.0

Affected Resource(s)

aws_eip_association

Terraform Configuration

provider "aws" {
  version = "2.39.0"
  region = var.aws_region
}

resource "aws_instance" "this" {
  ami = "ami-06fb5332e8e3e577a"
  instance_type = "t2.nano"
  key_name = "default_key"
  vpc_security_group_ids = ["sg-923d3cf4"]
  subnet_id = "subnet-61a23e06"
  associate_public_ip_address = true

  root_block_device {
    volume_size = 20
    volume_type = "gp2"
    delete_on_termination = true
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_eip" "this" {
  vpc = true
}

resource "aws_eip_association" "this" {
  instance_id   = aws_instance.this.id
  allocation_id = aws_eip.this.id
}

Expected Behavior

aws_eip_association is created successfully in TF state and in EC2.

Actual Behavior

Rarely, the EIP is associated, but in TF state the resource is not recorded due to eventual consistency issue when reading back the association

Error: Provider produced inconsistent result after apply
When applying changes to aws_eip_association.this, provider "aws" produced an unexpected new value for was present, but now absent. This is a bug in the provider, which should be reported in the provider's own issue tracker.

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSEIPAssociation_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSEIPAssociation_ -timeout 120m
=== RUN   TestAccAWSEIPAssociation_instance
=== PAUSE TestAccAWSEIPAssociation_instance
=== RUN   TestAccAWSEIPAssociation_networkInterface
=== PAUSE TestAccAWSEIPAssociation_networkInterface
=== RUN   TestAccAWSEIPAssociation_basic
=== PAUSE TestAccAWSEIPAssociation_basic
=== RUN   TestAccAWSEIPAssociation_ec2Classic
=== PAUSE TestAccAWSEIPAssociation_ec2Classic
=== RUN   TestAccAWSEIPAssociation_spotInstance
=== PAUSE TestAccAWSEIPAssociation_spotInstance
=== RUN   TestAccAWSEIPAssociation_disappears
=== PAUSE TestAccAWSEIPAssociation_disappears
=== CONT  TestAccAWSEIPAssociation_instance
=== CONT  TestAccAWSEIPAssociation_spotInstance
=== CONT  TestAccAWSEIPAssociation_disappears
=== CONT  TestAccAWSEIPAssociation_ec2Classic
=== CONT  TestAccAWSEIPAssociation_networkInterface
=== CONT  TestAccAWSEIPAssociation_basic
=== CONT  TestAccAWSEIPAssociation_ec2Classic
    ec2_classic_test.go:54: this test can only run in EC2-Classic, platforms available in us-east-1: ["VPC"]
--- SKIP: TestAccAWSEIPAssociation_ec2Classic (5.79s)
--- PASS: TestAccAWSEIPAssociation_networkInterface (75.35s)
--- PASS: TestAccAWSEIPAssociation_instance (108.61s)
--- PASS: TestAccAWSEIPAssociation_disappears (109.13s)
--- PASS: TestAccAWSEIPAssociation_basic (169.76s)
--- PASS: TestAccAWSEIPAssociation_spotInstance (310.48s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	310.577s

@dohoangkhiem dohoangkhiem requested a review from a team as a code owner December 17, 2020 04:11
@ghost ghost added size/XS Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. labels Dec 17, 2020
@dohoangkhiem dohoangkhiem changed the title resource/aws_eip_association: fix eventual consistency issue when ass… resource/aws_eip_association: fix eventual consistency issue when association EIP Dec 17, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 17, 2020
@dohoangkhiem dohoangkhiem changed the title resource/aws_eip_association: fix eventual consistency issue when association EIP resource/aws_eip_association: fix eventual consistency issue when associating EIP Dec 17, 2020
@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 17, 2020
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Hi @dohoangkhiem 👋 Thank you for submitting this fix. It is definitely on the right track -- just a few minor things and should be good to go. 👍

aws/resource_aws_eip_association.go Outdated Show resolved Hide resolved
aws/resource_aws_eip_association.go Show resolved Hide resolved
aws/resource_aws_eip_association.go Outdated Show resolved Hide resolved
@ghost ghost added size/S Managed by automation to categorize the size of a PR. and removed size/XS Managed by automation to categorize the size of a PR. labels Dec 18, 2020
@dohoangkhiem
Copy link
Contributor Author

Many thanks @bflad for suggestions, I updated PR, acc tests passed.

@bflad bflad self-requested a review December 18, 2020 12:47
@bflad bflad added this to the v3.22.0 milestone Dec 18, 2020
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Looks great, thank you @dohoangkhiem 🚀

Output from acceptance testing in AWS Commercial:

--- PASS: TestAccAWSEIPAssociation_networkInterface (67.84s)
--- PASS: TestAccAWSEIPAssociation_ec2Classic (82.56s)
--- PASS: TestAccAWSEIPAssociation_instance (95.90s)
--- PASS: TestAccAWSEIPAssociation_disappears (103.23s)
--- PASS: TestAccAWSEIPAssociation_basic (170.68s)
--- PASS: TestAccAWSEIPAssociation_spotInstance (302.76s)

Output from acceptance testing in AWS GovCloud (US):

--- PASS: TestAccAWSEIPAssociation_networkInterface (71.88s)
--- PASS: TestAccAWSEIPAssociation_instance (97.48s)
--- PASS: TestAccAWSEIPAssociation_disappears (104.81s)
--- PASS: TestAccAWSEIPAssociation_basic (181.36s)
--- PASS: TestAccAWSEIPAssociation_spotInstance (337.15s)
--- SKIP: TestAccAWSEIPAssociation_ec2Classic (2.41s)

@bflad bflad merged commit b20f342 into hashicorp:master Dec 18, 2020
bflad added a commit that referenced this pull request Dec 18, 2020
@ghost
Copy link

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

ghost commented Jan 17, 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 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. size/S Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants