diff --git a/cli/azd/internal/repository/infra_gen.go b/cli/azd/internal/repository/infra_gen.go index 1d0f22e6e17..e7f0538dc77 100644 --- a/cli/azd/internal/repository/infra_gen.go +++ b/cli/azd/internal/repository/infra_gen.go @@ -770,7 +770,9 @@ confirmDetection: funcMap := template.FuncMap{ "bicepName": bicepName, + "containerAppName": containerAppName, "upper": strings.ToUpper, + "lower": strings.ToLower, } root := "scaffold/templates" @@ -870,6 +872,22 @@ func bicepName(name string) string { return sb.String() } +const resourceTokenLen = 13 + +// abbreviations.json: appContainerApps +const containerAppPrefixLen = 2 + +// containerAppName returns a name that is valid to be used as an infix for a container app resource. +func containerAppName(name string) string { + maxLen := resourceTokenLen + containerAppPrefixLen + 1 // 1 for the separator length + name = strings.ToLower(name) + if len(name) > maxLen { + name = name[:maxLen] + } + + return name +} + func copyFS(embedFs embed.FS, root string, target string) error { return fs.WalkDir(embedFs, root, func(name string, d fs.DirEntry, err error) error { if err != nil { diff --git a/cli/azd/resources/scaffold/templates/main.bicept b/cli/azd/resources/scaffold/templates/main.bicept index 4175001d227..002777d3928 100644 --- a/cli/azd/resources/scaffold/templates/main.bicept +++ b/cli/azd/resources/scaffold/templates/main.bicept @@ -125,10 +125,10 @@ module postgresDb './app/db-postgre.bicep' = { module {{bicepName .Name}} './app/{{.Name}}.bicep' = { name: '{{.Name}}' params: { - name: '${abbrs.appContainerApps}{{.Name}}-${resourceToken}' + name: '${abbrs.appContainerApps}{{containerAppName .Name}}-${resourceToken}' location: location tags: tags - identityName: '${abbrs.managedIdentityUserAssignedIdentities}{{.Name}}-${resourceToken}' + identityName: '${abbrs.managedIdentityUserAssignedIdentities}{{containerAppName .Name}}-${resourceToken}' applicationInsightsName: monitoring.outputs.applicationInsightsName containerAppsEnvironmentName: appsEnv.outputs.name containerRegistryName: registry.outputs.name @@ -152,7 +152,7 @@ module {{bicepName .Name}} './app/{{.Name}}.bicep' = { {{- if (and .Backend .Backend.Frontends)}} allowedOrigins: [ {{- range .Backend.Frontends}} - 'https://${abbrs.appContainerApps}{{.Name}}-${resourceToken}.${appsEnv.outputs.domain}' + 'https://${abbrs.appContainerApps}{{containerAppName .Name}}-${resourceToken}.${appsEnv.outputs.domain}' {{- end}} ] {{- end}}