-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Victor Vazquez <[email protected]>
- Loading branch information
1 parent
d0937f9
commit 7b89277
Showing
11 changed files
with
302 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package infra | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"github.com/azure/azure-dev/cli/azd/pkg/environment" | ||
) | ||
|
||
// ResourceId returns the resource ID for the corresponding name. | ||
// | ||
// If the name is a resource ID string, it is immediately parsed without translation. | ||
func ResourceId(name string, env *environment.Environment) (resId *arm.ResourceID, err error) { | ||
resId, err = arm.ParseResourceID(name) | ||
if err == nil { | ||
return resId, nil | ||
} | ||
|
||
key := fmt.Sprintf("AZURE_RESOURCE_%s_ID", environment.Key(name)) | ||
resourceId, ok := env.LookupEnv(key) | ||
if !ok { | ||
return resId, fmt.Errorf("%s is not set as an output variable", key) | ||
} | ||
|
||
if resourceId == "" { | ||
return resId, fmt.Errorf("%s is empty", key) | ||
} | ||
|
||
resId, err = arm.ParseResourceID(resourceId) | ||
if err != nil { | ||
return resId, fmt.Errorf("parsing %s: %w", key, err) | ||
} | ||
|
||
return resId, nil | ||
} |
Oops, something went wrong.