Skip to content
DevOps AI ToolKit
Newsletter
All guides
AI for Infrastructure as Code By James Joyner IV · · 8 min read

Bicep Error: 'BCP057: The name "location" does not exist in the current context' — Cause, Fix, and Troubleshooting Guide

Quick answer

Fix Bicep 'Error BCP057: The name "location" does not exist in the current context' by declaring the missing param, var, or symbol or fixing scope.

  • #iac
  • #infrastructure-as-code
  • #bicep
  • #troubleshooting
Free toolkit

Fixing errors like this? Get 500 free DevOps AI prompts

500 copy-paste AI prompts for the stack you actually run — one PDF, free.

Overview

BCP057 is a compile-time error meaning you referenced a symbol — a param, var, resource, module, or built-in name — that Bicep cannot find in the scope where you used it. The build stops before producing any ARM JSON, so nothing reaches Azure. It is the Bicep equivalent of an “undefined variable” error in a programming language.

The error reads:

main.bicep(24,15) : Error BCP057: The name "location" does not exist in the current context. [https://aka.ms/bicep/core-diagnostics#BCP057]

The coordinate (24,15) points at the reference, not the (missing) declaration. Most of the time the fix is trivial — you forgot to declare the parameter, you mistyped its name, or you deleted a declaration but left a reference behind. The interesting cases involve scope: a symbol declared inside a loop, module, or lambda is not visible outside it, and referencing it there produces the same BCP057.

Symptoms

  • az bicep build fails with Error BCP057 and a line/column pointing at a reference.
  • A name you “know is there” is reported as not existing — often a subtle typo or casing difference.
  • The error appeared after you renamed or deleted a param/var but missed a usage.
  • VS Code underlines the reference in red and offers no completion for that name.
  • A reference inside a for loop body or a module block cannot see an outer symbol (or vice versa).

Common Root Causes

1. Parameter or variable never declared

You used location throughout resources but never wrote the param (a very common outcome of copying resource blocks out of documentation).

resource sa 'Microsoft.Storage/storageAccounts@2023-01-01' = {
  name: 'examplestor'
  location: location   // BCP057 — no `param location` anywhere
}

2. Typo or casing mismatch

Bicep identifiers are case-sensitive. Location, location, and loc are three different names.

param location string = resourceGroup().location
// ...
  location: Location   // BCP057 — declared as `location`, referenced as `Location`

3. Reference left behind after a rename/delete

You renamed storageName to storageAccountName in the declaration but one resource still references the old name.

main.bicep(40,11) : Error BCP057: The name "storageName" does not exist in the current context.

4. Scope violation — symbol is local to a loop, module, or lambda

Loop item variables, existing resources scoped elsewhere, and lambda parameters (map, filter) are only visible inside their block.

var names = ['a', 'b']
resource sas 'Microsoft.Storage/storageAccounts@2023-01-01' = [for n in names: {
  name: 'examplestor${n}'
  location: location
}]

output first string = n   // BCP057 — `n` only exists inside the loop

5. Referencing a param before/without the param keyword

Writing location = 'eastus' (assignment) instead of param location string = 'eastus' (declaration) means location is never actually declared.

6. Wrong file — symbol lives in a module you didn’t import

Expecting a value from another .bicep file without passing it in as a parameter or reading it from the module’s outputs.

How to Diagnose

Step 1: Jump to the flagged reference

az bicep build --file main.bicep

Go to the exact line/column. Confirm the spelling and casing of the name as used.

Step 2: Check whether the name is declared anywhere

grep -nE '(param|var|resource|module)[[:space:]]+location\b' main.bicep

No match means it was never declared — add the declaration. A match with different casing means a typo.

Step 3: Check scope

If the symbol is declared inside a for loop, a module block, or a lambda (map/filter/reduce), verify your reference is inside the same block. Loop and lambda variables do not escape their braces.

Step 4: Let the language server help

In VS Code with the Bicep extension, delete and retype the name — IntelliSense will list valid in-scope symbols. If your name is not offered, it is not in scope.

Fixes

Declare the missing parameter (with a sensible default)

For location, the idiomatic pattern is to default to the resource group’s region:

param location string = resourceGroup().location

Fix the typo / casing

Make the reference match the declaration exactly:

param location string = resourceGroup().location
resource sa 'Microsoft.Storage/storageAccounts@2023-01-01' = {
  name: 'examplestor'
  location: location   // matches the declaration
}

Finish the rename everywhere

Update every lingering reference to the new name:

grep -n 'storageName' main.bicep   # find stragglers
# then rename them to storageAccountName
az bicep build --file main.bicep

Respect scope — surface loop values via outputs

To expose something computed in a loop, index the resource collection instead of referencing the loop variable:

output firstName string = sas[0].name

Pass values across modules explicitly

Consume another file’s value through its module outputs, not by naming its internal symbol:

module net 'network.bicep' = { name: 'net', params: { location: location } }
output subnetId string = net.outputs.subnetId

What to Watch Out For

  • BCP057 points at the reference, not the declaration — the fix is almost always “declare it” or “fix the spelling,” not “change the line it points to.”
  • Identifiers are case-sensitive; standardize on lowerCamelCase to avoid Location vs location bugs.
  • After any rename, grep for the old name before rebuilding; a single missed reference fails the whole build.
  • Loop item variables and lambda parameters are block-scoped — never reference them outside their braces.
  • Default location to resourceGroup().location so the parameter is always available and environment-appropriate.
  • Cross-file values must flow through parameters (in) and module.outputs (out); you can never reach into another file’s private symbols.
Free download · 368-page PDF

Get 500 Battle-Tested DevOps AI Prompts — Free

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.