Skip to content

Commit

Permalink
add logic app ID for differentiation in app service
Browse files Browse the repository at this point in the history
  • Loading branch information
stephybun committed Sep 5, 2024
1 parent cc1362e commit 1e6aee7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions resourcemanager/commonids/app_service_logic_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package commonids

import "fmt"

// NOTE: A Logic App is just an App Service instance - but to allow for potential differentiation in the future
// we're wrapping this to provide a unique Type, Parse and Validation functions.

type LogicAppId = AppServiceId

// ParseLogicAppId parses 'input' into a LogicAppId
func ParseLogicAppId(input string) (*LogicAppId, error) {
parsed, err := ParseAppServiceID(input)
if err != nil {
return nil, fmt.Errorf("parsing %q as a Logic App ID: %+v", input, err)
}

return &LogicAppId{
SubscriptionId: parsed.SubscriptionId,
ResourceGroupName: parsed.ResourceGroupName,
SiteName: parsed.SiteName,
}, nil
}

// ParseLogicAppIdInsensitively parses 'input' case-insensitively into a LogicAppId
// note: this method should only be used for API response data and not user input
func ParseLogicAppIdInsensitively(input string) (*LogicAppId, error) {
parsed, err := ParseAppServiceIDInsensitively(input)
if err != nil {
return nil, fmt.Errorf("parsing %q as a Logic App ID: %+v", input, err)
}

return &LogicAppId{
SubscriptionId: parsed.SubscriptionId,
ResourceGroupName: parsed.ResourceGroupName,
SiteName: parsed.SiteName,
}, nil
}

// ValidateLogicAppId checks that 'input' can be parsed as a Logic App ID
func ValidateLogicAppId(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}

if _, err := ParseLogicAppId(v); err != nil {
errors = append(errors, err)
}

return
}

0 comments on commit 1e6aee7

Please sign in to comment.