hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.62k forks source link

creating an APIM revision results in error message Can't change property ApiVersion for non-current revision #18093

Closed jojoismael closed 9 months ago

jojoismael commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2.6

AzureRM Provider Version

2.84, 3.17.0

Affected Resource(s)/Data Source(s)

azurerm_api_management_api

Terraform Configuration Files

resource "azurerm_api_management_api" "apim-api-env-api" {
    name                = "APISample"
    resource_group_name = azurerm_api_management.apim-env-api.resource_group_name
    api_management_name = azurerm_api_management.apim-env-api.name
    display_name        = "APISample"
    description         = "APISample"
    path                = "APISample"
    protocols           = ["https"]
    revision            = "1"

    import {
     content_format = "openapi+json"
     content_value  = file("swaggerFiles/suppliers-1.json")
    }

}

resource "azurerm_api_management_api" "apim-api-env-api2" {
    name                = "APISample"
    resource_group_name = azurerm_api_management.apim-env-api.resource_group_name
    api_management_name = azurerm_api_management.apim-env-api.name
    display_name        = "APISample"
    description         = "APISample"
    path                = "APISample"
    protocols           = ["https"]
    revision            = "2"

    import {
     content_format = "openapi+json"
     content_value  = file("swaggerFiles/suppliers-1.json")
    }

       depends_on = [azurerm_api_management_api.apim-api-env-api]

  }

Debug Output/Panic Output

│ Error: waiting on creating/updating API Management API "APISample" (Resource Group "rg-sample-api"): Future#WaitForCompletion: the number of retries has been exceeded: StatusCode=400 -- Original Error: Code="ValidationError" Message="Can't change property Name for non-current revision "
│
│   with azurerm_api_management_api.apim-api-env-api2,
│   on apim-env-api.tf line 94, in resource "azurerm_api_management_api" "apim-api-env-api2":
│   94:   resource "azurerm_api_management_api" "apim-api-env-api2" {
│

Expected Behaviour

APIM API revision to be created in Azure portal, as per previous behaviour

Actual Behaviour

HTTP 400 returned with message: Can't change property Name for non-current revision

Steps to Reproduce

  1. Set environment variables for tracing

TF_LOG="TRACE" TF_LOG_PROVIDER="TRACE" TF_LOG_PATH="c:\tmp\terraform.txt"

  1. Two instances of azurerm_api_management_api declared
  1. AzureRM v 2.84 and v.3.17.0 returns error 400: Can't change property Name for non-current revision

  2. Next, copy PUT payload from terraform log file and submit via https://docs.microsoft.com/en-us/rest/api/apimanagement/current-ga/apis/create-or-update?tabs=HTTP#code-try-0

Important Factoids

No response

References

No response

jojoismael commented 2 years ago

Hello , first of all thanks to the entire terraform and the terraform azurerm provider teams for all of your great work and your hard work is truly appreciated by the community at large.

Previously, this was working perfectly fine , eg, revisions were being created successfully using our existing swagger files.

Then, I had to create a separate environment using our existing working terraform code base and then suddenly , we are getting this 400 error from the azurerm provider.

Tested both in azurerm 2.84 and 3.17 with same HTTP 400 results

In contrast, trying the same payload that was acquired from the terraform diagnostic log file in docs.micosoft.com (try button) results in a successful operation for both the base API and its ;rev-2

Please do take note that in both cases for the base API and revision=2, the same swagger file is being imported

Thanks so much for your assistance!

jojoismael commented 2 years ago

Update:

Modifying the swagger file’s title and description fields under “info” property to be the same as the name, display name, description and path in the terraform file has resulted on a different error on another field

From:

Message="Can't change property Name for non-current revision"

To:

Message="Can't change property ApiVersion for non-current revision"

│ Error: waiting on creating/updating API Management API "SampleApi" (Resource Group "rg-sample-api"): Future#WaitForCompletion: the number of retries has been exceeded: StatusCode=400 -- Original Error: Code="ValidationError" Message="Can't change property ApiVersion for non-current revision "

any thoughts? Thanks!

rubenaster commented 1 year ago

@jojoismael does working with revisions work for you now? I've noticed that with azurerm 3.17.0+ the revision in the state file is always set to "1", even so it's definitely configured with "2" etc.

levimatheri commented 1 year ago

I'm having this issue too, seeing this error message: "Can't change property ApiVersion for non-current revision"

S1M0NM commented 1 year ago

We also face this error, so currently it is not possible to create revisions.

rcskosir commented 9 months ago

Updating PR linking for this issue - PR https://github.com/hashicorp/terraform-provider-azurerm/pull/22380 has been superseded by https://github.com/hashicorp/terraform-provider-azurerm/pull/23031.

celsocoutinho-tangany commented 8 months ago

I am trying to create a new revision an an existing APIM API, and still getting an error on azurerm 3.89.0:

│ Error: creating/updating Api (Subscription: "xxx"
│ Resource Group Name: "xxx"
│ Service Name: "xxx"
│ Api: "my-api-id;rev=my-revision-id"): polling after CreateOrUpdate: executing request: unexpected status 404 with error: ResourceNotFound: Api not found.
│ 
│   with azurerm_api_management_api.apim_api_revision,
│   on main.tf line 14, in resource "azurerm_api_management_api" "apim_api_revision":
│   14: resource "azurerm_api_management_api" "apim_api_revision" {

With the code:

resource "azurerm_api_management_api" "apim_api_revision" {

  name                = data.azurerm_api_management_api.apim_api.name
  resource_group_name = data.azurerm_api_management_api.resource_group_name
  api_management_name = data.azurerm_api_management_api.api_management_name
  revision            = "my-revision"
  display_name        = "my-revision"
  source_api_id       = data.azurerm_api_management_api.apim_api.id

  import {
    content_format = "openapi"
    content_value  = templatefile("${path.root}/openapi.yaml", {})
  }
}

Am I doing something wrong, or is it the case that https://github.com/hashicorp/terraform-provider-azurerm/pull/23031 didn't solve the issue?

github-actions[bot] commented 5 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.