Open mennlo opened 1 year ago
Im facing this issue too. Whenever we tried to apply changes to the apim, the outcomes are unpredictable as well.
@mennlo Thanks for taking the time to open this issue. Please subscribe to PR #23348 that @sinbai has created.
It looks like the PR didn't solve the problem. It still occurs to me on v3.75.0.
Can we reopen this issue or should I make a new one?
It looks like the PR didn't solve the problem. It still occurs to me on v3.75.0.
Can we reopen this issue or should I make a new one?
It worked for me after using v3.75.0.
I also have this issue, also when using AzureRM provider in version 3.75.0 (mbfrahry FYI)
@zhallgato, @mennlo, @DominikKrissVisma Thank you for the update, I will reopen this issue.
Hey @sinbai, mind taking another look at this one?
Hi @DominikKrissVisma, @zhallgato , sorry that PR could not solve your problem. Since the PR already addressed mennlo's issue , I assume that your case might be different. Is it possible to provide detailed terraform configuration (easily reproducible and contains variable values - except sensitive information) and reproduce steps to help reproduce and resolve the problem? In addition, it might help a lot if Terraform trace logs could also be provided. Thanks in advance.
hello, this is terraform file (ranamed from tf to txt): genericapi.txt notice we are using azurerm_api_management_api_version_set, and revision in order to force API recreation. The reason is that when API yaml file changes, like there is new endpoint added, those changes are not always deployed via terraform. When this happens we are expiriencing the 404 issue:
Api: "int-c-client-systems-v2"): polling after CreateOrUpdate: executing request: unexpected status 404 with error: ResourceNotFound: Api not found.
with azurerm_api_management_api.generic_client_systems["ccc"],
on api_management_generic.tf line 31, in resource "azurerm_api_management_api" "generic_client_systems":
31: resource "azurerm_api_management_api" "generic_client_systems"
the issue is that API is actualy created during that run, but not tracked in the TF state file, therefore after this happes we need to import the API into state file.
This issue still persists in 3.80, I had to downgrade to 3.68 for the resource to create. Any timeline to fix this issue?
I tried to work-around this by downgrading from 3.80 to 3.68 but it seems the state is no longer compatible, so it's not the easiest work-around.
I get a bunch of
│ The current state of azurerm_api_management_product_policy.<policyName>
│ was created by a newer provider version than is currently selected. Upgrade
│ the azurerm provider to work with this state.
│ The current state of azurerm_api_management_api_policy.<policyName>
│ was created by a newer provider version than is currently selected. Upgrade
│ the azurerm provider to work with this state.
Sorry for the noise :-)
@sinbai looks like the original PR didn't resolve this issue - since you sent the original PR to fix this, can you take another look into this one? Thanks!
Can anyone here provide more contexts in terms of step-by-step-repro-this-issue?
Can anyone here provide more contexts in terms of step-by-step-repro-this-issue?
I can probably make one, but I can't make the time the next couple of days.
I can start by sharing some more information about the resource were this issue occurred to me on azurerm 3.80, though.
The resource looks like this
resource "azurerm_api_management_api" "api" {
name = "clientname-${var.env}-api-${var.api_name}" # e.g. "clientname-d-api-clientapi-internal"
api_management_name = var.api_management_name # e.g. "clientname-d-apim-common"
resource_group_name = var.resource_group_name # e.g. "clientname-d-rg-common"
revision = var.revision # e.g. "50923", "50930", ...
display_name = var.display_name # e.g. "clientname clientapi internal dev"
path = "${var.api_name}" # e.g. "clientapi"
protocols = ["https"]
subscription_required = var.subscription_required # e.g. true
service_url = var.service_url # e.g. https://clientname-d-aks.norwayeast.cloudapp.azure.com/clientapi
import {
content_format = "openapi"
content_value = file(var.openapi_definition) # a fairly ordinary OpenAPI v3 spec in json format
# with info.version set to "internal"
}
lifecycle {
# The version number is pulled from the BUILD_ID, so it changes constantly.
# This will only update if the actual API has changed.
ignore_changes = [revision]
}
}
We have just one azurerm_api_management_api resource with this name+api_management_name, so the "revision" property is just being used to track which CI pipeline run it came from.
I have some new information.
We had 6 APIMs in different environments (4 of them in East US and 2 of them in East US 2 Azure regions).
We only experienced the above-mentioned issue on those APIMs which were in East US 2 region.
So, we recreated these two APIMs in East US, and since the recreation we no longer experience the issue. Everything works fine.
Maybe the issue is related only to specific Azure regions. (maybe there are some delays in these regions?)
This is happening to me too. We are in US East 2 as well and running azurerm 3.80. We are also importing a fairly large openapi definition.
For us, it seems to happen when trying to add apis with "large" (openapi) definition files (+300KB, +90 operations). Smaller definition files worked fine, and reverting to 3.69.0 works for everything. Location Norway East.
I really appreciate everyone's help. It has been reproduced and is under investigation. Thank you so much!
I am hitting this issue as well, on 3.81.0
. My openai
definition is quite small, having only 3 operations
base-layer: the
PollUntilDone
ofCreateOrUpdateThenPoll
stops polling when the API returns resource not found error on first poll hashicorp/go-azure-sdk
Hi @tombuildsstuff I assume that this is a base layer issue. For the case of long running operation poller and the API return Location
refers to itself, the 404 errors should be additionally handled in the base layer, what do you think? Please refer to issue #740 for details.
Just started hitting this as well. AzureRM version 3.71, we're only adding one API with a single operation.
If downgrading isn't an option due to state file compatibility, are there any other workarounds besides create manually and import?
Any update on this issue? We also get this issue with 3.79.0 & 3.85.0. Our yaml file size is 7.4K.
Also if we just rerun the terraform all works fine. Is there any other work around for this?
@sinbai : We have observed something similar. I have created a small reproducer based on one of our real life deployments. I can consistently reproduce the failure/success of an api creation by making a small change to the openapi.yaml descriptor. Given the following parameter in the unique REST resource of our openapi.yaml file, the creation of the corresponding api will fail.
- description: status
in: query
name: status
schema:
type: string
default: P
enum:
- PRODUCTIVE
- ARCHIVED
A summary of the failure pattern is
GET versionset -> 404
PUT versionset -> 201
GET versionset -> 200
GET version -> 404
PUT version -> 202
GET version -> 404
If we modify the default to be default: PRODUCTIVE
however, the creation succeeds, with the following success pattern:
GET versionset -> 404
PUT versionset -> 201
GET versionset -> 200
GET version -> 404
PUT version -> 202
GET version -> 200
...
Note that https://apitools.dev/swagger-parser/online/ for instance validates both syntaxes. The Azure portal on the other hand doesn't: If we try to create the API by uploading the file via frontend using default: P
, we get the following error message: One or more fields contain incorrect values: Default value must be present in the list of values
. Our hypothesis is that the version creation fails silently in Azure API management.
We are currently on version v3.85.0
@sinbai : Do you plan to take a look at this issue again (see my comment above)? Do you want me to open a new issue?
@kjetiloen @hieumoscow since this will probably take months to address, can you please share the configuration you used to provision on 3.68.0
or 3.69.0
? I am having the same error in those versions...
Latest azurerm
provider (version 3.92) still exhibits this behavior. Any progress information on this issue? :)
@sinbai : Do you plan to take a look at this issue again (see my comment above)? Do you want me to open a new issue?
Hi @mrickly the best solution to this issue is to modify the implementation of base layer SDK. Could you please track this SDK issue for more updates?
Latest
azurerm
provider (version 3.92) still exhibits this behavior. Any progress information on this issue? :)
Hi @eugeneromero Could you please track https://github.com/hashicorp/go-azure-sdk/issues/740 SDK issue for more updates?
@sinbai : Do you plan to take a look at this issue again (see my comment above)? Do you want me to open a new issue?
Hi @mrickly the best solution to this issue is to modify the implementation of base layer SDK. Could you please track this SDK issue for more updates?
Hi @sinbai : I will do that, although I'm not sure that it covers our case. Unless the azure api systematically returns a delayed response via PollUntilDone (possibly different than 404 and 201, 422 for instance), I would expect to get a validation error already in the CreateOrUpdate step.
Hi Team, Is there any fixes going on ? Please let me know the solution. I am facing the similar issue, like while I am trying to deploying a new API.
Regards, Nikhil
Make sure that the name
value of the azurerm_api_management_api
resource does not contain any /
characters. What happens is that the the azurerm would include the name into the API call it makes, so if your name
is test/test
this will result into
PUT /subscriptions/$SUB_ID/resourceGroups/$RG_NAME/providers/Microsoft.ApiManagement/service/$APIM_NAME/apis/test/test;rev=1?api-version=2022-08-01z
And this is incorrect API request to Azure API, so it will result into 404 :)
Also try running TF_LOG=debug terraform apply
. You will be able to see the API requests the provider does, and then troubleshoot it from there. At least it helped me.
Can you please share a working configuration @Ayzrian ?
I had the same problem using version 3.96.0
downgrading to 3.46.0
works fine.
The logs TF_LOG=debug terraform apply
wasn't much helpful, just show the following behavior:
...
module.api.azurerm_api_management_api.api: Creating...
GET /subscriptions/SUBSCRIPTION/resourceGroups/RG/providers/Microsoft.ApiManagement/service/APIM/apis/API;rev=1?api-version=2022-08-01 HTTP/1.1
HTTP/2.0 404 Not Found
{"error":{"code":"ResourceNotFound","message":"Api not found.","details":null}}: timestamp=2024-03-21T08:39:38.727-0300
2024-03-21T08:39:38.727-0300 [DEBUG] provider.terraform-provider-azurerm_v3.96.0_x5: Importing API Management API "APIf;rev=1" of type "openapi": timestamp=2024-03-21T08:39:38.727-0300
PUT /subscriptions/SUBSCRIPTION/resourceGroups/RG/providers/Microsoft.ApiManagement/service/APIM/apis/API;rev=1?api-version=2022-08-01 HTTP/1.1
HTTP/2.0 202 Accepted
module.api.azurerm_api_management_api.api: Still creating... [10s elapsed]
2024-03-21T08:39:49.185-0300 [DEBUG] provider.terraform-provider-azurerm_v3.96.0_x5: AzureRM Request
GET /subscriptions/SUBSCRIPTION/resourceGroups/RG/providers/Microsoft.ApiManagement/service/APIM/apis/API;rev=1?api-version=2022-08-01 HTTP/1.1
HTTP/2.0 404 Not Found
{"error":{"code":"ResourceNotFound","message":"Api not found.","details":null}}: timestamp=2024-03-21T08:39:49.740-0300
2024-03-21T08:39:49.742-0300 [ERROR] provider.terraform-provider-azurerm_v3.96.0_x5: Response contains error diagnostic: diagnostic_severity=ERROR tf_provider_addr=provider tf_rpc=ApplyResourceChange tf_proto_version=5.4 @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/diag/diagnostics.go:58 @module=sdk.proto diagnostic_detail= tf_resource_type=azurerm_api_management_api diagnostic_summary="creating/updating Api (Subscription: "SUBSCRIPTION"
Api: "API;rev=1"): polling after CreateOrUpdate: executing request: unexpected status 404 with error: ResourceNotFound: Api not found." tf_req_id=req_id timestamp=2024-03-21T08:39:49.740-0300
... (some logs showing some operations in the backend)
2024-03-21T08:39:50.290-0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-03-21T08:39:50.297-0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/azurerm/3.96.0/darwin_arm64/terraform-provider-azurerm_v3.96.0_x5 pid=70672
2024-03-21T08:39:50.297-0300 [DEBUG] provider: plugin exited
I am having this same problem and tried it with the new 3.97.1 version of the AzureRM and am still getting the same error. I had hoped that it was fixed per some of the comments last week, but seems like it's still there.
I'm also getting this issue on provider version 3.97.1.
I'm also getting this issue on provider version 3.97.1.
Same (and as well with 3.92.0)
I am currently getting this on provier version 3.98.0
I have just moved from 3.89 to 3.98 in an attempt to fix this issue, but to no avail:
Error: creating/updating Api (Subscription: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" │ Resource Group Name: "rg-01-aaaf-cs-eastus-stg" │ Service Name: "apim-02-aaaf-cs-eastus-stg" │ Api: "api-fa-001-aaaf-cs-eastus-stg;rev=1"): polling after CreateOrUpdate: executing request: unexpected status 404 (404 Not Found) with error: ResourceNotFound: Api not found. │ │ with module.mod_aaaf_funcapp_001.azurerm_api_management_api.aaaf_apim_api_funcapp_001, │ on modules\100_funcapps\funcapp_001\main.tf line 123, in resource "azurerm_api_management_api" "aaaf_apim_api_funcapp_001": │ 123: resource "azurerm_api_management_api" "aaaf_apim_api_funcapp_001"
I'd really appreciate a fix or a work-around, please. I have literally hundreds of Function Apps to deploy into APIM
@deankelly780 did you get any solution for this? The strange part is when i run the terraform apply again then it works in second time.
No @sharatbhaskar1988 nothing yet. I am still working on it. If I come up with something, I'll ping it here.
The failure pattern seems different for me: I am currently developing the TF by deploying 2 x APIs and one works every time, but the other fails every time.
@sinbai Are you able to take another look at this issue? Thanks!
@manicminer and @sharatbhaskar1988 - I seem to have a solution that at least worked for my particular version of this issue.
When I was deploying, I was using two copies of a mostly identical template to create two different APIs. The only differences were the names of the Function Apps.
Both templates were using the same setting for "path":
resource "azurerm_api_management_api" "aaaf_apim_api_funcapp_001" {
name = "api-${var.aaaf_funcapp_001_name}"
resource_group_name = var.aaaf_resource_group_name
api_management_name = var.aaaf_apim_name
revision = "1"
display_name = var.aaaf_funcapp_001_name
path = "public"
protocols = [ "https" ]
import {
content_format = "openapi"
content_value = file("modules/100_funcapps/funcapp_001/openapi_spec.yaml")
}
depends_on = [ azurerm_api_management_backend.aaaf_apim_backend_funcapp_001 ]
}
By ensuring that "path" was set differently in both templates the problem went away. I hope this is useful to you.
@sinbai Are you able to take another look at this issue? Thanks!
@manicminer thanks for your PR. Due to testing locally with the following TF configuration, the reproducible situation mentioned in issue #740 (This error occurs when the API returns a 404 error during the first polling. If the polling API returns 200 for the first time, the problem could not be reproduced) did not occur (After trying several times, the API did not return 404.), I'm not sure why the issue still occurs after applying the PR.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.98.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "exampleRG"
location = "westeurope"
}
resource "azurerm_api_management" "test" {
name = "example"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
publisher_name = "pub1"
publisher_email = "pub1@email.com"
sku_name = "Consumption_0"
}
resource "azurerm_api_management_api" "test" {
name = "example"
resource_group_name = azurerm_resource_group.test.name
api_management_name = azurerm_api_management.test.name
display_name = "api1"
path = "api1"
protocols = ["https"]
# once created, update revision to 3, then run terraform apply
revision = "1"
import {
content_value = file("api_management_api_swagger.json")
content_format = "swagger-json"
}
}
However, it could be seen from the following log provided by ltmleo that TF polls the Get
request after the PUT
request, the API returns a 404 record only once. If the log is generated by applying the PR and no additional 404 records are missed, I assume that the retry 404 code in the PR does not seem to be working.
...
module.api.azurerm_api_management_api.api: Creating...
GET /subscriptions/SUBSCRIPTION/resourceGroups/RG/providers/Microsoft.ApiManagement/service/APIM/apis/API;rev=1?api-version=2022-08-01 HTTP/1.1
HTTP/2.0 404 Not Found
{"error":{"code":"ResourceNotFound","message":"Api not found.","details":null}}: timestamp=2024-03-21T08:39:38.727-0300
2024-03-21T08:39:38.727-0300 [DEBUG] provider.terraform-provider-azurerm_v3.96.0_x5: Importing API Management API "APIf;rev=1" of type "openapi": timestamp=2024-03-21T08:39:38.727-0300
PUT /subscriptions/SUBSCRIPTION/resourceGroups/RG/providers/Microsoft.ApiManagement/service/APIM/apis/API;rev=1?api-version=2022-08-01 HTTP/1.1
HTTP/2.0 202 Accepted
module.api.azurerm_api_management_api.api: Still creating... [10s elapsed]
2024-03-21T08:39:49.185-0300 [DEBUG] provider.terraform-provider-azurerm_v3.96.0_x5: AzureRM Request
GET /subscriptions/SUBSCRIPTION/resourceGroups/RG/providers/Microsoft.ApiManagement/service/APIM/apis/API;rev=1?api-version=2022-08-01 HTTP/1.1
HTTP/2.0 404 Not Found
{"error":{"code":"ResourceNotFound","message":"Api not found.","details":null}}: timestamp=2024-03-21T08:39:49.740-0300
2024-03-21T08:39:49.742-0300 [ERROR] provider.terraform-provider-azurerm_v3.96.0_x5: Response contains error diagnostic: diagnostic_severity=ERROR tf_provider_addr=provider tf_rpc=ApplyResourceChange tf_proto_version=5.4 @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/diag/diagnostics.go:58 @module=sdk.proto diagnostic_detail= tf_resource_type=azurerm_api_management_api diagnostic_summary="creating/updating Api (Subscription: "SUBSCRIPTION"
Api: "API;rev=1"): polling after CreateOrUpdate: executing request: unexpected status 404 with error: ResourceNotFound: Api not found." tf_req_id=req_id timestamp=2024-03-21T08:39:49.740-0300
... (some logs showing some operations in the backend)
2024-03-21T08:39:50.290-0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-03-21T08:39:50.297-0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/azurerm/3.96.0/darwin_arm64/terraform-provider-azurerm_v3.96.0_x5 pid=70672
2024-03-21T08:39:50.297-0300 [DEBUG] provider: plugin exited
Regardless, since the issue could not be reproduced, the root cause could not be located. If anyone here could provide the minimum reproducible TF configuration, repro steps and TF Log information, it would be of great help for us to troubleshoot.
@sinbai : When an invalid open api file is used, terraform 3.98 still fails with 404.
openapi:
openapi: 3.0.1
info:
title: j7t-reproducer-service
version: "1"
servers:
- url: rest
variables: {}
tags:
- name: tag1
description: description of tag1
paths:
/document:
get:
description: description of operation1
operationId: operation1
parameters:
- description: status
in: query
name: status
schema:
type: string
default: P
enum:
- PRODUCTIVE
- ARCHIVED
responses:
"200":
description: get doc by status
last couple of lines in the terraform log
2024-04-11T12:43:10.379Z [DEBUG] provider.terraform-provider-azurerm_v3.98.0_x5: PUT https://management.azure.com/subscriptions/e5e059e9-92ef-4e3c-a352-00554175fc0f/resourceGroups/caz-preprod-rg/providers/Microsoft.ApiManagement/service/caz-preprod-apim/apis/j7t-reproducer-service;rev=1?api-version=2022-08-01: timestamp=2024-04-11T12:43:10.379Z
2024-04-11T12:43:10.640Z [DEBUG] provider.terraform-provider-azurerm_v3.98.0_x5: AzureRM Response for https://management.azure.com/subscriptions/e5e059e9-92ef-4e3c-a352-00554175fc0f/resourceGroups/caz-preprod-rg/providers/Microsoft.ApiManagement/service/caz-preprod-apim/apis/j7t-reproducer-service;rev=1?api-version=2022-08-01:
HTTP/2.0 202 Accepted
Content-Length: 0
Cache-Control: no-cache
Date: Thu, 11 Apr 2024 12:43:09 GMT
Expires: -1
Location: https://management.azure.com/subscriptions/e5e059e9-92ef-4e3c-a352-00554175fc0f/resourceGroups/caz-preprod-rg/providers/Microsoft.ApiManagement/service/caz-preprod-apim/apis/j7t-reproducer-service;rev=1?api-version=2022-08-01&asyncId=6617dadefb4268092441a3a0&asyncCode=201
Pragma: no-cache
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Ms-Correlation-Request-Id: 55645181-aba8-cf02-d26f-00b83707aed0
X-Ms-Ratelimit-Remaining-Subscription-Writes: 1199
X-Ms-Request-Id: 55645181-aba8-cf02-d26f-00b83707aed0
X-Ms-Routing-Request-Id: WESTEUROPE:20240411T124310Z:30e04330-c4bc-4619-95ef-31c5ab5b3de5: timestamp=2024-04-11T12:43:10.640Z
2024-04-11T12:43:20.650Z [DEBUG] provider.terraform-provider-azurerm_v3.98.0_x5: AzureRM Request:
GET /subscriptions/e5e059e9-92ef-4e3c-a352-00554175fc0f/resourceGroups/caz-preprod-rg/providers/Microsoft.ApiManagement/service/caz-preprod-apim/apis/j7t-reproducer-service;rev=1?api-version=2022-08-01 HTTP/1.1
Host: management.azure.com
User-Agent: HashiCorp/go-azure-sdk (Go-http-Client/1.1 api/2022-08-01) HashiCorp Terraform/1.7.5 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/3.98.0 pid-222c6c49-1b0a-5959-a213-6608f9eb8820
Accept: application/json; charset=utf-8; IEEE754Compatible=false
Content-Type: application/json; charset=utf-8
Odata-Maxversion: 4.0
Odata-Version: 4.0
X-Ms-Correlation-Request-Id: 55645181-aba8-cf02-d26f-00b83707aed0
Accept-Encoding: gzip: timestamp=2024-04-11T12:43:20.650Z
2024-04-11T12:43:20.650Z [DEBUG] provider.terraform-provider-azurerm_v3.98.0_x5: GET https://management.azure.com/subscriptions/e5e059e9-92ef-4e3c-a352-00554175fc0f/resourceGroups/caz-preprod-rg/providers/Microsoft.ApiManagement/service/caz-preprod-apim/apis/j7t-reproducer-service;rev=1?api-version=2022-08-01: timestamp=2024-04-11T12:43:20.650Z
2024-04-11T12:43:20.772Z [DEBUG] provider.terraform-provider-azurerm_v3.98.0_x5: AzureRM Response for https://management.azure.com/subscriptions/e5e059e9-92ef-4e3c-a352-00554175fc0f/resourceGroups/caz-preprod-rg/providers/Microsoft.ApiManagement/service/caz-preprod-apim/apis/j7t-reproducer-service;rev=1?api-version=2022-08-01:
HTTP/2.0 404 Not Found
Content-Length: 79
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Thu, 11 Apr 2024 12:43:20 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Ms-Correlation-Request-Id: 55645181-aba8-cf02-d26f-00b83707aed0
X-Ms-Ratelimit-Remaining-Subscription-Reads: 11998
X-Ms-Request-Id: 55645181-aba8-cf02-d26f-00b83707aed0
X-Ms-Routing-Request-Id: WESTEUROPE:20240411T124320Z:3240c800-8f52-4b70-bfb1-80aaf242554d
{"error":{"code":"ResourceNotFound","message":"Api not found.","details":null}}: timestamp=2024-04-11T12:43:20.772Z
2024-04-11T12:43:20.772Z [TRACE] provider.terraform-provider-azurerm_v3.98.0_x5: Called downstream: @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:910 tf_provider_addr=provider tf_req_id=b00d4c5c-fc8c-1784-f3ad-c7fd00990078 tf_resource_type=azurerm_api_management_api @module=sdk.helper_schema tf_rpc=ApplyResourceChange timestamp=2024-04-11T12:43:20.772Z
2024-04-11T12:43:20.773Z [TRACE] provider.terraform-provider-azurerm_v3.98.0_x5: Received downstream response: tf_resource_type=azurerm_api_management_api tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:40 tf_req_duration_ms=10611 diagnostic_error_count=1 tf_provider_addr=provider tf_req_id=b00d4c5c-fc8c-1784-f3ad-c7fd00990078 @module=sdk.proto diagnostic_warning_count=0 tf_proto_version=5.4 timestamp=2024-04-11T12:43:20.772Z
2024-04-11T12:43:20.773Z [ERROR] provider.terraform-provider-azurerm_v3.98.0_x5: Response contains error diagnostic: @module=sdk.proto diagnostic_detail=""
diagnostic_summary=
| creating/updating Api (Subscription: "e5e059e9-92ef-4e3c-a352-00554175fc0f"
| Resource Group Name: "caz-preprod-rg"
| Service Name: "caz-preprod-apim"
| Api: "j7t-reproducer-service;rev=1"): polling after CreateOrUpdate: executing request: unexpected status 404 (404 Not Found) with error: ResourceNotFound: Api not found.
tf_proto_version=5.4 tf_provider_addr=provider @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/diag/diagnostics.go:58 diagnostic_severity=ERROR tf_rpc=ApplyResourceChange tf_req_id=b00d4c5c-fc8c-1784-f3ad-c7fd00990078 tf_resource_type=azurerm_api_management_api timestamp=2024-04-11T12:43:20.773Z
2024-04-11T12:43:20.773Z [TRACE] provider.terraform-provider-azurerm_v3.98.0_x5: Served request: @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:872 @module=sdk.proto tf_proto_version=5.4 tf_provider_addr=provider tf_req_id=b00d4c5c-fc8c-1784-f3ad-c7fd00990078 tf_rpc=ApplyResourceChange tf_resource_type=azurerm_api_management_api timestamp=2024-04-11T12:43:20.773Z
2024-04-11T12:43:20.845Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-04-11T12:43:20.846Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-04-11T12:43:20.847Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/null/3.2.2/linux_amd64/terraform-provider-null_v3.2.2_x5 pid=357
2024-04-11T12:43:20.847Z [DEBUG] provider: plugin exited
2024-04-11T12:43:20.856Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/azurerm/3.98.0/linux_amd64/terraform-provider-azurerm_v3.98.0_x5 pid=366
2024-04-11T12:43:20.856Z [DEBUG] provider: plugin exited
It is not clear to me whether azurerm or some of its libraries actually calls the Location https://management.azure.com/subscriptions/e5e059e9-92ef-4e3c-a352-00554175fc0f/resourceGroups/caz-preprod-rg/providers/Microsoft.ApiManagement/service/caz-preprod-apim/apis/j7t-reproducer-service;rev=1?api-version=2022-08-01&asyncId=6617dadefb4268092441a3a0&asyncCode=201
returned by the PUT (https://learn.microsoft.com/en-us/azure/architecture/patterns/async-request-reply). It does not appear in the log in any case.
Hi @mrickly thank you very much for the information, I could reproduce your situation. I have filed an Terraform SDK issue to track it. Could you please track it for more updates?
Thank you @sinbai , I will track the new issue.
@manicminer and @sharatbhaskar1988 - I seem to have a solution that at least worked for my particular version of this issue.
When I was deploying, I was using two copies of a mostly identical template to create two different APIs. The only differences were the names of the Function Apps.
Both templates were using the same setting for "path":
resource "azurerm_api_management_api" "aaaf_apim_api_funcapp_001" { name = "api-${var.aaaf_funcapp_001_name}" resource_group_name = var.aaaf_resource_group_name api_management_name = var.aaaf_apim_name revision = "1" display_name = var.aaaf_funcapp_001_name path = "public" protocols = [ "https" ] import { content_format = "openapi" content_value = file("modules/100_funcapps/funcapp_001/openapi_spec.yaml") } depends_on = [ azurerm_api_management_backend.aaaf_apim_backend_funcapp_001 ] }
By ensuring that "path" was set differently in both templates the problem went away. I hope this is useful to you.
@deankelly780 i have an open api doc which have different paths like /a/b/c and /d/e/f. Not sure what should i set in the path property.
@sinbai I just want to let you know that this error can happens during the initial deployment (terraform apply) of an API also. When the API is a bit more complex meaning the api has a lot of resources etc. the creation of the API on the API Management can take some time. In such a case also the wrong polling URL is used and the creation of the API fails also with an 404 error. Even tough the API is actually created on the API Management. Any subsequent deployment will then succeed because the API is actually already created on the API Management.
In the TF_TRACE Log the root cause is good recognizable:
Frist the correct PUT request to create the API is made:
[DEBUG] provider.terraform-provider-azurerm_v3.99.0_x5.exe: PUT https://management.azure.com/subscriptions/1cc5c6b6-15cb-4082-ad3f-38874b1c6488/resourceGroups/caz-test-gaia-switzerlandnorth-rg/providers/Microsoft.ApiManagement/service/jfe-test-apim/apis/jfe-test-api;rev=1?api-version=2022-08-01
For wich the Azure response correctly contents the Location
header:
[DEBUG] provider.terraform-provider-azurerm_v3.99.0_x5.exe: AzureRM Response for https://management.azure.com/subscriptions/1cc5c6b6-15cb-4082-ad3f-38874b1c6488/resourceGroups/caz-test-gaia-switzerlandnorth-rg/providers/Microsoft.ApiManagement/service/jfe-test-apim/apis/jfe-test-api;rev=1?api-version=2022-08-01:
HTTP/2.0 202 Accepted
Content-Length: 0
Cache-Control: no-cache
Date: Tue, 16 Apr 2024 16:05:59 GMT
Expires: -1
Location: https://management.azure.com/subscriptions/1cc5c6b6-15cb-4082-ad3f-38874b1c6488/resourceGroups/caz-test-gaia-switzerlandnorth-rg/providers/Microsoft.ApiManagement/service/jfe-test-apim/apis/jfe-test-api;rev=1?api-version=2022-08-01&asyncId=661ea1e75ddd170c48700615&asyncCode=201
Pragma: no-cache
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Ms-Correlation-Request-Id: 0aff170c-5357-ea12-c025-fe9c194313de
X-Ms-Ratelimit-Remaining-Subscription-Writes: 1199
X-Ms-Request-Id: 0aff170c-5357-ea12-c025-fe9c194313de
X-Ms-Routing-Request-Id: GERMANYWESTCENTRAL:20240416T160559Z:6e839db5-1f26-41f2-8120-635fd7f0594f
But then instead that the URL from the Location
header is get polled (according to Track asynchronous Azure operations: url-to-monitor-status) azurerm makes a GET request with the URL of the actual API resource which does not exist yet:
[DEBUG] provider.terraform-provider-azurerm_v3.99.0_x5.exe: AzureRM Request:
GET /subscriptions/1cc5c6b6-15cb-4082-ad3f-38874b1c6488/resourceGroups/caz-test-gaia-switzerlandnorth-rg/providers/Microsoft.ApiManagement/service/jfe-test-apim/apis/jfe-test-api;rev=1?api-version=2022-08-01 HTTP/1.1
Host: management.azure.com
User-Agent: HashiCorp/go-azure-sdk (Go-http-Client/1.1 api/2022-08-01) HashiCorp Terraform/1.8.0 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/3.99.0 pid-222c6c49-1b0a-5959-a213-6608f9eb8820
Accept: application/json; charset=utf-8; IEEE754Compatible=false
Content-Type: application/json; charset=utf-8
Odata-Maxversion: 4.0
Odata-Version: 4.0
X-Ms-Correlation-Request-Id: 0aff170c-5357-ea12-c025-fe9c194313de
Accept-Encoding: gzip
Consequently Azure response then with 404 which lead then to the failure of the deployment:
[DEBUG] provider.terraform-provider-azurerm_v3.99.0_x5.exe: AzureRM Response for https://management.azure.com/subscriptions/1cc5c6b6-15cb-4082-ad3f-38874b1c6488/resourceGroups/caz-test-gaia-switzerlandnorth-rg/providers/Microsoft.ApiManagement/service/jfe-test-apim/apis/jfe-test-api;rev=1?api-version=2022-08-01:
HTTP/2.0 404 Not Found
Content-Length: 79
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Tue, 16 Apr 2024 16:06:09 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Ms-Correlation-Request-Id: 0aff170c-5357-ea12-c025-fe9c194313de
X-Ms-Ratelimit-Remaining-Subscription-Reads: 11999
X-Ms-Request-Id: 0aff170c-5357-ea12-c025-fe9c194313de
X-Ms-Routing-Request-Id: GERMANYWESTCENTRAL:20240416T160610Z:81bc76dc-904c-40ea-b8b5-d333aa296505
{"error":{"code":"ResourceNotFound","message":"Api not found.","details":null}}:
[TRACE] provider.terraform-provider-azurerm_v3.99.0_x5.exe: Called downstream: @module=sdk.helper_schema tf_req_id=5b5f079c-857a-58f5-64c4-58242ddc6e19 tf_resource_type=azurerm_api_management_api @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:910 tf_provider_addr=provider tf_rpc=ApplyResourceChange
[TRACE] provider.terraform-provider-azurerm_v3.99.0_x5.exe: Received downstream response: tf_resource_type=azurerm_api_management_api tf_rpc=ApplyResourceChange diagnostic_warning_count=0 tf_proto_version=5.4 tf_provider_addr=provider tf_req_duration_ms=12132 tf_req_id=5b5f079c-857a-58f5-64c4-58242ddc6e19 @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:40 @module=sdk.proto diagnostic_error_count=1
[ERROR] provider.terraform-provider-azurerm_v3.99.0_x5.exe: Response contains error diagnostic: @module=sdk.proto diagnostic_detail="" diagnostic_severity=ERROR
diagnostic_summary=
| creating/updating Api (Subscription: "1cc5c6b6-15cb-4082-ad3f-38874b1c6488"
| Resource Group Name: "caz-test-gaia-switzerlandnorth-rg"
| Service Name: "jfe-test-apim"
| Api: "jfe-test-api;rev=1"): polling after CreateOrUpdate: executing request: unexpected status 404 (404 Not Found) with error: ResourceNotFound: Api not found.
tf_proto_version=5.4 tf_provider_addr=provider @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/diag/diagnostics.go:58 tf_req_id=5b5f079c-857a-58f5-64c4-58242ddc6e19 tf_resource_type=azurerm_api_management_api tf_rpc=ApplyResourceChange timestamp="2024-04-16T18:06:10.163+0200"
2024-04-16T18:06:10.163+0200 [TRACE] provider.terraform-provider-azurerm_v3.99.0_x5.exe: Served request: tf_rpc=ApplyResourceChange tf_proto_version=5.4 tf_resource_type=azurerm_api_management_api tf_req_id=5b5f079c-857a-58f5-64c4-58242ddc6e19 @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:872 @module=sdk.proto tf_provider_addr=providert
So I think this will get probably also fixed with https://github.com/hashicorp/go-azure-sdk/issues/962 .
Is there an existing issue for this?
Community Note
Terraform Version
1.5.7
AzureRM Provider Version
Affected Resource(s)/Data Source(s)
azurerm_api_management_api
Terraform Configuration Files
EXAMPLE managed_apis var:
EXAMPLE test.openapi.yaml
Debug Output/Panic Output
Expected Behaviour
The
azurerm_api_management_api
should be created successfully.I'm trying to create an
azurerm_api_management_api
using an openapi type imported file.Actual Behaviour
With any version
> 3.69.0
, Theazurerm_api_management_api
creation fails with the following error:If you used
<= 3.69.0
the creation is successful.Steps to Reproduce
terraform apply
Important Factoids
No response
References
No response