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

Support for Custom Timeouts in Custom Refresh Func's #4838

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion azurerm/resource_arm_automation_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func resourceArmAutomationModuleCreateUpdate(d *schema.ResourceData, meta interf
Target: []string{
string(automation.ModuleProvisioningStateSucceeded),
},
Timeout: 30 * time.Minute,
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err2 := client.Get(ctx, resGroup, accName, name)
Expand All @@ -157,6 +156,15 @@ func resourceArmAutomationModuleCreateUpdate(d *schema.ResourceData, meta interf
return resp, "Unknown", nil
},
}
if features.SupportsCustomTimeouts() {
if d.IsNewResource() {
stateConf.Timeout = d.Timeout(schema.TimeoutCreate)
} else {
stateConf.Timeout = d.Timeout(schema.TimeoutUpdate)
}
} else {
stateConf.Timeout = 30 * time.Minute
}

_, err := stateConf.WaitForState()
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,16 @@ func resourceArmContainerGroupDelete(d *schema.ResourceData, meta interface{}) e
Pending: []string{"Attached"},
Target: []string{"Detached"},
Refresh: containerGroupEnsureDetachedFromNetworkProfileRefreshFunc(ctx, networkProfileClient, networkProfileResourceGroup, networkProfileName, resourceGroup, name),
Timeout: 10 * time.Minute,
MinTimeout: 15 * time.Second,
ContinuousTargetOccurence: 5,
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = d.Timeout(schema.TimeoutDelete)
} else {
stateConf.Timeout = 10 * time.Minute
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Container Group %q (Resource Group %q) to finish deleting: %s", name, resourceGroup, err)
}
Expand Down
12 changes: 11 additions & 1 deletion azurerm/resource_arm_container_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,19 @@ func resourceArmContainerServiceCreateUpdate(d *schema.ResourceData, meta interf
Pending: []string{"Updating", "Creating"},
Target: []string{"Succeeded"},
Refresh: containerServiceStateRefreshFunc(client, resGroup, name),
Timeout: 30 * time.Minute,
MinTimeout: 15 * time.Second,
}

if features.SupportsCustomTimeouts() {
if d.IsNewResource() {
stateConf.Timeout = d.Timeout(schema.TimeoutCreate)
} else {
stateConf.Timeout = d.Timeout(schema.TimeoutUpdate)
}
} else {
stateConf.Timeout = 30 * time.Minute
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Container Service (%s) to become available: %s", d.Get("name"), err)
}
Expand Down
28 changes: 21 additions & 7 deletions azurerm/resource_arm_cosmosdb_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{})
}
}

resp, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account)
resp, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account, d)
if err != nil {
return fmt.Errorf("Error creating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down Expand Up @@ -496,7 +496,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
Tags: tags.Expand(t),
}

if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account); err != nil {
if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account, d); err != nil {
return fmt.Errorf("Error updating CosmosDB Account %q properties (Resource Group %q): %+v", name, resourceGroup, err)
}

Expand Down Expand Up @@ -532,14 +532,14 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
}

account.DatabaseAccountCreateUpdateProperties.Locations = &locationsUnchanged
if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account); err != nil {
if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account, d); err != nil {
return fmt.Errorf("Error removing CosmosDB Account %q renamed locations (Resource Group %q): %+v", name, resourceGroup, err)
}
}

//add any new/renamed locations
account.DatabaseAccountCreateUpdateProperties.Locations = &newLocations
upsertResponse, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account)
upsertResponse, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account, d)
if err != nil {
return fmt.Errorf("Error updating CosmosDB Account %q locations (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down Expand Up @@ -741,7 +741,6 @@ func resourceArmCosmosDbAccountDelete(d *schema.ResourceData, meta interface{})
stateConf := &resource.StateChangeConf{
Pending: []string{"Deleting"},
Target: []string{"NotFound"},
Timeout: 180 * time.Minute,
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err2 := client.Get(ctx, resourceGroup, name)
Expand All @@ -755,14 +754,20 @@ func resourceArmCosmosDbAccountDelete(d *schema.ResourceData, meta interface{})
return resp, "Deleting", nil
},
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = d.Timeout(schema.TimeoutDelete)
} else {
stateConf.Timeout = 180 * time.Minute
}
if _, err = stateConf.WaitForState(); err != nil {
return fmt.Errorf("Waiting forCosmosDB Account %q to delete (Resource Group %q): %+v", name, resourceGroup, err)
}

return nil
}

func resourceArmCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClient, ctx context.Context, resourceGroup string, name string, account documentdb.DatabaseAccountCreateUpdateParameters) (*documentdb.DatabaseAccount, error) {
func resourceArmCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClient, ctx context.Context, resourceGroup string, name string, account documentdb.DatabaseAccountCreateUpdateParameters, d *schema.ResourceData) (*documentdb.DatabaseAccount, error) {
future, err := client.CreateOrUpdate(ctx, resourceGroup, name, account)
if err != nil {
return nil, fmt.Errorf("Error creating/updating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err)
Expand All @@ -776,7 +781,6 @@ func resourceArmCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClie
stateConf := &resource.StateChangeConf{
Pending: []string{"Creating", "Updating", "Deleting"},
Target: []string{"Succeeded"},
Timeout: 180 * time.Minute,
MinTimeout: 30 * time.Second,
Delay: 30 * time.Second, // required because it takes some time before the 'creating' location shows up
Refresh: func() (interface{}, string, error) {
Expand All @@ -796,6 +800,16 @@ func resourceArmCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClie
},
}

if features.SupportsCustomTimeouts() {
if d.IsNewResource() {
stateConf.Timeout = d.Timeout(schema.TimeoutCreate)
} else {
stateConf.Timeout = d.Timeout(schema.TimeoutUpdate)
}
} else {
stateConf.Timeout = 180 * time.Minute
}

resp, err := stateConf.WaitForState()
if err != nil {
return nil, fmt.Errorf("Error waiting for the CosmosDB Account %q (Resource Group %q) to provision: %+v", name, resourceGroup, err)
Expand Down
12 changes: 9 additions & 3 deletions azurerm/resource_arm_eventhub_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,24 @@ func resourceArmEventHubNamespaceDelete(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error issuing delete request of EventHub Namespace %q (Resource Group %q): %+v", name, resGroup, err)
}

return waitForEventHubNamespaceToBeDeleted(ctx, client, resGroup, name)
return waitForEventHubNamespaceToBeDeleted(ctx, client, resGroup, name, d)
}

func waitForEventHubNamespaceToBeDeleted(ctx context.Context, client *eventhub.NamespacesClient, resourceGroup, name string) error {
func waitForEventHubNamespaceToBeDeleted(ctx context.Context, client *eventhub.NamespacesClient, resourceGroup, name string, d *schema.ResourceData) error {
// we can't use the Waiter here since the API returns a 200 once it's deleted which is considered a polling status code..
log.Printf("[DEBUG] Waiting for EventHub Namespace (%q in Resource Group %q) to be deleted", name, resourceGroup)
stateConf := &resource.StateChangeConf{
Pending: []string{"200"},
Target: []string{"404"},
Refresh: eventHubNamespaceStateStatusCodeRefreshFunc(ctx, client, resourceGroup, name),
Timeout: 40 * time.Minute,
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = d.Timeout(schema.TimeoutDelete)
} else {
stateConf.Timeout = 40 * time.Minute
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for EventHub NameSpace (%q in Resource Group %q) to be deleted: %+v", name, resourceGroup, err)
}
Expand Down
38 changes: 27 additions & 11 deletions azurerm/resource_arm_eventhub_namespace_disaster_recovery_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigCreate(d *schema.Resource
return fmt.Errorf("Error creating/updating EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name, d.Timeout(schema.TimeoutCreate)); err != nil {
return fmt.Errorf("Error waiting for replication to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigUpdate(d *schema.Resource
return fmt.Errorf("Error issuing break pairing request for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name, d.Timeout(schema.TimeoutUpdate)); err != nil {
return fmt.Errorf("Error waiting for break pairing request to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}
}
Expand All @@ -164,7 +164,7 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigUpdate(d *schema.Resource
return fmt.Errorf("Error creating/updating EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name, d.Timeout(schema.TimeoutUpdate)); err != nil {
return fmt.Errorf("Error waiting for replication to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

Expand Down Expand Up @@ -228,7 +228,7 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigDelete(d *schema.Resource
return fmt.Errorf("Error breaking pairing for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name, d.Timeout(schema.TimeoutDelete)); err != nil {
return fmt.Errorf("Error waiting for break pairing request to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

Expand All @@ -240,7 +240,6 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigDelete(d *schema.Resource
deleteWait := &resource.StateChangeConf{
Pending: []string{"200"},
Target: []string{"404"},
Timeout: 30 * time.Minute,
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := client.Get(ctx, resourceGroup, namespaceName, name)
Expand All @@ -255,6 +254,13 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigDelete(d *schema.Resource
return resp, strconv.Itoa(resp.StatusCode), nil
},
}

if features.SupportsCustomTimeouts() {
deleteWait.Timeout = d.Timeout(schema.TimeoutDelete)
} else {
deleteWait.Timeout = 30 * time.Minute
}

if _, err := deleteWait.WaitForState(); err != nil {
return fmt.Errorf("Error waiting the deletion of EventHub Namespace Disaster Recovery Configs %q deletion (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}
Expand All @@ -264,7 +270,6 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigDelete(d *schema.Resource
nameFreeWait := &resource.StateChangeConf{
Pending: []string{"NameInUse"},
Target: []string{"None"},
Timeout: 30 * time.Minute,
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := client.CheckNameAvailability(ctx, resourceGroup, namespaceName, eventhub.CheckNameAvailabilityParameter{Name: utils.String(name)})
Expand All @@ -275,19 +280,24 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigDelete(d *schema.Resource
return resp, string(resp.Reason), nil
},
}

if features.SupportsCustomTimeouts() {
nameFreeWait.Timeout = d.Timeout(schema.TimeoutDelete)
} else {
nameFreeWait.Timeout = 30 * time.Minute
}

if _, err := nameFreeWait.WaitForState(); err != nil {
return fmt.Errorf("Error waiting the the EventHub Namespace Disaster Recovery Configs %q name to be available (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}

return nil
}

func resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx context.Context, client *eventhub.DisasterRecoveryConfigsClient, resourceGroup, namespaceName, name string) error {
func resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx context.Context, client *eventhub.DisasterRecoveryConfigsClient, resourceGroup, namespaceName, name string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{string(eventhub.Accepted)},
Target: []string{string(eventhub.Succeeded)},
// Delay: 15 * time.Second,
Timeout: 30 * time.Minute,
Pending: []string{string(eventhub.Accepted)},
Target: []string{string(eventhub.Succeeded)},
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
read, err := client.Get(ctx, resourceGroup, namespaceName, name)
Expand All @@ -306,6 +316,12 @@ func resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx context.
},
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = timeout
} else {
stateConf.Timeout = 30 * time.Minute
}

_, err := stateConf.WaitForState()
return err
}
12 changes: 9 additions & 3 deletions azurerm/resource_arm_iot_dps.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,24 @@ func resourceArmIotDPSDelete(d *schema.ResourceData, meta interface{}) error {
}
}

return waitForIotDPSToBeDeleted(ctx, client, resourceGroup, name)
return waitForIotDPSToBeDeleted(ctx, client, resourceGroup, name, d)
}

func waitForIotDPSToBeDeleted(ctx context.Context, client *iothub.IotDpsResourceClient, resourceGroup, name string) error {
func waitForIotDPSToBeDeleted(ctx context.Context, client *iothub.IotDpsResourceClient, resourceGroup, name string, d *schema.ResourceData) error {
// we can't use the Waiter here since the API returns a 404 once it's deleted which is considered a polling status code..
log.Printf("[DEBUG] Waiting for IoT Device Provisioning Service %q (Resource Group %q) to be deleted", name, resourceGroup)
stateConf := &resource.StateChangeConf{
Pending: []string{"200"},
Target: []string{"404"},
Refresh: iotdpsStateStatusCodeRefreshFunc(ctx, client, resourceGroup, name),
Timeout: 40 * time.Minute,
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = d.Timeout(schema.TimeoutDelete)
} else {
stateConf.Timeout = 40 * time.Minute
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for IoT Device Provisioning Service %q (Resource Group %q) to be deleted: %+v", name, resourceGroup, err)
}
Expand Down
12 changes: 9 additions & 3 deletions azurerm/resource_arm_iothub.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,18 +635,24 @@ func resourceArmIotHubDelete(d *schema.ResourceData, meta interface{}) error {
return err
}

return waitForIotHubToBeDeleted(ctx, client, resourceGroup, name)
return waitForIotHubToBeDeleted(ctx, client, resourceGroup, name, d)
}

func waitForIotHubToBeDeleted(ctx context.Context, client *devices.IotHubResourceClient, resourceGroup, name string) error {
func waitForIotHubToBeDeleted(ctx context.Context, client *devices.IotHubResourceClient, resourceGroup, name string, d *schema.ResourceData) error {
// we can't use the Waiter here since the API returns a 404 once it's deleted which is considered a polling status code..
log.Printf("[DEBUG] Waiting for IotHub (%q in Resource Group %q) to be deleted", name, resourceGroup)
stateConf := &resource.StateChangeConf{
Pending: []string{"200"},
Target: []string{"404"},
Refresh: iothubStateStatusCodeRefreshFunc(ctx, client, resourceGroup, name),
Timeout: 40 * time.Minute,
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = d.Timeout(schema.TimeoutDelete)
} else {
stateConf.Timeout = 40 * time.Minute
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for IotHub (%q in Resource Group %q) to be deleted: %+v", name, resourceGroup, err)
}
Expand Down
7 changes: 6 additions & 1 deletion azurerm/resource_arm_key_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,17 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e
Pending: []string{"pending"},
Target: []string{"available"},
Refresh: keyVaultRefreshFunc(*vault),
Timeout: 30 * time.Minute,
Delay: 30 * time.Second,
PollInterval: 10 * time.Second,
ContinuousTargetOccurence: 10,
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = d.Timeout(schema.TimeoutCreate)
} else {
stateConf.Timeout = 30 * time.Minute
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Key Vault %q (Resource Group %q) to become available: %s", name, resourceGroup, err)
}
Expand Down
11 changes: 8 additions & 3 deletions azurerm/resource_arm_key_vault_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ func resourceArmKeyVaultCertificate() *schema.Resource {
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Create: schema.DefaultTimeout(60 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},

Expand Down Expand Up @@ -421,9 +420,15 @@ func resourceArmKeyVaultCertificateCreate(d *schema.ResourceData, meta interface
Pending: []string{"Provisioning"},
Target: []string{"Ready"},
Refresh: keyVaultCertificateCreationRefreshFunc(ctx, client, keyVaultBaseUrl, name),
Timeout: 60 * time.Minute,
MinTimeout: 15 * time.Second,
}

if features.SupportsCustomTimeouts() {
stateConf.Timeout = d.Timeout(schema.TimeoutCreate)
} else {
stateConf.Timeout = 60 * time.Minute
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Certificate %q in Vault %q to become available: %s", name, keyVaultBaseUrl, err)
}
Expand Down
Loading