Skip to content

Commit

Permalink
Merge pull request #7753 from magodo/testfix_express_circuit_route
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored Jul 16, 2020
2 parents a92df50 + 4918290 commit 1ca7b47
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package network

import (
"context"
"fmt"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -220,6 +223,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 +347,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
}
}

0 comments on commit 1ca7b47

Please sign in to comment.