Skip to content

Commit

Permalink
Merge pull request #846 from genevieve/master
Browse files Browse the repository at this point in the history
Retry to create storage container.
  • Loading branch information
tombuildsstuff authored Feb 16, 2018
2 parents 08da498 + 97f2843 commit 54c3ca4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions azurerm/resource_arm_storage_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down

0 comments on commit 54c3ca4

Please sign in to comment.