Skip to content

Commit e99f6ad

Browse files
committed
WIP
1 parent 45c7fdb commit e99f6ad

File tree

9 files changed

+169
-160
lines changed

9 files changed

+169
-160
lines changed

cli/azd/internal/scaffold/funcs.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"regexp"
1111
"strings"
1212

13-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
13+
"github.com/tidwall/gjson"
1414
)
1515

1616
// BicepName returns a name suitable for use as a bicep variable name.
@@ -263,27 +263,18 @@ func hostFromEndpoint(endpoint string) (string, error) {
263263
return urlEndpoint.Hostname(), nil
264264
}
265265

266-
func aiProjectConnectionString(resourceId string, projectUrl string) (string, error) {
267-
hostName, err := hostFromEndpoint(projectUrl)
268-
if err != nil {
269-
return "", fmt.Errorf("failed to parse project URL: %w", err)
266+
func aiProjectEndpoint(endpoints string) (string, error) {
267+
result := gjson.Parse(endpoints)
268+
if !result.Exists() {
269+
return "", fmt.Errorf("invalid endpoints JSON: %s", endpoints)
270270
}
271271

272-
resId, err := arm.ParseResourceID(resourceId)
273-
if err != nil {
274-
return "", nil
272+
endpoint := result.Get("AI Foundry API")
273+
if !endpoint.Exists() {
274+
return "", fmt.Errorf("endpoint 'AI Foundry API' not found in endpoints")
275275
}
276276

277-
return fmt.Sprintf("%s;%s;%s;%s", hostName, resId.SubscriptionID, resId.ResourceGroupName, resId.Name), nil
278-
}
279-
280-
func emitAiProjectConnectionString(resourceIdVar string, projectUrlVar string) (string, error) {
281-
return fmt.Sprintf(
282-
"${split(%s, '/')[2]};${split(%s, '/')[2]};${split(%s, '/')[4]};${split(%s, '/')[8]}",
283-
projectUrlVar,
284-
resourceIdVar,
285-
resourceIdVar,
286-
resourceIdVar), nil
277+
return endpoint.String(), nil
287278
}
288279

289280
func emitHostFromEndpoint(endpointVar string) (string, error) {

cli/azd/internal/scaffold/resource_expr_eval.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ type FuncMap map[string]any
4242
// The functions are evaluated at runtime against live Azure resources.
4343
func BaseEvalFuncMap() FuncMap {
4444
return FuncMap{
45-
"lower": strings.ToLower,
46-
"upper": strings.ToUpper,
47-
"replace": strings.ReplaceAll,
48-
"host": hostFromEndpoint,
49-
"aiProjectConnectionString": aiProjectConnectionString,
45+
"lower": strings.ToLower,
46+
"upper": strings.ToUpper,
47+
"replace": strings.ReplaceAll,
48+
"host": hostFromEndpoint,
49+
"aiProjectEndpoint": aiProjectEndpoint,
5050
}
5151
}
5252

@@ -57,11 +57,10 @@ func BaseEvalFuncMap() FuncMap {
5757
// The functions are not evaluated at runtime, but rather emitted as part of the Bicep template.
5858
func BaseEmitBicepFuncMap() FuncMap {
5959
return FuncMap{
60-
"lower": bicepFuncCall("toLower"),
61-
"upper": bicepFuncCall("toUpper"),
62-
"replace": bicepFuncCallThree("replace"),
63-
"host": emitHostFromEndpoint,
64-
"aiProjectConnectionString": emitAiProjectConnectionString,
60+
"lower": bicepFuncCall("toLower"),
61+
"upper": bicepFuncCall("toUpper"),
62+
"replace": bicepFuncCallThree("replace"),
63+
"host": emitHostFromEndpoint,
6564
}
6665
}
6766

cli/azd/internal/scaffold/resource_meta.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,36 @@ var Resources = []ResourceMeta{
9191
},
9292
{
9393
ResourceType: "Microsoft.CognitiveServices/accounts",
94-
ApiVersion: "2023-05-01",
94+
ApiVersion: "2025-04-01-preview",
9595
},
9696
{
9797
ResourceType: "Microsoft.CognitiveServices/accounts/deployments",
98-
ApiVersion: "2023-05-01",
98+
ApiVersion: "2025-04-01-preview",
9999
ParentForEval: "Microsoft.CognitiveServices/accounts",
100100
StandardVarPrefix: "AZURE_OPENAI",
101101
Variables: map[string]string{
102102
"endpoint": "${.properties.endpoint}",
103103
},
104104
},
105+
{
106+
ResourceType: "Microsoft.CognitiveServices/accounts/projects",
107+
ResourceKind: "AIServices",
108+
ApiVersion: "2025-04-01-preview",
109+
StandardVarPrefix: "AZURE_AI_PROJECT",
110+
Variables: map[string]string{
111+
"endpoint": "${aiProjectEndpoint .properties.endpoints}",
112+
},
113+
RoleAssignments: RoleAssignments{
114+
Write: []RoleAssignment{
115+
{
116+
Name: "CognitiveServicesUser",
117+
RoleDefinitionName: "Cognitive Services User",
118+
RoleDefinitionId: "a97b65f3-24c7-4388-baec-2e87135dc908",
119+
Scope: RoleAssignmentScopeGroup,
120+
},
121+
},
122+
},
123+
},
105124
{
106125
ResourceType: "Microsoft.ContainerRegistry/registries",
107126
ApiVersion: "2023-06-01-preview",
@@ -233,31 +252,11 @@ var Resources = []ResourceMeta{
233252
},
234253
},
235254
{
236-
ResourceType: "Microsoft.MachineLearningServices/workspaces",
237-
ResourceKind: "Project",
238-
ApiVersion: "2024-10-01",
239-
StandardVarPrefix: "AZURE_AI_PROJECT",
240-
Variables: map[string]string{
241-
"connectionString": "${aiProjectConnectionString .id .properties.discoveryUrl}",
242-
},
243-
RoleAssignments: RoleAssignments{
244-
Write: []RoleAssignment{
245-
{
246-
Name: "AIDeveloper",
247-
RoleDefinitionName: "Azure AI Developer",
248-
RoleDefinitionId: "64702f94-c441-49e6-a78b-ef80e0188fee",
249-
Scope: RoleAssignmentScopeGroup,
250-
},
251-
},
252-
},
253-
},
254-
{
255-
ResourceType: "Microsoft.Search/searchServices",
256-
// TODO: Switch to 2025-02-01-preview once available, which has a new 'endpoint' property
257-
ApiVersion: "2024-06-01-preview",
255+
ResourceType: "Microsoft.Search/searchServices",
256+
ApiVersion: "2025-02-01-preview",
258257
StandardVarPrefix: "AZURE_AI_SEARCH",
259258
Variables: map[string]string{
260-
"endpoint": "https://${.name}.search.windows.net",
259+
"endpoint": "${.properties.endpoint}",
261260
},
262261
RoleAssignments: RoleAssignments{
263262
Write: []RoleAssignment{

cli/azd/pkg/azapi/azure_resource_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
AzureResourceTypeDevCenterProject AzureResourceType = "Microsoft.DevCenter/projects"
4444
AzureResourceTypeMachineLearningWorkspace AzureResourceType = "Microsoft.MachineLearningServices/workspaces"
4545
AzureResourceTypeMachineLearningConnection AzureResourceType = "Microsoft.MachineLearningServices/workspaces/connections"
46+
AzureResourceTypeRoleAssignment AzureResourceType = "Microsoft.Authorization/roleAssignments"
4647

4748
//nolint:lll
4849
AzureResourceTypeMachineLearningEndpoint AzureResourceType = "Microsoft.MachineLearningServices/workspaces/onlineEndpoints"
@@ -130,6 +131,8 @@ func GetResourceTypeDisplayName(resourceType AzureResourceType) string {
130131
return "Machine Learning Endpoint"
131132
case AzureResourceTypeMachineLearningConnection:
132133
return "Machine Learning Connection"
134+
case AzureResourceTypeRoleAssignment:
135+
return "Role Assignment"
133136
}
134137

135138
return ""

cli/azd/resources/scaffold/base/abbreviations.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"cacheRedis": "redis-",
1212
"cdnProfiles": "cdnp-",
1313
"cdnProfilesEndpoints": "cdne-",
14-
"cognitiveServicesAccounts": "cog-",
15-
"cognitiveServicesFormRecognizer": "cog-fr-",
16-
"cognitiveServicesTextAnalytics": "cog-ta-",
14+
"cognitiveServicesAIServices": "ais-",
15+
"cognitiveServicesFormRecognizer": "di-",
16+
"cognitiveServicesTextAnalytics": "lang-",
1717
"computeAvailabilitySets": "avail-",
1818
"computeCloudServices": "cld-",
1919
"computeDiskEncryptionSets": "des",

cli/azd/resources/scaffold/base/modules/ai-search-conn.bicep

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
@description('The name of the AI Hub')
2-
param aiHubName string
1+
@description('The name of the main AI Services')
2+
param aiServicesName string
3+
4+
@description('The name of the AI Services project')
5+
param aiServicesProjectName string
36

47
@description('The name of the AI Search')
58
param aiSearchName string
69

7-
resource search 'Microsoft.Search/searchServices@2024-06-01-preview' existing = {
10+
resource search 'Microsoft.Search/searchServices@2025-02-01-preview' existing = {
811
name: aiSearchName
912
}
1013

11-
resource hub 'Microsoft.MachineLearningServices/workspaces@2024-10-01' existing = {
12-
name: aiHubName
14+
resource aiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = {
15+
name: aiServicesName
1316

14-
resource AzureAISearch 'connections@2024-10-01' = {
15-
name: 'AzureAISearch-connection'
16-
properties: {
17-
category: 'CognitiveSearch'
18-
target: 'https://${search.name}.search.windows.net'
19-
authType: 'ApiKey'
20-
isSharedToAll: true
21-
credentials: {
22-
key: search.listAdminKeys().primaryKey
23-
}
24-
metadata: {
25-
ApiType: 'Azure'
26-
ResourceId: search.id
17+
resource project 'projects' existing = {
18+
name: aiServicesProjectName
19+
20+
resource AzureAISearch 'connections' = {
21+
name: 'AzureAISearch-connection'
22+
properties: {
23+
category: 'CognitiveSearch'
24+
target: search.properties.endpoint
25+
authType: 'AAD'
26+
isSharedToAll: true
27+
metadata: {
28+
ApiType: 'Azure'
29+
ResourceId: search.id
30+
location: search.location
31+
}
2732
}
2833
}
2934
}

0 commit comments

Comments
 (0)