Azure / Azure/terraform-provider-azapi

`azapi_resource`: unable to manage `Microsoft.Marketplace/privateStores/collections/offers`

Open
#899 2 comments 1 reaction 0 assignees View on GitHub
triaged upstream-api
Dominant language
Go
Stars
244
Forks
97
Avg merge
3d 18h
Merged PRs (30d)
8

Description

Azure API for Private Marketplace offers return 400 when an offer doesn't exists, as such it is not possible to manage this resource with the AzAPI provider as of now.

Ideally Azure API should return a 404 error but I am not sure on the time it will take (if even accepted) for this change (https://github.com/Azure/azure-rest-api-specs/issues/35316).

Code to reproduce the error:
```terraform
resource "azapi_resource" "offer" {
type = "Microsoft.Marketplace/privateStores/collections/offers@2023-01-01"

# Update GUID with your tenant ID (Private Marketplace needs to be enabled first)
parent_id = "/providers/Microsoft.Marketplace/privateStores/00000000-0000-0000-0000-000000000000/collections/00000000-0000-0000-0000-000000000000"
name = "center-for-internet-security-inc.cis-ubuntu"

body = {
properties = {
specificPlanIdsLimitation = []
}
}
}

```

Error:
```
│ Error: Failed to retrieve resource

│ with azapi_resource.offers["center-for-internet-security-inc.cis-ubuntu"],
│ on offers.tf line 9, in resource "azapi_resource" "offers":
│ 9: resource "azapi_resource" "offers" {

│ checking for presence of existing Resource: (ResourceId
│ "/providers/Microsoft.Marketplace/privateStores/00000000-0000-0000-0000-000000000000/collections/00000000-0000-0000-0000-000000000000/offers/center-for-internet-security-inc.cis-ubuntu"
│ / Api Version "2023-01-01"): GET
│ https://management.azure.com/providers/Microsoft.Marketplace/privateStores/00000000-0000-0000-0000-000000000000/collections/00000000-0000-0000-0000-000000000000/offers/center-for-internet-security-inc.cis-ubuntu
│ --------------------------------------------------------------------------------
│ RESPONSE 400: 400 Bad Request
│ ERROR CODE: BadRequest
│ --------------------------------------------------------------------------------
│ {
│ "error": {
│ "code": "BadRequest",
│ "message": "Offer center-for-internet-security-inc.cis-ubuntu does not exist"
│ }
│ }
│ --------------------------------------------------------------------------------

```

The error happends due to the following check expecting 404: https://github.com/Azure/terraform-provider-azapi/blob/main/internal/services/azapi_resource.go#L666

Contributor guide

Open the contributing guide

Research direction

Start at internal/services/azapi_resource.go around line 666 and inspect how the existing-resource presence check handles Azure responses. Run the Terraform reproduction from the issue against the Private Marketplace offers API, then verify that an absent offer can be managed while existing-resource behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, go, terraform
Domain
cloud, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.