diff --git a/cli/azd/pkg/azapi/azure_resource_types.go b/cli/azd/pkg/azapi/azure_resource_types.go index 61827354535..9e1476db0b3 100644 --- a/cli/azd/pkg/azapi/azure_resource_types.go +++ b/cli/azd/pkg/azapi/azure_resource_types.go @@ -50,8 +50,13 @@ const ( AzureResourceTypeRoleAssignment AzureResourceType = "Microsoft.Authorization/roleAssignments" //nolint:lll - AzureResourceTypeMachineLearningEndpoint AzureResourceType = "Microsoft.MachineLearningServices/workspaces/onlineEndpoints" + AzureResourceTypeMachineLearningEndpoint AzureResourceType = "Microsoft.MachineLearningServices/workspaces/onlineEndpoints" + //nolint:lll AzureResourceTypeCognitiveServiceAccountDeployment AzureResourceType = "Microsoft.CognitiveServices/accounts/deployments" + //nolint:lll + AzureResourceTypeCognitiveServiceAccountProject AzureResourceType = "Microsoft.CognitiveServices/accounts/projects" + //nolint:lll + AzureResourceTypeCognitiveServiceAccountCapabilityHost AzureResourceType = "Microsoft.CognitiveServices/accounts/capabilityHosts" ) // GetResourceTypeDisplayName retrieves the display name for the given resource type. @@ -123,6 +128,10 @@ func GetResourceTypeDisplayName(resourceType AzureResourceType) string { return "Azure AI Services" case AzureResourceTypeCognitiveServiceAccountDeployment: return "Azure AI Services Model Deployment" + case AzureResourceTypeCognitiveServiceAccountProject: + return "Foundry project" + case AzureResourceTypeCognitiveServiceAccountCapabilityHost: + return "Foundry capability host" case AzureResourceTypeSearchService: return "Search service" case AzureResourceTypeVideoIndexer: diff --git a/cli/azd/pkg/infra/azure_resource_manager.go b/cli/azd/pkg/infra/azure_resource_manager.go index 3887472a516..a3d6e5773fa 100644 --- a/cli/azd/pkg/infra/azure_resource_manager.go +++ b/cli/azd/pkg/infra/azure_resource_manager.go @@ -287,6 +287,10 @@ func (rm *AzureResourceManager) getCognitiveServiceResourceTypeDisplayName( return "Azure OpenAI", nil } else if strings.Contains(resource.Kind, "FormRecognizer") { return "Document Intelligence", nil + } else if strings.Contains(resource.Kind, "AIHub") { + return "Foundry", nil + } else if strings.Contains(resource.Kind, "AIServices") { + return "Foundry", nil } else { return "Azure AI Services", nil } diff --git a/cli/azd/pkg/infra/azure_resource_manager_test.go b/cli/azd/pkg/infra/azure_resource_manager_test.go index f3b3d6b1ce5..bf2a692b855 100644 --- a/cli/azd/pkg/infra/azure_resource_manager_test.go +++ b/cli/azd/pkg/infra/azure_resource_manager_test.go @@ -512,6 +512,130 @@ func TestFindResourceGroupForEnvironment(t *testing.T) { } } +func TestGetResourceTypeDisplayNameForCognitiveServices(t *testing.T) { + const SUBSCRIPTION_ID = "273f1e6b-6c19-4c9e-8b67-5fbe78b14063" + + tests := []struct { + name string + resourceId string + resourceType azapi.AzureResourceType + kind string + expectedName string + }{ + { + name: "Azure OpenAI", + resourceId: fmt.Sprintf( + "/subscriptions/%s/resourceGroups/test-rg/providers/Microsoft.CognitiveServices/accounts/test-openai", + SUBSCRIPTION_ID, + ), + resourceType: azapi.AzureResourceTypeCognitiveServiceAccount, + kind: "OpenAI", + expectedName: "Azure OpenAI", + }, + { + name: "Document Intelligence (FormRecognizer)", + resourceId: fmt.Sprintf( + "/subscriptions/%s/resourceGroups/test-rg/providers/"+ + "Microsoft.CognitiveServices/accounts/test-formrecognizer", + SUBSCRIPTION_ID, + ), + resourceType: azapi.AzureResourceTypeCognitiveServiceAccount, + kind: "FormRecognizer", + expectedName: "Document Intelligence", + }, + { + name: "Foundry (AIServices)", + resourceId: fmt.Sprintf( + "/subscriptions/%s/resourceGroups/test-rg/providers/Microsoft.CognitiveServices/accounts/test-foundry", + SUBSCRIPTION_ID, + ), + resourceType: azapi.AzureResourceTypeCognitiveServiceAccount, + kind: "AIServices", + expectedName: "Foundry", + }, + { + name: "Foundry (AIHub)", + resourceId: fmt.Sprintf( + "/subscriptions/%s/resourceGroups/test-rg/providers/Microsoft.CognitiveServices/accounts/test-aihub", + SUBSCRIPTION_ID, + ), + resourceType: azapi.AzureResourceTypeCognitiveServiceAccount, + kind: "AIHub", + expectedName: "Foundry", + }, + { + name: "Foundry project", + resourceId: fmt.Sprintf( + "/subscriptions/%s/resourceGroups/test-rg/providers/"+ + "Microsoft.CognitiveServices/accounts/test-foundry/projects/test-project", + SUBSCRIPTION_ID, + ), + resourceType: azapi.AzureResourceTypeCognitiveServiceAccountProject, + kind: "AIServices", + expectedName: "Foundry project", + }, + { + name: "Azure AI Services (CognitiveServices)", + resourceId: fmt.Sprintf( + "/subscriptions/%s/resourceGroups/test-rg/providers/Microsoft.CognitiveServices/accounts/test-cogservices", + SUBSCRIPTION_ID, + ), + resourceType: azapi.AzureResourceTypeCognitiveServiceAccount, + kind: "CognitiveServices", + expectedName: "Azure AI Services", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mockContext := mocks.NewMockContext(context.Background()) + resourceService := azapi.NewResourceService( + mockContext.SubscriptionCredentialProvider, + mockContext.ArmClientOptions, + ) + deploymentService := mockazapi.NewStandardDeploymentsFromMockContext(mockContext) + + mockContext.HttpClient.When(func(request *http.Request) bool { + return request.Method == http.MethodGet && + strings.Contains(request.URL.Path, "/Microsoft.CognitiveServices/accounts/") + }).RespondFn(func(request *http.Request) (*http.Response, error) { + response := map[string]interface{}{ + "id": tt.resourceId, + "name": "test-resource", + "type": "Microsoft.CognitiveServices/accounts", + "location": "eastus2", + "kind": tt.kind, + } + + body, err := json.Marshal(response) + if err != nil { + return nil, err + } + + return &http.Response{ + StatusCode: http.StatusOK, + Body: io.NopCloser(bytes.NewReader(body)), + Request: &http.Request{ + Method: http.MethodGet, + URL: request.URL, + }, + }, nil + }) + + arm := NewAzureResourceManager(resourceService, deploymentService) + displayName, err := arm.GetResourceTypeDisplayName( + *mockContext.Context, + SUBSCRIPTION_ID, + tt.resourceId, + tt.resourceType, + ) + + require.NoError(t, err) + require.Equal(t, tt.expectedName, displayName) + }) + } +} + func TestGetResourceTypeDisplayNameForRedisEnterprise(t *testing.T) { const SUBSCRIPTION_ID = "273f1e6b-6c19-4c9e-8b67-5fbe78b14063"