microsoft / microsoft/terraform-provider-msgraph

msgraph_resource_action overwrites custom Content-Type with application/json when body is set

Open
#125 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Go
Stars
65
Forks
25
Avg merge
3d 10h
Merged PRs (30d)
6

Description

When using msgraph_resource_action to call Microsoft Graph endpoints that require a non-JSON request body, custom Content-Type headers are ignored/overwritten.
Example use case: uploading Entra ID organizational branding image assets:
resource "msgraph_resource_action" "organizational_branding_assets" {
resource_url = "organization/${var.tenant_id}/branding/localizations/0/bannerLogo"
api_version = "v1.0"
method = "PUT"

headers = {
"Content-Type" = "image/png"
}

body = filebase64("${path.module}/branding/banner.png")
}
Expected behavior
The request should be sent with:
Content-Type: image/png
or the provider should provide a supported way to send raw/binary request bodies with a custom content type.
Actual behavior
Microsoft Graph receives:
Content-Type: application/json
and rejects the request:
Invalid Image Content-Type 'application/json'.
Root cause
In internal/clients/msgraph_client.go, MSGraphClient.Action applies custom headers first:
for key, value := range options.Headers {
req.Raw().Header.Set(key, value)
}
but then, when body != nil, it calls:
runtime.MarshalAsJSON(req, body)
req.Raw().Header.Set("Content-Type", "application/json")
This overwrites any user-provided Content-Type.
Impact
This makes msgraph_resource_action unusable for Microsoft Graph endpoints that require raw binary or non-JSON bodies, such as:
PUT /organization/{tenantId}/branding/localizations/{locale}/{streamProperty}
where Graph expects image/png, image/jpeg, etc.
Suggested fix
Either:
Do not overwrite Content-Type if the user already provided one in headers, or
Add support for raw body uploads, for example raw_body, body_base64, or similar, that bypasses JSON marshaling and respects the provided Content-Type.
Provider version
microsoft/msgraph v0.3.0

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start in internal/clients/msgraph_client.go at MSGraphClient.Action and trace how options.Headers and the request body are applied. Verify the behavior for a non-JSON body such as the branding image example; done means a caller-provided Content-Type is respected and Microsoft Graph receives the requested media type instead of application/json.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.