forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
id_firewallrule.go
126 lines (105 loc) · 3.33 KB
/
id_firewallrule.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package firewallrules
import (
"fmt"
"strings"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)
type FirewallRuleId struct {
SubscriptionId string
ResourceGroup string
AccountName string
Name string
}
func NewFirewallRuleID(subscriptionId, resourceGroup, accountName, name string) FirewallRuleId {
return FirewallRuleId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
AccountName: accountName,
Name: name,
}
}
func (id FirewallRuleId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Account Name %q", id.AccountName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Firewall Rule", segmentsStr)
}
func (id FirewallRuleId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataLakeAnalytics/accounts/%s/firewallRules/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.AccountName, id.Name)
}
// ParseFirewallRuleID parses a FirewallRule ID into an FirewallRuleId struct
func ParseFirewallRuleID(input string) (*FirewallRuleId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}
resourceId := FirewallRuleId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}
if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}
if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}
if resourceId.AccountName, err = id.PopSegment("accounts"); err != nil {
return nil, err
}
if resourceId.Name, err = id.PopSegment("firewallRules"); err != nil {
return nil, err
}
if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}
return &resourceId, nil
}
// ParseFirewallRuleIDInsensitively parses an FirewallRule ID into an FirewallRuleId struct, insensitively
// This should only be used to parse an ID for rewriting to a consistent casing,
// the ParseFirewallRuleID method should be used instead for validation etc.
func ParseFirewallRuleIDInsensitively(input string) (*FirewallRuleId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}
resourceId := FirewallRuleId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}
if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}
if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}
// find the correct casing for the 'accounts' segment
accountsKey := "accounts"
for key := range id.Path {
if strings.EqualFold(key, accountsKey) {
accountsKey = key
break
}
}
if resourceId.AccountName, err = id.PopSegment(accountsKey); err != nil {
return nil, err
}
// find the correct casing for the 'firewallRules' segment
firewallRulesKey := "firewallRules"
for key := range id.Path {
if strings.EqualFold(key, firewallRulesKey) {
firewallRulesKey = key
break
}
}
if resourceId.Name, err = id.PopSegment(firewallRulesKey); err != nil {
return nil, err
}
if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}
return &resourceId, nil
}