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

azurerm_express_route_circuit: fix acctest (actually a bug) #7753

Merged
merged 2 commits into from
Jul 16, 2020
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package network

import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"log"
"time"

Expand Down Expand Up @@ -220,6 +222,21 @@ func resourceArmExpressRouteCircuitCreateUpdate(d *schema.ResourceData, meta int
return fmt.Errorf("Error Creating/Updating ExpressRouteCircuit %q (Resource Group %q): %+v", name, resGroup, err)
}

// API has bug, which appears to be eventually consistent on creation. Tracked by this issue: https://github.com/Azure/azure-rest-api-specs/issues/10148
log.Printf("[DEBUG] Waiting for Express Route Circuit %q (Resource Group %q) to be able to be queried", name, resGroup)
stateConf := &resource.StateChangeConf{
Pending: []string{"NotFound"},
Target: []string{"Exists"},
Refresh: expressRouteCircuitCreationRefreshFunc(ctx, client, resGroup, name),
PollInterval: 3 * time.Second,
ContinuousTargetOccurence: 3,
Timeout: d.Timeout(schema.TimeoutCreate),
}

if _, err = stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error for Express Route Circuit %q (Resource Group %q) to be able to be queried: %+v", name, resGroup, err)
}

read, err := client.Get(ctx, resGroup, name)
if err != nil {
return fmt.Errorf("Error Retrieving ExpressRouteCircuit %q (Resource Group %q): %+v", name, resGroup, err)
Expand Down Expand Up @@ -329,3 +346,18 @@ func flattenExpressRouteCircuitSku(sku *network.ExpressRouteCircuitSku) []interf
},
}
}

func expressRouteCircuitCreationRefreshFunc(ctx context.Context, client *network.ExpressRouteCircuitsClient, resGroup, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.Get(ctx, resGroup, name)
if err != nil {
if utils.ResponseWasNotFound(res.Response) {
return nil, "NotFound", nil
}

return nil, "", fmt.Errorf("Error polling to check if the Express Route Circuit has been created: %+v", err)
}

return res, "Exists", nil
}
}