User Tools

Site Tools


terraform:map

This is an old revision of the document!


Terraform Map statement

$ more main.tf
variable "owner" {
  description = "Hat owner"
  type        = string
}


variable "var_map" {
  type = map(string)
  default = {
    tom  = "Trilby"
    bertie  = "Bowler"
    harry  = "Homberg"
  }
}


output "owner" {
  value = var.owner
}
output "hatvalue" {
  value = "${lookup(var.var_map, var.owner)}"
}
output "hatvalue1" {
  value = var.var_map[var.owner]
}
$ terraform apply
var.owner
  Hat owner
 
  Enter a value: bertie
 
 
Changes to Outputs:
  ~ hatvalue = " wears  Homberg" -> " wears  Bowler"
  ~ owner    = "harry" -> "bertie"
 
You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
 
Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.
 
  Enter a value: yes
 
 
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
 
Outputs:
 
hatvalue = " wears  Bowler"
owner = "bertie"
$

Map object

terraform/map.1739888567.txt.gz · Last modified: by andrew

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki