forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpa_billing_scope.go
57 lines (46 loc) · 1.67 KB
/
mpa_billing_scope.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
package parse
import (
"fmt"
"strings"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/azure"
)
type MicrosoftPartnerAccountBillingScopeId struct {
BillingAccountName string
CustomerName string
}
func NewMPABillingScopeID(billingAccountName, customerName string) MicrosoftPartnerAccountBillingScopeId {
return MicrosoftPartnerAccountBillingScopeId{
BillingAccountName: billingAccountName,
CustomerName: customerName,
}
}
func (id MicrosoftPartnerAccountBillingScopeId) String() string {
segments := []string{
fmt.Sprintf("Customer Name %q", id.CustomerName),
fmt.Sprintf("Billing Account Name %q", id.BillingAccountName),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "M P A Billing Scope", segmentsStr)
}
func (id MicrosoftPartnerAccountBillingScopeId) ID() string {
fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/customers/%s"
return fmt.Sprintf(fmtString, id.BillingAccountName, id.CustomerName)
}
// MicrosoftPartnerAccountBillingScopeID parses a MPABillingScope ID into an MicrosoftPartnerAccountBillingScopeId struct
func MicrosoftPartnerAccountBillingScopeID(input string) (*MicrosoftPartnerAccountBillingScopeId, error) {
id, err := azure.ParseAzureResourceIDWithoutSubscription(input)
if err != nil {
return nil, err
}
resourceId := MicrosoftPartnerAccountBillingScopeId{}
if resourceId.BillingAccountName, err = id.PopSegment("billingAccounts"); err != nil {
return nil, err
}
if resourceId.CustomerName, err = id.PopSegment("customers"); err != nil {
return nil, err
}
if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}
return &resourceId, nil
}