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

check for forbidden in equinix_metal_device read #235

Merged
merged 4 commits into from
Aug 1, 2022

Conversation

ocobles
Copy link
Contributor

@ocobles ocobles commented Jul 28, 2022

Create and Delete functions were already checking for 404s/403s, however it may occur a device is in failed state for external changes from the portal or any way out of terraform, returning a 403s in a refresh/plan/apply (read) action.

Added 403 check on read function and to remove resource from terraform state without errors. It will also check isNewResource to prevent the terraform import from failing silently.

Added a mock for packngo.DeviceService, with only implementation of the GET method. Other methods can be implemented gradually in the future according to the tests needs.

Fix #233

@ocobles ocobles requested a review from displague July 28, 2022 21:29
@codecov-commenter
Copy link

codecov-commenter commented Jul 28, 2022

Codecov Report

Merging #235 (d87e51e) into master (86242e6) will decrease coverage by 0.91%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #235      +/-   ##
==========================================
- Coverage   59.94%   59.02%   -0.92%     
==========================================
  Files          73       73              
  Lines       12564    12565       +1     
==========================================
- Hits         7531     7417     -114     
- Misses       4739     4868     +129     
+ Partials      294      280      -14     
Impacted Files Coverage Δ
equinix/resource_metal_device.go 71.22% <100.00%> (+4.95%) ⬆️
equinix/data_source_metal_ip_block_ranges.go 40.86% <0.00%> (-41.74%) ⬇️
equinix/resource_metal_bgp_session.go 46.34% <0.00%> (-39.03%) ⬇️
equinix/data_source_metal_device_bgp_neighbors.go 71.09% <0.00%> (-26.57%) ⬇️
equinix/data_source_metal_precreated_ip_block.go 54.36% <0.00%> (-19.42%) ⬇️
equinix/data_source_metal_virtual_circuit.go 96.36% <0.00%> (-3.64%) ⬇️
equinix/resource_metal_reserved_ip_block.go 81.15% <0.00%> (-2.02%) ⬇️
equinix/resource_metal_virtual_circuit.go 76.45% <0.00%> (-0.33%) ⬇️
equinix/helpers_device.go 68.42% <0.00%> (+0.52%) ⬆️
equinix/port_helpers.go 67.17% <0.00%> (+1.14%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86242e6...d87e51e. Read the comment docs.

@displague
Copy link
Member

Go tests are failing:

=== RUN   TestAccMetalDevice_readErrorHandling
=== RUN   TestAccMetalDevice_readErrorHandling/forbiddenAfterProvision
2022/07/29 12:28:46 [WARN] Device () not found or in failed status, removing from state
=== RUN   TestAccMetalDevice_readErrorHandling/notFoundAfterProvision
2022/07/29 12:28:46 [WARN] Device () not found or in failed status, removing from state
=== RUN   TestAccMetalDevice_readErrorHandling/forbiddenWaitForActiveDeviceProvision
=== RUN   TestAccMetalDevice_readErrorHandling/notFoundProvision
    resource_metal_device_acc_test.go:1088: resourceMetalDeviceRead() error = HTTP 404 , wantErr false
=== RUN   TestAccMetalDevice_readErrorHandling/errorProvision
--- FAIL: TestAccMetalDevice_readErrorHandling (0.00s)
    --- PASS: TestAccMetalDevice_readErrorHandling/forbiddenAfterProvision (0.00s)
    --- PASS: TestAccMetalDevice_readErrorHandling/notFoundAfterProvision (0.00s)
    --- PASS: TestAccMetalDevice_readErrorHandling/forbiddenWaitForActiveDeviceProvision (0.00s)
    --- FAIL: TestAccMetalDevice_readErrorHandling/notFoundProvision (0.00s)
    --- PASS: TestAccMetalDevice_readErrorHandling/errorProvision (0.00s)

@ocobles
Copy link
Contributor Author

ocobles commented Aug 1, 2022

TestAccMetalDevice_readErrorHandling

Updated with desired behavior: If it's a new resource (create), then remote operation error (in that case 404 Not Found) should be returned to prevent terraform sdk from returning a more opaque error "Provider produced inconsistent result after apply"

https://github.com/equinix/terraform-provider-equinix/runs/7607490391?check_suite_focus=true#step:5:166

@displague displague merged commit a68f883 into master Aug 1, 2022
@displague displague deleted the equinix_metal_device_detect_403 branch August 1, 2022 19:45
thogarty pushed a commit that referenced this pull request Sep 5, 2023
check for forbidden in equinix_metal_device read
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.

equinix_metal_device 403s on failed provision are not detected
3 participants