|
| 1 | +package autoscalevcores |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | + |
| 7 | + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" |
| 8 | +) |
| 9 | + |
| 10 | +var _ resourceids.ResourceId = AutoScaleVCoreId{} |
| 11 | + |
| 12 | +// AutoScaleVCoreId is a struct representing the Resource ID for a Auto Scale V Core |
| 13 | +type AutoScaleVCoreId struct { |
| 14 | + SubscriptionId string |
| 15 | + ResourceGroupName string |
| 16 | + VcoreName string |
| 17 | +} |
| 18 | + |
| 19 | +// NewAutoScaleVCoreID returns a new AutoScaleVCoreId struct |
| 20 | +func NewAutoScaleVCoreID(subscriptionId string, resourceGroupName string, vcoreName string) AutoScaleVCoreId { |
| 21 | + return AutoScaleVCoreId{ |
| 22 | + SubscriptionId: subscriptionId, |
| 23 | + ResourceGroupName: resourceGroupName, |
| 24 | + VcoreName: vcoreName, |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +// ParseAutoScaleVCoreID parses 'input' into a AutoScaleVCoreId |
| 29 | +func ParseAutoScaleVCoreID(input string) (*AutoScaleVCoreId, error) { |
| 30 | + parser := resourceids.NewParserFromResourceIdType(AutoScaleVCoreId{}) |
| 31 | + parsed, err := parser.Parse(input, false) |
| 32 | + if err != nil { |
| 33 | + return nil, fmt.Errorf("parsing %q: %+v", input, err) |
| 34 | + } |
| 35 | + |
| 36 | + var ok bool |
| 37 | + id := AutoScaleVCoreId{} |
| 38 | + |
| 39 | + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { |
| 40 | + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) |
| 41 | + } |
| 42 | + |
| 43 | + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { |
| 44 | + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) |
| 45 | + } |
| 46 | + |
| 47 | + if id.VcoreName, ok = parsed.Parsed["vcoreName"]; !ok { |
| 48 | + return nil, fmt.Errorf("the segment 'vcoreName' was not found in the resource id %q", input) |
| 49 | + } |
| 50 | + |
| 51 | + return &id, nil |
| 52 | +} |
| 53 | + |
| 54 | +// ParseAutoScaleVCoreIDInsensitively parses 'input' case-insensitively into a AutoScaleVCoreId |
| 55 | +// note: this method should only be used for API response data and not user input |
| 56 | +func ParseAutoScaleVCoreIDInsensitively(input string) (*AutoScaleVCoreId, error) { |
| 57 | + parser := resourceids.NewParserFromResourceIdType(AutoScaleVCoreId{}) |
| 58 | + parsed, err := parser.Parse(input, true) |
| 59 | + if err != nil { |
| 60 | + return nil, fmt.Errorf("parsing %q: %+v", input, err) |
| 61 | + } |
| 62 | + |
| 63 | + var ok bool |
| 64 | + id := AutoScaleVCoreId{} |
| 65 | + |
| 66 | + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { |
| 67 | + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) |
| 68 | + } |
| 69 | + |
| 70 | + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { |
| 71 | + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) |
| 72 | + } |
| 73 | + |
| 74 | + if id.VcoreName, ok = parsed.Parsed["vcoreName"]; !ok { |
| 75 | + return nil, fmt.Errorf("the segment 'vcoreName' was not found in the resource id %q", input) |
| 76 | + } |
| 77 | + |
| 78 | + return &id, nil |
| 79 | +} |
| 80 | + |
| 81 | +// ValidateAutoScaleVCoreID checks that 'input' can be parsed as a Auto Scale V Core ID |
| 82 | +func ValidateAutoScaleVCoreID(input interface{}, key string) (warnings []string, errors []error) { |
| 83 | + v, ok := input.(string) |
| 84 | + if !ok { |
| 85 | + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) |
| 86 | + return |
| 87 | + } |
| 88 | + |
| 89 | + if _, err := ParseAutoScaleVCoreID(v); err != nil { |
| 90 | + errors = append(errors, err) |
| 91 | + } |
| 92 | + |
| 93 | + return |
| 94 | +} |
| 95 | + |
| 96 | +// ID returns the formatted Auto Scale V Core ID |
| 97 | +func (id AutoScaleVCoreId) ID() string { |
| 98 | + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.PowerBIDedicated/autoScaleVCores/%s" |
| 99 | + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VcoreName) |
| 100 | +} |
| 101 | + |
| 102 | +// Segments returns a slice of Resource ID Segments which comprise this Auto Scale V Core ID |
| 103 | +func (id AutoScaleVCoreId) Segments() []resourceids.Segment { |
| 104 | + return []resourceids.Segment{ |
| 105 | + resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), |
| 106 | + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), |
| 107 | + resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"), |
| 108 | + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), |
| 109 | + resourceids.StaticSegment("providers", "providers", "providers"), |
| 110 | + resourceids.ResourceProviderSegment("microsoftPowerBIDedicated", "Microsoft.PowerBIDedicated", "Microsoft.PowerBIDedicated"), |
| 111 | + resourceids.StaticSegment("autoScaleVCores", "autoScaleVCores", "autoScaleVCores"), |
| 112 | + resourceids.UserSpecifiedSegment("vcoreName", "vcoreValue"), |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +// String returns a human-readable description of this Auto Scale V Core ID |
| 117 | +func (id AutoScaleVCoreId) String() string { |
| 118 | + components := []string{ |
| 119 | + fmt.Sprintf("Subscription: %q", id.SubscriptionId), |
| 120 | + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), |
| 121 | + fmt.Sprintf("Vcore Name: %q", id.VcoreName), |
| 122 | + } |
| 123 | + return fmt.Sprintf("Auto Scale V Core (%s)", strings.Join(components, "\n")) |
| 124 | +} |
0 commit comments