From 65d2181e367e5d5085493f3085915c386a785aa3 Mon Sep 17 00:00:00 2001 From: tiwood Date: Tue, 17 Dec 2019 14:39:09 +0100 Subject: [PATCH 1/3] Added WaitForState() func to resource 'azurerm_log_profile' --- azurerm/resource_arm_monitor_log_profile.go | 29 ++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_monitor_log_profile.go b/azurerm/resource_arm_monitor_log_profile.go index 86204bb597fe..96126262a952 100644 --- a/azurerm/resource_arm_monitor_log_profile.go +++ b/azurerm/resource_arm_monitor_log_profile.go @@ -1,6 +1,7 @@ package azurerm import ( + "context" "fmt" "log" "strings" @@ -143,9 +144,18 @@ func resourceArmLogProfileCreateUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error Creating/Updating Log Profile %q: %+v", name, err) } - // Wait for Log Profile to become available - if err := resource.Retry(600*time.Second, retryLogProfilesClientGet(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: logProfilesCreateUpdateRefreshFunc(ctx, client, name), + Timeout: 5 * time.Minute, + 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) @@ -304,3 +314,16 @@ func parseLogProfileNameFromID(id string) (string, error) { return components[6], nil } + +func logProfilesCreateUpdateRefreshFunc(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 logProfilesCreateUpdateRefreshFunc for Log profile %q: %s", name, err) + } + return "Available", "Available", nil + } +} From da3a307abbb3d626a5f0438c7632cb615e02a724 Mon Sep 17 00:00:00 2001 From: tiwood Date: Tue, 17 Dec 2019 15:07:13 +0100 Subject: [PATCH 2/3] Renamed refresh func --- azurerm/resource_arm_monitor_log_profile.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_monitor_log_profile.go b/azurerm/resource_arm_monitor_log_profile.go index 5a8b1118987a..3c0459813cc0 100644 --- a/azurerm/resource_arm_monitor_log_profile.go +++ b/azurerm/resource_arm_monitor_log_profile.go @@ -157,7 +157,7 @@ func resourceArmLogProfileCreateUpdate(d *schema.ResourceData, meta interface{}) stateConf := &resource.StateChangeConf{ Pending: []string{"NotFound"}, Target: []string{"Available"}, - Refresh: logProfilesCreateUpdateRefreshFunc(ctx, client, name), + Refresh: logProfilesCreateRefreshFunc(ctx, client, name), Timeout: duration, MinTimeout: 15 * time.Second, ContinuousTargetOccurence: 5, @@ -321,14 +321,14 @@ func parseLogProfileNameFromID(id string) (string, error) { return components[6], nil } -func logProfilesCreateUpdateRefreshFunc(ctx context.Context, client *insights.LogProfilesClient, name string) resource.StateRefreshFunc { +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 logProfilesCreateUpdateRefreshFunc for Log profile %q: %s", name, err) + return nil, "", fmt.Errorf("Error issuing read request in logProfilesCreateRefreshFunc for Log profile %q: %s", name, err) } return "Available", "Available", nil } From cda38c817032a8df1e4a4e93614d19aaebe4885f Mon Sep 17 00:00:00 2001 From: tiwood Date: Tue, 17 Dec 2019 16:18:04 +0100 Subject: [PATCH 3/3] Removed unused func retryLogProfilesClientGet --- azurerm/resource_arm_monitor_log_profile.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/azurerm/resource_arm_monitor_log_profile.go b/azurerm/resource_arm_monitor_log_profile.go index 3c0459813cc0..c675ae3a211d 100644 --- a/azurerm/resource_arm_monitor_log_profile.go +++ b/azurerm/resource_arm_monitor_log_profile.go @@ -297,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, "/")