Skip to content

Commit

Permalink
Merge pull request #5194 from tiwood/log-profile-retry
Browse files Browse the repository at this point in the history
azurerm_log_profile wait for stable state
  • Loading branch information
tombuildsstuff authored Dec 17, 2019
2 parents ffe060a + cda38c8 commit fb52a09
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions azurerm/resource_arm_monitor_log_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,19 @@ func resourceArmLogProfileCreateUpdate(d *schema.ResourceData, meta interface{})
duration = d.Timeout(schema.TimeoutUpdate)
}
}
// Wait for Log Profile to become available
if err := resource.Retry(duration, retryLogProfilesClientGet(ctx, client, name, meta)); err != nil {
return fmt.Errorf("Error waiting for Log Profile %q to become available: %+v", name, err)

log.Printf("[DEBUG] Waiting for Log Profile %q to be provisioned", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"NotFound"},
Target: []string{"Available"},
Refresh: logProfilesCreateRefreshFunc(ctx, client, name),
Timeout: duration,
MinTimeout: 15 * time.Second,
ContinuousTargetOccurence: 5,
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Log Profile %q to become available: %s", name, err)
}

read, err := client.Get(ctx, name)
Expand Down Expand Up @@ -287,16 +297,6 @@ func flattenAzureRmLogProfileRetentionPolicy(input *insights.RetentionPolicy) []
return []interface{}{result}
}

func retryLogProfilesClientGet(ctx context.Context, client *insights.LogProfilesClient, name string, meta interface{}) func() *resource.RetryError {
return func() *resource.RetryError {
if _, err := client.Get(ctx, name); err != nil {
return resource.RetryableError(err)
}

return nil
}
}

func parseLogProfileNameFromID(id string) (string, error) {
components := strings.Split(id, "/")

Expand All @@ -310,3 +310,16 @@ func parseLogProfileNameFromID(id string) (string, error) {

return components[6], nil
}

func logProfilesCreateRefreshFunc(ctx context.Context, client *insights.LogProfilesClient, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
logProfile, err := client.Get(ctx, name)
if err != nil {
if utils.ResponseWasNotFound(logProfile.Response) {
return nil, "NotFound", nil
}
return nil, "", fmt.Errorf("Error issuing read request in logProfilesCreateRefreshFunc for Log profile %q: %s", name, err)
}
return "Available", "Available", nil
}
}

0 comments on commit fb52a09

Please sign in to comment.