-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
express_route_circuit.go
40 lines (31 loc) · 1.11 KB
/
express_route_circuit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package azurerm
import (
"fmt"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func extractResourceGroupAndErcName(resourceId string) (resourceGroup string, name string, err error) {
id, err := parseAzureResourceID(resourceId)
if err != nil {
return "", "", err
}
resourceGroup = id.ResourceGroup
name = id.Path["expressRouteCircuits"]
return
}
func retrieveErcByResourceId(resourceId string, meta interface{}) (erc *network.ExpressRouteCircuit, resourceGroup string, e error) {
ercClient := meta.(*ArmClient).expressRouteCircuitClient
ctx := meta.(*ArmClient).StopContext
resGroup, name, err := extractResourceGroupAndErcName(resourceId)
if err != nil {
return nil, "", fmt.Errorf("Error Parsing Azure Resource ID -: %+v", err)
}
resp, err := ercClient.Get(ctx, resGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return nil, "", nil
}
return nil, "", fmt.Errorf("Error making Read request on Express Route Circuit %s: %+v", name, err)
}
return &resp, resGroup, nil
}