From 97f2843a94fa70f11b35d35aa6dad21f86d648f8 Mon Sep 17 00:00:00 2001 From: Rowan Jacobs Date: Thu, 15 Feb 2018 15:45:57 -0800 Subject: [PATCH] Retry to create storage container. https://github.com/terraform-providers/terraform-provider-azurerm/issues/841 Signed-off-by: Genevieve LEsperance --- azurerm/resource_arm_storage_container.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_storage_container.go b/azurerm/resource_arm_storage_container.go index e359fddb8aba..416eb03f127d 100644 --- a/azurerm/resource_arm_storage_container.go +++ b/azurerm/resource_arm_storage_container.go @@ -4,10 +4,12 @@ import ( "fmt" "log" "strings" + "time" "regexp" "github.com/Azure/azure-sdk-for-go/storage" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) @@ -105,8 +107,7 @@ func resourceArmStorageContainerCreate(d *schema.ResourceData, meta interface{}) log.Printf("[INFO] Creating container %q in storage account %q.", name, storageAccountName) reference := blobClient.GetContainerReference(name) - createOptions := &storage.CreateContainerOptions{} - _, err = reference.CreateIfNotExists(createOptions) + err = resource.Retry(120*time.Second, checkContainerIsCreated(reference)) if err != nil { return fmt.Errorf("Error creating container %q in storage account %q: %s", name, storageAccountName, err) } @@ -124,6 +125,18 @@ func resourceArmStorageContainerCreate(d *schema.ResourceData, meta interface{}) return resourceArmStorageContainerRead(d, meta) } +func checkContainerIsCreated(reference *storage.Container) func() *resource.RetryError { + return func() *resource.RetryError { + createOptions := &storage.CreateContainerOptions{} + _, err := reference.CreateIfNotExists(createOptions) + if err != nil { + return resource.RetryableError(err) + } + + return nil + } +} + // resourceAzureStorageContainerRead does all the necessary API calls to // read the status of the storage container off Azure. func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) error {