msgraph_resource: retry is not applied to the refresh read, so a transient 404 removes the resource from state
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start at Read() in internal/services/msgraph_resource.go around line 518, where the refresh read builds its options without RetryOptions, and compare it with the create, read-after-create, update and delete call sites that already pass clients.NewRetryOptions(model.Retry). Read clients.NewRequestOptions and clients.NewRetryOptions to see how query parameters and retry options are assembled, then mirror the working call sites. Done means a 404 whose message matches retry.error_message_regex is retried on refresh instead of hitting ResponseErrorWasNotFound and calling RemoveResource.
Written by the indexing model from the issue text.
Description
msgraph_resource: retry is not applied to the refresh read, so a transient 404 removes the resource from state
Versions: terraform-provider-msgraph v0.6.0 (also present on main), Terraform 1.15.5
Problem
retry.error_message_regex is honoured on create, read-after-create, update and delete, but not on the regular refresh read of a non-relationship resource. Read() builds its options without RetryOptions (internal/services/msgraph_resource.go, line 518 in v0.6.0):
options := clients.NewRequestOptions(nil, AsMapOfLists(model.ReadQueryParameters))
responseBody, err := r.client.Read(ctx, resourceItemUrl(model), model.ApiVersion.ValueString(), options)
if err != nil {
if utils.ResponseErrorWasNotFound(err) {
resp.State.RemoveResource(ctx)
For APIs that return intermittent 404s, one unlucky refresh silently drops an existing resource from state, and Terraform then plans to create it again.
Reproduction
resource "msgraph_resource" "assignment" {
api_version = "beta"
url = "roleManagement/exchange/roleAssignments"
body = {
principalId = "/ServicePrincipals/<sp-object-id>"
roleDefinitionId = "<role-definition-id>"
directoryScopeId = "/Groups/<group-object-id>"
}
retry = {
error_message_regex = ["couldn't be found on "]
}
}
GET /beta/roleManagement/exchange/roleAssignments/<id> returns 404 for an existing assignment in roughly 1 of 4 to 6 calls (10 of 50 with plain curl), with a different domain controller named each time:
RESPONSE 404: 404 Not Found
ERROR CODE: NotFound
"message": "Error executing request. The operation couldn't be performed because object
'...\ConfigurationUnits\<tenant>.onmicrosoft.com\Application Mail.ReadWrite' couldn't be
found on '<dc>.PROD.OUTLOOK.COM'."
The provider log shows Retry: exit due to non-retriable status code, and the resource is removed from state although retry matches the message.
Proposed fix
Pass the retry options like the other call sites do:
options := clients.RequestOptions{
QueryParameters: clients.NewQueryParameters(AsMapOfLists(model.ReadQueryParameters)),
RetryOptions: clients.NewRetryOptions(model.Retry),
}
- Dominant language
- Go
- Stars
- 65
- Forks
- 27
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/terraform-provider-msgraph
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
microsoft/terraform-provider-msgraph#188 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 69/100
-
`msgraph_resource`: created object is not saved to state when post-create verification failsPossibly taken @benhaspalace claimed this 36 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Paginated reads lose headers and metadata and refetch the first pagePossibly taken @QixiaLu claimed this 17 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
microsoft/terraform-provider-msgraph#172 · 1 comment · 1 assignee ·
All issues in microsoft/terraform-provider-msgraph
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
JuliusBrussee/caveman#1567 ·
Maintainers usually reply within 1 day
-
[DOC] API documentation link is broken on the databricks_workspace_binding registry pagePossibly taken @akhil9tiet claimed this today. Opendocs
Difficulty 1/5 Under an hour Newbie friendliness 82/100
databricks/terraform-provider-databricks#6276 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
topic: code type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
arduino/arduino-cli#3368 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
google/osv-scanner#3327 ·
Maintainers usually reply within 1 day