forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
id_subscription.go
75 lines (59 loc) · 1.84 KB
/
id_subscription.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
package webapplicationfirewallmanagedrulesets
import (
"fmt"
"strings"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)
type SubscriptionId struct {
SubscriptionId string
}
func NewSubscriptionID(subscriptionId string) SubscriptionId {
return SubscriptionId{
SubscriptionId: subscriptionId,
}
}
func (id SubscriptionId) String() string {
segments := []string{}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Subscription", segmentsStr)
}
func (id SubscriptionId) ID() string {
fmtString := "/subscriptions/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId)
}
// ParseSubscriptionID parses a Subscription ID into an SubscriptionId struct
func ParseSubscriptionID(input string) (*SubscriptionId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}
resourceId := SubscriptionId{
SubscriptionId: id.SubscriptionID,
}
if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}
if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}
return &resourceId, nil
}
// ParseSubscriptionIDInsensitively parses an Subscription ID into an SubscriptionId struct, insensitively
// This should only be used to parse an ID for rewriting to a consistent casing,
// the ParseSubscriptionID method should be used instead for validation etc.
func ParseSubscriptionIDInsensitively(input string) (*SubscriptionId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}
resourceId := SubscriptionId{
SubscriptionId: id.SubscriptionID,
}
if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}
if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}
return &resourceId, nil
}