mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-03 20:57:09 -06:00
providers/azurerm: attempt to read storage account ID if cancelled
This commit is contained in:
parent
8dafcb36fd
commit
ccb972ae50
@ -141,23 +141,34 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
|
||||
|
||||
// Check the result of the wrapped function. I put this into a select
|
||||
// since we will likely also want to introduce a time-based timeout.
|
||||
var err error
|
||||
var createErr error
|
||||
select {
|
||||
case err = <-wrap.ErrCh:
|
||||
case createErr = <-wrap.ErrCh:
|
||||
// Successfully ran (but perhaps not successfully completed)
|
||||
// the function.
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error creating Azure Storage Account '%s': %s",
|
||||
storageAccountName, err)
|
||||
}
|
||||
|
||||
// The only way to get the ID back apparently is to read the resource again
|
||||
read, err := storageClient.GetProperties(resourceGroupName, storageAccountName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set the ID right away if we have one
|
||||
if read.ID != nil {
|
||||
log.Printf("[INFO] storage account %q ID: %q", storageAccountName, *read.ID)
|
||||
d.SetId(*read.ID)
|
||||
}
|
||||
|
||||
// If we had a create error earlier then we return with that error now.
|
||||
// We do this later here so that we can grab the ID above is possible.
|
||||
if createErr != nil {
|
||||
return fmt.Errorf(
|
||||
"Error creating Azure Storage Account '%s': %s",
|
||||
storageAccountName, createErr)
|
||||
}
|
||||
|
||||
// If we got no ID then the resource group doesn't yet exist
|
||||
if read.ID == nil {
|
||||
return fmt.Errorf("Cannot read Storage Account %s (resource group %s) ID",
|
||||
storageAccountName, resourceGroupName)
|
||||
@ -175,8 +186,6 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
|
||||
return fmt.Errorf("Error waiting for Storage Account (%s) to become available: %s", storageAccountName, err)
|
||||
}
|
||||
|
||||
d.SetId(*read.ID)
|
||||
|
||||
return resourceArmStorageAccountRead(d, meta)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user