Skip to content

Commit

Permalink
Handle upper-case names
Browse files Browse the repository at this point in the history
  • Loading branch information
weikanglim committed Aug 10, 2023
1 parent 28f8b88 commit c027c6d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions cli/azd/internal/repository/infra_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,9 @@ confirmDetection:

funcMap := template.FuncMap{
"bicepName": bicepName,
"containerAppName": containerAppName,
"upper": strings.ToUpper,
"lower": strings.ToLower,
}

root := "scaffold/templates"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cli/azd/resources/scaffold/templates/main.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}}
Expand Down

0 comments on commit c027c6d

Please sign in to comment.