Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/azd/internal/repository/detect_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (d *detectConfirm) remove(ctx context.Context) error {
confirm, err := d.console.Confirm(ctx, input.ConsoleOptions{
Message: fmt.Sprintf(
"Remove %s in %s?", projectDisplayName(svc), relSafe(d.root, svc.Path)),
DefaultValue: true,
})
if err != nil {
return err
Expand All @@ -280,6 +281,7 @@ func (d *detectConfirm) remove(ctx context.Context) error {
confirm, err := d.console.Confirm(ctx, input.ConsoleOptions{
Message: fmt.Sprintf(
"Remove %s?", db.Display()),
DefaultValue: true,
})
if err != nil {
return err
Expand Down
19 changes: 2 additions & 17 deletions cli/azd/internal/scaffold/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,9 @@ func lowerCase(r byte) byte {
return r
}

// Provide a reasonable limit for the container app infix to avoid name length issues
// This is calculated as follows:
// 1. Start with max initial length of 32 characters from the Container App name
// https://learn.microsoft.com/azure/azure-resource-manager/management/resource-name-rules#microsoftapp
// 2. Prefix abbreviation of 'ca-' from abbreviations.json (4 characters)
// 3. Bicep resource token (13 characters) + separator '-' (1 character) -- total of 14 characters
// 32 characters are allowed for the Container App name. See
// https://learn.microsoft.com/azure/azure-resource-manager/management/resource-name-rules#microsoftapp
//
// Which leaves us with: 32 - 4 - 14 = 14 characters.
const containerAppNameInfixMaxLen = 12

// We allow 2 additional characters for wiggle-room. We've seen failures when container app name is exactly at 32.
const containerAppNameMaxLen = 30

Expand Down Expand Up @@ -173,14 +166,6 @@ func EnvFormat(src string) string {
return fmt.Sprintf("${AZURE_%s}", snake)
}

// ContainerAppInfix returns a suitable infix for a container app resource.
//
// The name is treated to only contain alphanumeric and dash characters, with no repeated dashes, and no dashes
// as the first or last character.
func ContainerAppInfix(name string) string {
return containerAppName(name, containerAppNameInfixMaxLen)
}

// Formats a parameter value for use in a bicep file.
// If the value is a string, it is quoted inline with no indentation.
// Otherwise, the value is marshaled with indentation specified by prefix and indent.
Expand Down
10 changes: 5 additions & 5 deletions cli/azd/internal/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func copyFS(embedFs fs.FS, root string, target string) error {
// To execute a named template, call Execute with the defined name.
func Load() (*template.Template, error) {
funcMap := template.FuncMap{
"bicepName": BicepName,
"containerAppInfix": ContainerAppInfix,
"upper": strings.ToUpper,
"lower": strings.ToLower,
"formatParam": FormatParameter,
"bicepName": BicepName,
"containerAppName": ContainerAppName,
"upper": strings.ToUpper,
"lower": strings.ToLower,
"formatParam": FormatParameter,
}

t, err := template.New("templates").
Expand Down
8 changes: 4 additions & 4 deletions cli/azd/resources/scaffold/templates/main.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ module postgresDb './app/db-postgres.bicep' = {
module {{bicepName .Name}} './app/{{.Name}}.bicep' = {
name: '{{.Name}}'
params: {
name: '${abbrs.appContainerApps}{{containerAppInfix .Name}}-${resourceToken}'
name: '{{containerAppName .Name}}'
location: location
tags: tags
identityName: '${abbrs.managedIdentityUserAssignedIdentities}{{containerAppInfix .Name}}-${resourceToken}'
identityName: '${abbrs.managedIdentityUserAssignedIdentities}{{.Name}}-${resourceToken}'
applicationInsightsName: monitoring.outputs.applicationInsightsName
containerAppsEnvironmentName: appsEnv.outputs.name
containerRegistryName: registry.outputs.name
exists: {{bicepName .Name}}Exists
appDefinition: {{bicepName .Name}}Definition
{{- if .DbRedis}}
redisName: 'rd-{{containerAppInfix .Name}}-${resourceToken}'
redisName: 'rd-{{containerAppName .Name}}'
{{- end}}
{{- if .DbCosmosMongo}}
cosmosDbConnectionString: vault.getSecret(cosmosDb.outputs.connectionStringKey)
Expand All @@ -162,7 +162,7 @@ module {{bicepName .Name}} './app/{{.Name}}.bicep' = {
{{- if (and .Backend .Backend.Frontends)}}
allowedOrigins: [
{{- range .Backend.Frontends}}
'https://${abbrs.appContainerApps}{{containerAppInfix .Name}}-${resourceToken}.${appsEnv.outputs.domain}'
'https://{{containerAppName .Name}}.${appsEnv.outputs.domain}'
{{- end}}
]
{{- end}}
Expand Down