Skip to content

Commit

Permalink
Fix schema not always visibile just after creation.
Browse files Browse the repository at this point in the history
Retry client.Get in resourceApiManagementApiSchemaCreateUpdate in case that
schema was not yet created.
  • Loading branch information
wiktorn committed Jun 11, 2021
1 parent 015be11 commit 6af5f41
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 6af5f41

Please sign in to comment.