hashicorp / pandora

A suite of single-purpose tools enabling automation for Terraform/Azure
Mozilla Public License 2.0
65 stars 47 forks source link

OperationalInsights.QueryPacks API failed to handle the API response when the response code is 201 #982

Open neil-yechenwei opened 2 years ago

neil-yechenwei commented 2 years ago

Hi *,

While trying to create the query pack resource, it failed and throw below error message. Per the error message, seems the Pandora SDK failed to handle the API response when the response code is 201. Could you help take a look? Thanks in advance.

The API version being used: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/operationalinsights/resource-manager/Microsoft.OperationalInsights/stable/2019-09-01/QueryPacks.json#L189

The snippet code in TF resource to send request to create the resource: image

Request body:

PUT https://management.azure.com/subscriptions/xx-xx-xx-xx/resourceGroups/acctestRG-LA/providers/Microsoft.OperationalInsights/queryPacks/acctestlaqp

{
    "location": "eastus",
    "properties": {},
    "tags": null
}

Error message:

creating Query Pack (Subscription: "xx-xx-xx-xx"
Resource Group Name: "acctestRG-LA"
Query Pack Name: "acctestlaqp"):
operationalinsights.OperationalInsightsClient#QueryPacksCreateOrUpdate:
Failure responding to request: StatusCode=201 -- Original Error:
autorest/azure: Service returned an error. Status=201 Code="Unknown"
Message="Unknown service error"
Details=[{"etag":"\"xx-xx-xx-xx\"","id":"/subscriptions/xx-xx-xx-xx/resourceGroacctestRG-LA/providers/Microsoft.OperationalInsights/querypacks/acctestlaqp","kind":n"location":"eastus","name":"acctestlaqp","properties":{"provisioningState":"Succeed"queryPackId":"xx-xx-xx-xx","timeCreated":"xxxxx","timeModified":"xxxxx"tags":{},"type":"microsoft.operationalinsights/querypacks"}]

The error is thrown from this function: image image

tombuildsstuff commented 2 years ago

@neil-yechenwei the API's returning a 201 but it's not defined in the Swagger: https://github.com/Azure/azure-rest-api-specs/blob/fda2db441da3f1fab31bb235e97da3e33c8e3903/specification/operationalinsights/resource-manager/Microsoft.OperationalInsights/stable/2019-09-01/QueryPacks.json#L220-L225

In the future we're planning on supporting "overrides" within the Data which'll allow us to workaround these Swagger issues by overriding them on our side, but for now this'll need to be fixed in the Swagger, since it's out of date - so can you open an issue on the Rest API Specs repository about this?

neil-yechenwei commented 2 years ago

Thanks. Sure. Filed an issue on https://github.com/Azure/azure-rest-api-specs/issues/19603

tombuildsstuff commented 2 years ago

In the interim it should be possible to workaround this by ignoring the error for that status code:

client := operationalinsights.NewOperationalInsightsClientWithBaseURI("..")
    ctx := context.TODO()
    id := operationalinsights.NewQueryPackID("", "", "")
    payload := operationalinsights.LogAnalyticsQueryPack{}
    if _, err := client.QueryPacksCreateOrUpdate(ctx, id, payload); err != nil {
        if !response.WasStatusCode(resp.HttpResponse, http.Created) { // NOTE: we'll need to make this public: https://github.com/hashicorp/go-azure-helpers/blob/65fb6fe4419b73c7f072ca0e40d969dd2309661b/lang/response/response.go#L22
            return fmt.Error("creating %s: %+v", id, err)
        }
    }
neil-yechenwei commented 2 years ago

Thanks @tombuildsstuff. Once response.WasStatusCode goes public, I will update my PR.

tombuildsstuff commented 2 years ago

WasStatusCode will be exposed in https://github.com/hashicorp/go-azure-helpers/pull/124

tombuildsstuff commented 2 years ago

Available once https://github.com/hashicorp/terraform-provider-azurerm/pull/17588 is merged

wuxu92 commented 7 months ago

will be fixed by Azure/azure-rest-api-specs#27524