Difference between revisions of "Terraform lookup function"

From wikieduonline
Jump to navigation Jump to search
Line 4: Line 4:
  
 
<code>lookup([[map]], key, default)</code>
 
<code>lookup([[map]], key, default)</code>
 +
 +
== Examples ==
 +
variable "candy_list" {
 +
  type = list(string)
 +
  default = ["snickers", "kitkat", "reeces", "m&ms"]
 +
}
 +
 
 +
output "give_me_candy" {
 +
  value = "${lookup(var.candy_list, 2)}"
 +
}
  
 
== Related ==
 
== Related ==

Revision as of 20:27, 5 April 2023

Terraform lookup function retrieves the value of a single element from a map, given its key.

lookup(map, key, default)

Examples

variable "candy_list" {
  type = list(string)
  default = ["snickers", "kitkat", "reeces", "m&ms"]
}
 
output "give_me_candy" {
  value = "${lookup(var.candy_list, 2)}"
}

Related

See also

Advertising: