Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.41 KB

variables.md

File metadata and controls

53 lines (39 loc) · 1.41 KB

Variables

A variable declaration is used to assign a value to an identifier in the current scope. They can depend on resources, other variables or inputs. They can be assigned any valid value.

Unlike many imperative languages, variables cannot be reassigned, and must be assigned when declared. A variable cannot have the same name as a parameter, resource, output or another variable in the same scope.

Unlike parameters or outputs, variables do not require declaring the type. The type is inferred from the value of the variable.

There are no constraints on placement of variable declarations. They can be mixed with any other valid declarations in any order.

Examples

The examples below cover variable declaration using hard-coded and calculated values.

String variable

var myString = 'my string value'

var location = resourceGroup().location

Boolean variables

var iAmTrue = true
var iAmFalse = false

var hasItems = length(myArray) >= 0

Numeric variables

var meaningOfLifeTheUniVerseAndEverything = 42

var lengthOfMyArray = length(myArray)

Object variables

var myObject = {
  first: 1
  second: 2
}

var keys = listKeys(myResource.id, myResource.apiVersion)

Array variables

var myArray = [
  'item 1'
  'item 2'
]

var myOtherArray = createArray('first', 'second', 'third')