-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log progress of resources created during
azd provision
(#152)
Azure resources created are logged to standard output (in interactive mode).
- Loading branch information
1 parent
bad5ed4
commit c8cdad1
Showing
10 changed files
with
427 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ pyapp | |
keychain | ||
restoreapp | ||
rzip | ||
serverfarms | ||
sstore | ||
staticwebapp | ||
structs | ||
|
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 |
---|---|---|
@@ -1,14 +1,76 @@ | ||
package infra | ||
|
||
import "strings" | ||
|
||
type AzureResourceType string | ||
|
||
const ( | ||
AzureResourceTypeResourceGroup AzureResourceType = "Microsoft.Resources/resourceGroups" | ||
AzureResourceTypeDeployment AzureResourceType = "Microsoft.Resources/deployments" | ||
AzureResourceTypeStorageAccount AzureResourceType = "Microsoft.Storage/storageAccounts" | ||
AzureResourceTypeKeyVault AzureResourceType = "Microsoft.KeyVault/vaults" | ||
AzureResourceTypePortalDashboard AzureResourceType = "Microsoft.Portal/dashboards" | ||
AzureResourceTypeAppInsightComponent AzureResourceType = "Microsoft.Insights/components" | ||
AzureResourceTypeWebSite AzureResourceType = "Microsoft.Web/sites" | ||
AzureResourceTypeContainerApp AzureResourceType = "Microsoft.App/containerApps" | ||
AzureResourceTypeResourceGroup AzureResourceType = "Microsoft.Resources/resourceGroups" | ||
AzureResourceTypeDeployment AzureResourceType = "Microsoft.Resources/deployments" | ||
AzureResourceTypeStorageAccount AzureResourceType = "Microsoft.Storage/storageAccounts" | ||
AzureResourceTypeKeyVault AzureResourceType = "Microsoft.KeyVault/vaults" | ||
AzureResourceTypePortalDashboard AzureResourceType = "Microsoft.Portal/dashboards" | ||
AzureResourceTypeAppInsightComponent AzureResourceType = "Microsoft.Insights/components" | ||
AzureResourceTypeLogAnalyticsWorkspace AzureResourceType = "Microsoft.OperationalInsights/workspaces" | ||
AzureResourceTypeWebSite AzureResourceType = "Microsoft.Web/sites" | ||
AzureResourceTypeStaticWebSite AzureResourceType = "Microsoft.Web/staticSites" | ||
AzureResourceTypeServicePlan AzureResourceType = "Microsoft.Web/serverfarms" | ||
AzureResourceTypeSqlDatabase AzureResourceType = "Microsoft.Sql/servers" | ||
AzureResourceTypeCosmosDb AzureResourceType = "Microsoft.DocumentDB/databaseAccounts" | ||
AzureResourceTypeContainerApp AzureResourceType = "Microsoft.App/containerApps" | ||
AzureResourceTypeContainerAppEnvironment AzureResourceType = "Microsoft.App/managedEnvironments" | ||
) | ||
|
||
const resourceLevelSeparator = "/" | ||
|
||
// GetResourceTypeDisplayName retrieves the display name for the given resource type. | ||
// If the display name was not found for the given resource type, an empty string is returned instead. | ||
func GetResourceTypeDisplayName(resourceType AzureResourceType) string { | ||
// Azure Resource Manager does not offer an API for obtaining display name for resource types. | ||
// Display names for Azure resource types in Azure Portal are encoded in UX definition files instead. | ||
// As a result, we provide static translations for known resources below. These are obtained from the Azure Portal. | ||
switch resourceType { | ||
case AzureResourceTypeResourceGroup: | ||
return "Resource group" | ||
case AzureResourceTypeStorageAccount: | ||
return "Storage account" | ||
case AzureResourceTypeKeyVault: | ||
return "Key vault" | ||
case AzureResourceTypePortalDashboard: | ||
return "Portal dashboard" | ||
case AzureResourceTypeAppInsightComponent: | ||
return "Application Insights" | ||
case AzureResourceTypeLogAnalyticsWorkspace: | ||
return "Log Analytics workspace" | ||
case AzureResourceTypeWebSite: | ||
return "Web App" | ||
case AzureResourceTypeStaticWebSite: | ||
return "Static Web App" | ||
case AzureResourceTypeContainerApp: | ||
return "Container App" | ||
case AzureResourceTypeContainerAppEnvironment: | ||
return "Container Apps Environment" | ||
case AzureResourceTypeServicePlan: | ||
return "App Service plan" | ||
case AzureResourceTypeCosmosDb: | ||
return "Azure Cosmos DB" | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// IsTopLevelResourceType returns true if the resource type is a top-level resource type, otherwise false. | ||
// A top-level resource type is of the format of: {ResourceProvider}/{TopLevelResourceType}, i.e. Microsoft.DocumentDB/databaseAccounts | ||
func IsTopLevelResourceType(resourceType AzureResourceType) bool { | ||
resType := string(resourceType) | ||
firstIndex := strings.Index(resType, resourceLevelSeparator) | ||
|
||
if firstIndex == -1 || | ||
firstIndex == 0 || | ||
firstIndex == len(resType)-1 { | ||
return false | ||
} | ||
|
||
// Should not contain second separator | ||
return !strings.Contains(resType[firstIndex+1:], resourceLevelSeparator) | ||
} |
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,33 @@ | ||
package infra | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsTopLevelResourceType(t *testing.T) { | ||
var tests = []struct { | ||
resourceType string | ||
result bool | ||
}{ | ||
{"", false}, | ||
{"/", false}, | ||
{"/foo", false}, | ||
{"foo", false}, | ||
{"foo/", false}, | ||
{"foo/b", true}, | ||
{"foo/bar", true}, | ||
{"foo/bar/baz", false}, | ||
{"foo/bar/", false}, | ||
{"Microsoft.Storage/storageAccounts", true}, | ||
{"Microsoft.DocumentDB/databaseAccounts/collections", false}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(fmt.Sprintf("\"%s\")", test.resourceType), func(t *testing.T) { | ||
assert.Equal(t, test.result, IsTopLevelResourceType(AzureResourceType(test.resourceType))) | ||
}) | ||
} | ||
} |
Oops, something went wrong.