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

vpcs: Protect against race conditions in IP range assignment. #552

Merged
merged 2 commits into from
Jan 19, 2021

Conversation

andrewsomething
Copy link
Member

@andrewsomething andrewsomething commented Jan 13, 2021

This prevents parallel creation of VPCs in the same region to protect against race conditions in IP range assignment. Fixes: #551

It creates an internal copy of the mutexkv package that had previously been part of the Terraform SDK. This is the same strategy employed by other providers.

https://www.terraform.io/docs/extend/guides/v2-upgrade-guide.html#removal-of-helper-mutexkv-package

Providers that need the functionality provided by the helper/mutexkv package are encouraged to copy the types and functions it provided into their own codebase, provided here under a public domain license

Before change, the new test fails with:

$ make testacc TESTARGS='-run=TestAccDigitalOceanVPC_IPRangeRace'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccDigitalOceanVPC_IPRangeRace -timeout 120m
?       github.com/digitalocean/terraform-provider-digitalocean [no test files]
=== RUN   TestAccDigitalOceanVPC_IPRangeRace
=== PAUSE TestAccDigitalOceanVPC_IPRangeRace
=== CONT  TestAccDigitalOceanVPC_IPRangeRace
    resource_digitalocean_vpc_test.go:87: Step 1/1 error: Error running apply: 
        Error: Error creating VPC: POST https://api.digitalocean.com/v2/vpcs: 422 (request "beeb46fc-d4ba-4223-bffd-462e21fe4f23") This range/size overlaps with another VPC network in your account: tf-acc-test-rk10vpxzml 10.108.0.0/20.
        
        
--- FAIL: TestAccDigitalOceanVPC_IPRangeRace (2.72s)
FAIL
FAIL    github.com/digitalocean/terraform-provider-digitalocean/digitalocean    2.730s
testing: warning: no tests to run
PASS
ok      github.com/digitalocean/terraform-provider-digitalocean/internal/datalist       (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/digitalocean/terraform-provider-digitalocean/internal/setutil        (cached) [no tests to run]
FAIL
make: *** [GNUmakefile:16: testacc] Error 1

Post-change it passes:

$ make testacc TESTARGS='-run=TestAccDigitalOceanVPC_IPRangeRace'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccDigitalOceanVPC_IPRangeRace -timeout 120m
?       github.com/digitalocean/terraform-provider-digitalocean [no test files]
=== RUN   TestAccDigitalOceanVPC_IPRangeRace
=== PAUSE TestAccDigitalOceanVPC_IPRangeRace
=== CONT  TestAccDigitalOceanVPC_IPRangeRace
--- PASS: TestAccDigitalOceanVPC_IPRangeRace (8.24s)
PASS
ok      github.com/digitalocean/terraform-provider-digitalocean/digitalocean    8.245s
testing: warning: no tests to run
PASS
ok      github.com/digitalocean/terraform-provider-digitalocean/internal/datalist       (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/digitalocean/terraform-provider-digitalocean/internal/mutexkv        (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/digitalocean/terraform-provider-digitalocean/internal/setutil        (cached) [no tests to run]

@andrewsomething andrewsomething requested a review from a team January 15, 2021 21:24
Base automatically changed from master to main January 19, 2021 21:30
Copy link
Contributor

@ChiefMateStarbuck ChiefMateStarbuck left a comment

Choose a reason for hiding this comment

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

NOICE

@ChiefMateStarbuck ChiefMateStarbuck merged commit 962d2d6 into main Jan 19, 2021
@andrewsomething andrewsomething deleted the asb/issues/551 branch January 19, 2021 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API error when creating multiple VPCs at the same time without an ip_range
2 participants