diff --git a/azurerm/internal/services/apimanagement/api_management_api_schema_resource.go b/azurerm/internal/services/apimanagement/api_management_api_schema_resource.go index 19b95a823ec95..ec811abc1f9ad 100644 --- a/azurerm/internal/services/apimanagement/api_management_api_schema_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_api_schema_resource.go @@ -6,6 +6,7 @@ import ( "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement/schemaz" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" @@ -105,15 +106,23 @@ func resourceApiManagementApiSchemaCreateUpdate(d *schema.ResourceData, meta int return fmt.Errorf("creating or updating API Schema %q (API Management Service %q / API %q / Resource Group %q): %s", schemaID, serviceName, apiName, resourceGroup, err) } - resp, err := client.Get(ctx, resourceGroup, serviceName, apiName, schemaID) + err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + resp, err := client.Get(ctx, resourceGroup, serviceName, apiName, schemaID) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return resource.RetryableError(fmt.Errorf("Expected schema %q (API Management Service %q / API %q / Resource Group %q) to be created but was in non existent state, retrying", schemaID, serviceName, apiName, resourceGroup)) + } + return resource.NonRetryableError(fmt.Errorf("Error geting schema %q (API Management Service %q / API %q / Resource Group %q): %+v", schemaID, serviceName, apiName, resourceGroup, err)) + } + if resp.ID == nil { + return resource.NonRetryableError(fmt.Errorf("Cannot read ID for API Schema %q (API Management Service %q / API %q / Resource Group %q): %s", schemaID, serviceName, apiName, resourceGroup, err)) + } + d.SetId(*resp.ID) + return nil + }) if err != nil { - return fmt.Errorf("retrieving API Schema %q (API Management Service %q / API %q / Resource Group %q): %s", schemaID, serviceName, apiName, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read ID for API Schema %q (API Management Service %q / API %q / Resource Group %q): %s", schemaID, serviceName, apiName, resourceGroup, err) + return fmt.Errorf("Error geting schema %q (API Management Service %q / API %q / Resource Group %q): %+v", schemaID, serviceName, apiName, resourceGroup, err) } - d.SetId(*resp.ID) - return resourceApiManagementApiSchemaRead(d, meta) }