Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry to create storage container. #846

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Retry to create storage container.
#841

Signed-off-by: Genevieve LEsperance <glesperance@pivotal.io>
rowanjacobs authored and Genevieve LEsperance committed Feb 15, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 97f2843a94fa70f11b35d35aa6dad21f86d648f8
17 changes: 15 additions & 2 deletions azurerm/resource_arm_storage_container.go
Original file line number Diff line number Diff line change
@@ -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{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explicitly set timeout here so we can effectively use the timeout duration of the Retry call? I'm not sure on the default, maybe its ok?

Copy link
Author

@genevieve genevieve Feb 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s only one other instance of retrying in the codebase that’s I found and the timeout was not configurable. We can add a create timeout to the scheme if we think it should be adjustable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we lean on the SDK's default timeout through the codebase, so I don't think we need to override this value? (2m should be enough time for Azure to become consistent)

_, 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 {