User Tools

Site Tools


terraform:map

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
terraform:map [18/02/2025 10:37] – created andrewterraform:map [18/02/2025 15:30] (current) – [Map object] andrew
Line 23: Line 23:
 } }
 output "hatvalue" { output "hatvalue" {
-  value = " wears  ${lookup(var.var_map, var.owner)}"+  value = "${lookup(var.var_map, var.owner)}"
 } }
 +output "hatvalue1" {
 +  value = var.var_map[var.owner]
 +}
 +
 </code> </code>
  
Line 58: Line 62:
 $ $
 </code> </code>
 +
 +
 +
 +
 +====== Map object ======
 +
 +
 +<code>
 +variable "map_object" {
 +  type = map(object({
 +    var1 = string
 +    var2 = string
 +    var3 = bool
 +    }))
 +
 +  default = {
 +    "east-1" = {
 +      var1 = "variable1east - string"
 +      var2 = "variable2east - string"
 +      var3 = true
 +    }
 +    "west-1" = {
 +      var1 = "variable1west - string"
 +      var2 = "variable2west - string"
 +      var3 = true
 +    }
 +
 +  }
 +}
 +
 +
 +output "choice_obj" {
 +  value = var.map_object["east-1"]
 +}
 +
 +output "Choice_var1" {
 +  value = var.map_object["east-1"].var2
 +}
 +</code>
 +
 +
 +<code bash>
 +$ terraform apply
 +
 +Changes to Outputs:
 +  + Choice_var1 = "variable2west - string"
 +  + choice_obj  = {
 +      + var1 = "variable1west - string"
 +      + var2 = "variable2west - string"
 +      + var3 = true
 +    }
 +
 +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:
 +
 +Choice_var1 = "variable2west - string"
 +choice_obj = {
 +  "var1" = "variable1west - string"
 +  "var2" = "variable2west - string"
 +  "var3" = true
 +}
 +$
 +</code>
 +
 +
terraform/map.1739875077.txt.gz · Last modified: by andrew

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki