From 5e3bf1cd42cda719b7f51d38ee92eece101d821b Mon Sep 17 00:00:00 2001 From: Simon Schneider Date: Tue, 3 Dec 2019 15:15:28 +0100 Subject: [PATCH] check for response not found also when no error occurs fixes a bug that reflects Azure apimanagement API behaviour changes from 2018-01-01 to 2019-01-01 --- azurerm/resource_arm_api_management_product_api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/azurerm/resource_arm_api_management_product_api.go b/azurerm/resource_arm_api_management_product_api.go index 93055da71081..45fa29ea8911 100644 --- a/azurerm/resource_arm_api_management_product_api.go +++ b/azurerm/resource_arm_api_management_product_api.go @@ -102,6 +102,14 @@ func resourceArmApiManagementProductApiRead(d *schema.ResourceData, meta interfa return fmt.Errorf("Error retrieving API %q / Product %q (API Management Service %q / Resource Group %q): %+v", apiName, productId, serviceName, resourceGroup, err) } + // This can be removed once updated to apimanagement API to 2019-01-01 + // https://github.com/Azure/azure-sdk-for-go/blob/master/services/apimanagement/mgmt/2019-01-01/apimanagement/productapi.go#L134 + if utils.ResponseWasNotFound(resp) { + log.Printf("[DEBUG] API %q was not found in Product %q (API Management Service %q / Resource Group %q) was not found - removing from state!", apiName, productId, serviceName, resourceGroup) + d.SetId("") + return nil + } + d.Set("api_name", apiName) d.Set("product_id", productId) d.Set("resource_group_name", resourceGroup)