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

azurerm_api_management_product_api does not assign an API to a product if this assignment existed previously #5002

Closed
eugeneromero opened this issue Nov 27, 2019 · 4 comments · Fixed by #5054

Comments

@eugeneromero
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

Terraform (and AzureRM Provider) Version

1.37.0

Affected Resource(s)

  • azurerm_api_management_product_api

Terraform Configuration Files

resource "azurerm_api_management_product_api" "attach" {
  product_id = "test"
  api_name = "myAPI"
  api_management_name = "myAPImanager"
  resource_group_name = "rg"
}

Expected Behavior

After creating an API and attaching it to a product with Terraform, one should be able to delete the API and, upon recreating it, the API should be attached to the product again.

Actual Behavior

When recreating the API, Terraform creates the API succesfully, but does not see the need to add it to the product, so the API ends up with no product assignment. If one tries assigning it to a different product however, this works successfully.

When performing the plan, terraform does refresh the product_api state, but it thinks the API is still assigned to the product (from its previous assignment) so does not attempt to add it again.

Steps to Reproduce

  1. Declare a new API with azurerm_api_management_api
  2. Add the API to an existing product with azurerm_api_management_product_api
  3. terraform plan & apply, the API is created and added successfully to the product
  4. Manually remove the API from the API Management
  5. Run terraform plan --refresh=true and apply again
  6. Terraform recreates the API but does not assign it to a product
  7. Repeat the above three steps but change the product_id to a different one, TF successfully adds it to the product

Important Factoids

References

  • #0000
@eugeneromero
Copy link
Author

Pinging @tombuildsstuff since he is the original creator of this resource :)

@eugeneromero eugeneromero changed the title azurerm_api_management_product_api does not add a new API if it existed previously azurerm_api_management_product_api does not assign an API to a product if this assignment existed previously Nov 27, 2019
@evertonmc
Copy link
Contributor

bug seems to be related to the Plan checking if the *_product_api already exists before creating
https://github.com/terraform-providers/terraform-provider-azurerm/blob/0fd80ac109826ceb3c2cd6ca791b5943e45ec0c4/azurerm/resource_arm_api_management_product_group.go#L94-L96
and never getting into because the client will return error==nil for NotFound status codes (when the *_product_api link doesn't exist yet)

https://github.com/terraform-providers/terraform-provider-azurerm/blob/0fd80ac109826ceb3c2cd6ca791b5943e45ec0c4/vendor/github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement/productapi.go#L131-L139

In this stage, tf doesn't plan the creation of the azurerm_api_management_product_api because it ignores the missing existence

@ghost
Copy link

ghost commented Jan 8, 2020

This has been released in version 1.40.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 = "~> 1.40.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Mar 28, 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 Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants