User Tools

Site Tools


terraform:map

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
terraform:map [18/02/2025 14:22] andrewterraform:map [18/02/2025 15:30] (current) – [Map object] andrew
Line 69: Line 69:
  
  
 +<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.1739888567.txt.gz · Last modified: by andrew

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki