forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mca_billing_scope.go
63 lines (52 loc) · 2.02 KB
/
mca_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
58
59
60
61
62
63
package parse
import (
"fmt"
"strings"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/azure"
)
type MicrosoftCustomerAccountBillingScopeId struct {
BillingAccountName string
BillingProfileName string
InvoiceSectionName string
}
func NewMCABillingScopeID(billingAccountName, billingProfileName, invoiceSectionName string) MicrosoftCustomerAccountBillingScopeId {
return MicrosoftCustomerAccountBillingScopeId{
BillingAccountName: billingAccountName,
BillingProfileName: billingProfileName,
InvoiceSectionName: invoiceSectionName,
}
}
func (id MicrosoftCustomerAccountBillingScopeId) String() string {
segments := []string{
fmt.Sprintf("Invoice Section Name %q", id.InvoiceSectionName),
fmt.Sprintf("Billing Profile Name %q", id.BillingProfileName),
fmt.Sprintf("Billing Account Name %q", id.BillingAccountName),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "M C A Billing Scope", segmentsStr)
}
func (id MicrosoftCustomerAccountBillingScopeId) ID() string {
fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/billingProfiles/%s/invoiceSections/%s"
return fmt.Sprintf(fmtString, id.BillingAccountName, id.BillingProfileName, id.InvoiceSectionName)
}
// MicrosoftCustomerAccountBillingScopeID parses a MCABillingScope ID into an MicrosoftCustomerAccountBillingScopeId struct
func MicrosoftCustomerAccountBillingScopeID(input string) (*MicrosoftCustomerAccountBillingScopeId, error) {
id, err := azure.ParseAzureResourceIDWithoutSubscription(input)
if err != nil {
return nil, err
}
resourceId := MicrosoftCustomerAccountBillingScopeId{}
if resourceId.BillingAccountName, err = id.PopSegment("billingAccounts"); err != nil {
return nil, err
}
if resourceId.BillingProfileName, err = id.PopSegment("billingProfiles"); err != nil {
return nil, err
}
if resourceId.InvoiceSectionName, err = id.PopSegment("invoiceSections"); err != nil {
return nil, err
}
if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}
return &resourceId, nil
}