msgraph_resource: deleting an app's last Private Access application segment returns 400

Open
#189 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
69/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, terraform

Research direction

Start by reading the provider code for msgraph_resource, especially ResponseErrorWasNotFound and the delete and refresh paths that call it. Check the existing tests for 404 and ResourceNotFound handling, then run the relevant tests. Done means this Graph 400 response is treated as not found during deletion and refresh, with tests covering the behavior.

Written by the indexing model from the issue text.

Description

Summary

When an application has no segments left, Graph answers GET on any segment ID under it with 400 Invalid_Appsegment ("Segment configuration is null") instead of 404. ResponseErrorWasNotFound only recognises a 404 or the error code ResourceNotFound, so with msgraph_resource:

  1. Delete: the DELETE succeeds, but WaitForDeletion gets the 400 and fails with Error waiting for deletion. The resource stays in state.
  2. Refresh: every later plan fails reading that resource with the same 400, so the configuration is stuck until someone runs terraform state rm.

The retry block can't help: the 400 never goes away.

Provider / Terraform
microsoft/msgraph v0.6.0
Terraform 1.12.2

resource "msgraph_resource" "segment" {
  api_version = "beta"
  url         = "applications/${var.application_object_id}/onPremisesPublishing/segmentsConfiguration/microsoft.graph.ipSegmentConfiguration/applicationSegments"
  body = {
    destinationHost = "*.example.internal"
    destinationType = "fqdn"
    ports           = ["443-443"]
    protocol        = "tcp"
  }
}
Steps to reproduce
  1. Apply the above against a Private Access (nonwebapp) application that has no other segments.
  2. Remove the resource (or change its for_each key) and apply.
Result
Error: Error waiting for deletion

retrieving resource: GET
https://graph.microsoft.com/beta/applications/<app>/onPremisesPublishing/segmentsConfiguration/microsoft.graph.ipSegmentConfiguration/applicationSegments/<segment>
RESPONSE 400: 400 Bad Request
ERROR CODE: Invalid_Appsegment
{ "error": { "code": "Invalid_Appsegment", "message": "Segment configuration is null" } }
What Graph returns, for reference
Request App still has ≥1 segment App has no segments
GET …/applicationSegments/{missing id} 404 400 Invalid_Appsegment
GET …/applicationSegments the segments {"value": []}

So a 404 is returned in every case except when the app has no segments left.

Expected

The delete completes and the resource leaves state. A refresh of a segment that no longer exists removes it from state, as a 404 would.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/terraform-provider-msgraph

All issues in microsoft/terraform-provider-msgraph

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.