Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Management (azurerm_api_management_api) support for openapi v3 content_format #3203

Closed
mhennecke opened this issue Apr 7, 2019 · 26 comments

Comments

@mhennecke
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

The azurerm_api_management_api is missing support for OpenAPI v3 JSON and YAML imports in
provider version v1.24.0. Please add "openapi", "openapi+json" and "openapi-link" to the allowed content formats.

New or Affected Resource(s)

  • azurerm_api_management_api

Potential Terraform Configuration

resource "azurerm_resource_group" "test" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_api_management" "test" {
  name                = "example-apim"
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"
  publisher_name      = "My Company"
  publisher_email     = "[email protected]"

  sku {
    name     = "Developer"
    capacity = 1
  }
}

resource "azurerm_api_management_api" "test" {
  name                = "example-api"
  resource_group_name = "${azurerm_resource_group.test.name}"
  api_management_name = "${azurerm_api_management.test.name}"
  revision            = "1"
  display_name        = "Example API"
  path                = "example"
  protocols           = ["https"]

  import {
    content_format = "openapi-link"
    content_value  = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml"
  }
}

References

@tombuildsstuff
Copy link
Contributor

hey @mhennecke

Thanks for opening this issue :)

Taking a look into this it appears this requires an upgrade to the version of the Azure API we're using - we've got an upstream issue open requesting that here (which I've just requested an update for), but once that becomes available in the Azure SDK for Go (which is generated from that repo) we can look to add support for this 👍

Thanks!

@tombuildsstuff tombuildsstuff modified the milestones: v1.25.0, Blocked Apr 8, 2019
@tombuildsstuff tombuildsstuff removed this from the Blocked milestone May 10, 2019
@tombuildsstuff tombuildsstuff removed the upstream/microsoft Indicates that there's an upstream issue blocking this issue/PR label May 10, 2019
@tombuildsstuff
Copy link
Contributor

👋

The upstream issue's been fixed: Azure/azure-rest-api-specs#4409 - once the SDK's been updated #3335 we should be able to go to the new version of the API Management API - at which point it should be possible to add support for this

Thanks!

@aczelandi
Copy link
Contributor

hey @tombuildsstuff,

Any plans on this? :)

@aczelandi
Copy link
Contributor

aczelandi commented Jul 26, 2019

cc. @katbyte
Do you have any plans on implementing this?
I tried to do it but it seems like it requires updating azure-sdk-for-go to version 31.2.0 and autorest to 0.5.0, and updating everything to api version 2019-01-01, but it became too complicated.

/cc. @maximbaz

@ybelMekk
Copy link

ybelMekk commented Oct 3, 2019

Hei. Im intressed in this feature. Im working for Norway welfare and is in need for this, as we are exposing apis with the use of Azure Api-management. I would like to build the infrastructure with terraform.

Any updates on the upgrade of the version of the Azure API?

please hit me back

thanks

@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Oct 9, 2019

@ybelMekk @AndiA92 unfortunately we're still blocked on Azure/azure-rest-api-specs#6372

Once the Swagger's been fixed / the new API is available we should be able to add support for this - but unfortunately there's not a lot we can do until that's resolved.

Thanks!

@tombuildsstuff tombuildsstuff added this to the Blocked milestone Oct 9, 2019
@tombuildsstuff tombuildsstuff added the upstream/microsoft Indicates that there's an upstream issue blocking this issue/PR label Oct 9, 2019
@molinch
Copy link

molinch commented Oct 24, 2019

@tombuildsstuff Hi Tom, is this issue blocking importing an OpenAPI specification using Terraform?
The above can be done using Powershell and ARM already.

@tombuildsstuff
Copy link
Contributor

@molinch yep - we're still waiting on the API Team to publish a Swagger document (which in turn generates a Go SDK for us to use) for the new API version

@jeanpaulsmit
Copy link
Contributor

Any updates on this or possibly a timeframe?

@timja
Copy link
Contributor

timja commented Jan 15, 2020

@PPACI
Copy link

PPACI commented Jan 30, 2020

Just for information. I've forked the provider on my side, and I've managed to used openapi3 json and yaml.
I think I will not do a PR since I don't have time to properly check inetgration test and if I didn't break something in the process, but here it what I've done :

  1. I've updated the dependency of the resource to 2019-01-01 release of azure go sdk
    https://github.com/terraform-providers/terraform-provider-azurerm/blob/a3fc3a99a8c8b5a412a906df662a54633d22f224/azurerm/internal/services/apimanagement/resource_arm_api_management_api.go#L9
    I had to correct some signatures but it was more about passing empty string (that's where i'm not 100% sure of what I've done)
  2. Add the new signature to the "enum" of valid content
    https://github.com/terraform-providers/terraform-provider-azurerm/blob/a3fc3a99a8c8b5a412a906df662a54633d22f224/azurerm/internal/services/apimanagement/resource_arm_api_management_api.go#L102

For reference, here is the list
https://github.com/Azure/azure-sdk-for-go/blob/91316876b14205b98fc116bba77b3bb689746954/services/apimanagement/mgmt/2019-01-01/apimanagement/models.go#L205

Then you can go build and name your custom plugin like terraform-provider-custom. Put the provider in your project folder.

You will able to import it like

provider "azurerm" {
  version = "=1.42.0"
}

provider "custom" {
}

and then use it just for your resource like

resource "azurerm_api_management_api" "foobar" {
  provider            = custom
  name                 = "foobar"
  import {
    content_format = "openapi"
    content_value  = file("${path.module}/api-schema/openapi_openapi.yml")
  }
}

I hope it will help some people 👍
Since it's go, I can cross-compile the forked plugin for people if you don't want to re-fork it. Tell me.

PS. The fork is on an internal gitlab server, so I can't directly share the repo...

@mcalster
Copy link

mcalster commented Feb 2, 2020

@tombuildsstuff the Azure go sdk has been updated, do you have a timeline on when the Provider will be updated? Just wanting to know if we should pursue the steps @PPACI outlined above or wait for the official fix.
Thx for the great work so far :-)

@timja
Copy link
Contributor

timja commented Feb 11, 2020

It has now been updated, released in 39.1.0 of the azure sdk for go Azure/azure-sdk-for-go#7317

@tombuildsstuff tombuildsstuff added sdk/requires-newer-api-version This requires upgrading the version of the API being used sdk/requires-upgrade This is dependent upon upgrading an SDK labels Feb 11, 2020
@mcalster

This comment has been minimized.

@abhijithkumar123
Copy link

abhijithkumar123 commented Feb 20, 2020

When I set content_format as "swagger-link-json" and try to import an openapi v3 spec file, I get the following error:

StatusCode=404 -- Original Error: autorest/azure: error response cannot be parsed: "" error: EOF

Is there a workaround to this?

@alanwales
Copy link

I am also seeing "The Swagger version specified is unknown" when trying to upload an open api v3 document, until the openapi-link content_format is supported we will continue to use V2 swagger

@ybelMekk
Copy link

Is this one closed any day soon? 💃

@vinoth12988
Copy link

@tombuildsstuff , Azure API stopped support on exporting Swagger-json format from the portal. Which means only way to update the existing API's in the APIM is through openAPI format from Terrafrom. This is now high priority.

@hctv19
Copy link

hctv19 commented Mar 27, 2020

@tombuildsstuff There were a number of updates recently merged into the https://github.com/Azure/azure-rest-api-specs repo, and it looks like the Go SDK has been updated as well based on the last comment on the issue that was marked as blocking this one: Azure/azure-rest-api-specs#4409

@lucashuet93
Copy link
Contributor

lucashuet93 commented Apr 20, 2020

I'd began work on the addition of the OAS v3 content-formats, but realized that this is a much larger undertaking than originally expected.

The current set of API Management related azurerm code uses the 2018-01-01 version of APIM, and the OASv3 content-formats were added in version 2019-01-01. The azurerm provider now uses version 41.0.0 of the Azure SDK for Go, which added support for APIM versions 2018-06-01-preview, 2019-01-01, and 2019-12-01-preview, so the addition of the OASv3 content-formats is indeed possible.

In order to make the change to allow the new content-formats on the API resource, however, the entire azurerm codebase for API Management needs to be updated to utilize 2019-01-01. As soon as the version is updated, it breaks clients and other resources downstream. The upgrade to the new version of APIM cannot be limited to the API resource type only. Even if it was possible to limit the changes to the API resource without causing other errors, I’m not sure that the Terraform team would accept a PR that causes the set of API Management resources to use multiple versions and be out of sync with each other. It will all need to be updated simultaneously.

@katbyte
Copy link
Collaborator

katbyte commented Apr 23, 2020

@lucashuet93 - i merged in a PR to upgrade to 2019-12-01 a couple days ago so this should be unblocked now 🙂

@katbyte katbyte removed this from the Blocked milestone Apr 23, 2020
@katbyte katbyte removed sdk/requires-newer-api-version This requires upgrading the version of the API being used sdk/requires-upgrade This is dependent upon upgrading an SDK upstream/microsoft Indicates that there's an upstream issue blocking this issue/PR labels Apr 23, 2020
@lucashuet93
Copy link
Contributor

@katbyte Awesome to hear! I've now opened PR #6618 which fixes this issue.

@mbfrahry mbfrahry added this to the v2.8.0 milestone Apr 24, 2020
@mbfrahry
Copy link
Member

This has been merged with #6618 and should make it into v2.8.0 of the provider

@ghost
Copy link

ghost commented May 1, 2020

This has been released in version 2.8.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.8.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented May 25, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators May 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests