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

upgrade apimanagement from 2018-01-01 to 2019-01-01 #5096

Conversation

tnicolaysen
Copy link
Contributor

  • added support for OpenAPI import types in API resource
  • 2018-01-01 api has been removed from /vendor
  • 2019-01-01 api has been added to /vendor
  • documentation has been updated
  • all breaking compiler changes have been fixed
  • API, Policy, Subscription and User resources have been tested

TODOs are still left and awaiting further detailing after discussions and input from the community

- added support for OpenAPI import types in API resource
- 2018-01-01 api has been removed from /vendor
- 2019-01-01 api has been added to /vendor
- documentation has been updated
- all breaking compiler changes have been fixed
- API, Policy, Subscription and User resources have been tested

TODOs are still left and awaiting further detailing after discussions and input from the community
@@ -553,14 +554,14 @@ func resourceArmApiManagementServiceCreateUpdate(d *schema.ResourceData, meta in
signInSettingsRaw := d.Get("sign_in").([]interface{})
signInSettings := expandApiManagementSignInSettings(signInSettingsRaw)
signInClient := meta.(*ArmClient).ApiManagement.SignInClient
if _, err := signInClient.CreateOrUpdate(ctx, resourceGroup, name, signInSettings); err != nil {
if _, err := signInClient.CreateOrUpdate(ctx, resourceGroup, name, signInSettings, ""); err != nil { // TODO: Check how to deal with etag
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help verifying how to work with the If-Match header / Etags in this plugin.

return fmt.Errorf("Error setting Sign In settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

signUpSettingsRaw := d.Get("sign_up").([]interface{})
signUpSettings := expandApiManagementSignUpSettings(signUpSettingsRaw)
signUpClient := meta.(*ArmClient).ApiManagement.SignUpClient
if _, err := signUpClient.CreateOrUpdate(ctx, resourceGroup, name, signUpSettings); err != nil {
if _, err := signUpClient.CreateOrUpdate(ctx, resourceGroup, name, signUpSettings, ""); err != nil { // TODO: Check how to deal with etag
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help verifying how to work with the If-Match header / Etags in this plugin.

@@ -581,7 +582,7 @@ func resourceArmApiManagementServiceCreateUpdate(d *schema.ResourceData, meta in

// then add the new one, if it exists
if policy != nil {
if _, err := policyClient.CreateOrUpdate(ctx, resourceGroup, name, *policy); err != nil {
if _, err := policyClient.CreateOrUpdate(ctx, resourceGroup, name, *policy, ""); err != nil { // TODO: Check how to deal with etag
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help verifying how to work with the If-Match header / Etags in this plugin.

@@ -711,7 +712,7 @@ func resourceArmApiManagementServiceDelete(d *schema.ResourceData, meta interfac
log.Printf("[DEBUG] Deleting API Management Service %q (Resource Grouo %q)", name, resourceGroup)
resp, err := client.Delete(ctx, resourceGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(resp) {
if !(resp.Response() != nil && (*resp.Response()).StatusCode == http.StatusNotFound) { // TODO: VERIFY!!!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new API returns a Future type. The helper did not have support for that.
I think this codes does the same logical check, i.e. check that the response is not 404.

Copy link
Contributor

@evertonmc evertonmc Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -159,8 +167,9 @@ func resourceArmApiManagementApiSchemaDelete(d *schema.ResourceData, meta interf
serviceName := id.Path["service"]
apiName := id.Path["apis"]
schemaID := id.Path["schemas"]
force := false // TODO: Verify that this is correct
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the plugin has a concept of force. Is false the correct value?

@@ -241,8 +241,9 @@ func resourceArmApiManagementLoggerDelete(d *schema.ResourceData, meta interface
resourceGroup := id.ResourceGroup
serviceName := id.Path["service"]
name := id.Path["loggers"]
force := false // TODO: validate that this is correct
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the plugin has a concept of force. Is false the correct value?

Comment on lines -124 to +129
ProductID: utils.String(productId),
Scope: utils.String(scope),
State: apimanagement.SubscriptionState(state),
UserID: utils.String(userId),
OwnerID: utils.String(ownerId),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major breaking change in the Azure SDK.
ProductID -> Scope
UserID -> OwnerID
The values have different formats. Example from the docs:

{
  "properties": {
    "ownerId": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/users/57127d485157a511ace86ae7",
    "scope": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/products/5600b59475ff190048060002",
    "displayName": "testsub"
  }
}

The Go SDK looked like it supported relative paths, i.e. /users/USER-ID
The scope property supports other things than the product, but I used product since it was used in the current implementation.

https://docs.microsoft.com/en-us/rest/api/apimanagement/2019-01-01/subscription/createorupdate

@@ -184,8 +187,8 @@ func resourceArmApiManagementSubscriptionRead(d *schema.ResourceData, meta inter
d.Set("primary_key", props.PrimaryKey)
d.Set("secondary_key", props.SecondaryKey)
d.Set("state", string(props.State))
d.Set("product_id", props.ProductID)
d.Set("user_id", props.UserID)
d.Set("scope", props.Scope) // TODO: check if this is a breaking change. was product_id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this mess up diffing (i.e. plan) after updating?

@tnicolaysen
Copy link
Contributor Author

@tombuildsstuff Do you want a issue to go along with this, or is a PR enough?

- tested and looks like it behaves as expected. inspected state-file.
@tombuildsstuff
Copy link
Contributor

hey @tnicolaysen

Thanks for this PR - apologies for the delayed review here!

Previous versions of the API Management API only supported using JSON for the API Management Schema - however API version 2019-01-01 introduces support for using SOAP/XML in addition to JSON. This is problematic for us due to the way the API Response is structured differently - where the properties object is different for XML and JSON - meaning that in it's current form this isn't deserialized correctly in the Azure SDK for Go.

We've opened several issues/PR's to fix this in the Azure SDK for Go (or rather, the Azure/azure-rest-api-specs repository, which it's generated from) - however the API team has instead opted to fix this in a new API version, which is being tracked in this Github issue.

Ultimately this means that we're currently blocked from upgrading the version of the Azure API being used for API Management until the new API version is available (which we're aware is blocking multiple PR's/bits of new functionality). However since we're currently blocked from upgrading to this API version (and I'd like to thank you for this contribution) - unfortunately I'm going to close this PR for the moment until the upstream issue has been resolved/the new API version has become available.

Thanks!

@ghost
Copy link

ghost commented Mar 29, 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 👉 hashibot-feedback@hashicorp.com. Thanks!

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

Successfully merging this pull request may close these issues.

3 participants