Migrating the ARM if() Expression to a Bicep Ternary Conditional Operator

Design and implement infrastructure as code (IaC)
Answer Correct answer: D — Bicep returns values with the ternary operator, so the ARM if() migrates to isComplete ? 1a : 2a; Bicep if only deploys a resource conditionally.

You have an Azure Resource Manager (ARM) template that contains the following expression. [if(parameters('isComplete'), '1a', '2a')] You need to migrate the template to Bicep. Which expression should you run?

  1. iif(isComplete, '1a', '2a')
  2. if(isComplete, '1a', '2a')
  3. if('isComplete') '1a' else '2a'
  4. isComplete ? '1a' '2a' Correct Answer

Community Votes

D
68%
C
16%
A
16%

68% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

Bicep expresses conditionals with the ternary conditional operator, so the migration is a variable assignment of isComplete ? '1a' : '2a'. The Bicep if keyword is only for conditionally deploying a resource, not for producing a value, and iif remains an ARM-only function.

An ARM template contains the expression if(parameters('isComplete'), '1a', '2a') and must be migrated to Bicep. Bicep is not a direct translation of the ARM template language, so the conditional construct has to be rewritten using Bicep's own operator rather than carried over as a function call.

Carrying the ARM function form across as iif(), which is an ARM template function with no Bicep equivalent, or writing if(isComplete, '1a', '2a'), which is neither valid Bicep value syntax nor a valid conditional-resource declaration.

Community Discussion (9 comments)

Yameo 👍 7 Selected: D
C is incorrect, the only possible is D, but the ':' is missing
Christian_garcia_martin 👍 1 Selected: D
D is correct but looks the OCR missed the ":" you'll see in the exam
Dankho 👍 1 Selected: D
After reviewing all options, I'm going with D but it's missing the colon
swk2az400 👍 2 Selected: C
Two possiblities: if (parameters('isComplete')) { '1a' } else { '2a' } or in a shortened way var result = isComplete ? '1a' : '2a'
Gooldmember 👍 2 Selected: D
D is correct if you imagine the ':' is added :)
maqsoodshah 👍 3 Selected: A
isComplete ? '1a' '2a' This syntax is incorrect because the conditional operator (? :) requires a : between the two return values. The correct syntax would be isComplete ? '1a' : '2a', but even then, iif is the preferred method in Bicep. Correct answer : A. iif(isComplete, '1a', '2a') This is correct because iif is the equivalent function in Bicep for the ARM if expression. It evaluates the condition (isComplete) and returns the corresponding value based on whether the condition is true or false.
schwagalla 👍 1 Selected: D
It should be answer D, but the ':' is currently missing there. All the other answers are wrong. There is no if function in bicep that has an else block. See: https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions The only way to use 'if' is together with a resource to conditionally deploy it. But you cannot use it to assign a string to a variable or so.
Mattt 👍 1 Selected: D
D is correct
8fc2e85 👍 1 Selected: C
D not correct. Syntax isn't correct for bicep. Would be isComplete ? '1a' : '2a'

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Bicep is not a syntactic superset of the ARM template language, so an ARM conditional cannot be copied across. The ARM expression if(parameters('isComplete'), '1a', '2a') returns a value, and in Bicep a value-producing conditional is written with the ternary conditional operator, so the migration is isComplete? '1a': '2a'. The option in the question is missing its colon, which several commenters identified as an OCR or export defect rather than a substantive disagreement. The vote was 68 for D, with 16 for C and 16 for A. Yameo, the highest-liked commenter, ruled out C and endorsed D while noting the missing colon, and Gooldmember, Christian_garcia_martin, and Dankho all reached the same conclusion, with Dankho phrasing it as all the other options being wrong.

Why the Other Options Are Wrong

The expression iif(isComplete, '1a', '2a') (A) is the ARM template function form, and iif is an ARM capability rather than a Bicep function, so it does not exist in the target language. maqsoodshah selected A but the reasoning is self-defeating, since the same comment concedes that the conditional operator form is the correct Bicep syntax and recommends adding the colon to the ternary. The expression if(isComplete, '1a', '2a') (B) uses the if keyword as though it were a function returning a value, which is not valid Bicep. The form if('isComplete') '1a' else '2a' (C) mixes an if statement with an else clause that Bicep does not have, and 8fc2e85 dismissed D on syntax grounds while proposing exactly the ternary form that D represents. schwagalla supplied the authoritative clarification, noting that in Bicep if is only used with a resource to conditionally deploy it and cannot assign a string to a variable.

Community Comment Notes

The community was decisive at 68 votes for D, and the discussion focused on a single defect rather than the concept. Yameo, with seven likes, stated that C is incorrect and D is the only possibility but the colon is missing. schwagalla linked the Bicep functions documentation and explained why there is no if function with an else block in Bicep, that if is only for conditionally deploying a resource, which is the fact that eliminates both A and B. Four separate commenters independently noticed the missing colon, and Gooldmember phrased it as D being correct if you imagine the colon added. The only dissent, 8fc2e85, argued against D on syntax grounds while proposing the same ternary operator with the colon, so the dissent actually confirms the intended answer.

Official Reference

Related Analysis

Practice All AZ-400 Questions

Access 100 questions with complete answers and detailed explanations.

View Full AZ-400 Practice Test →

← Back to AZ-400 Study Guide