github.com/hugorut/terraform@v1.1.3/src/terraform/testdata/apply-multi-var-comprehensive/root.tf (about)

     1  variable "num" {
     2  }
     3  
     4  resource "test_thing" "source" {
     5    count = var.num
     6  
     7    key = "source.${count.index}"
     8  
     9    # The diffFunc in the test exports "name" here too, which we can use
    10    # to test values that are known during plan.
    11  }
    12  
    13  resource "test_thing" "multi_count_var" {
    14    count = var.num
    15  
    16    key = "multi_count_var.${count.index}"
    17  
    18    # Can pluck a single item out of a multi-var
    19    source_id   = test_thing.source.*.id[count.index]
    20    source_name = test_thing.source.*.name[count.index]
    21  }
    22  
    23  resource "test_thing" "multi_count_derived" {
    24    # Can use the source to get the count
    25    count = length(test_thing.source)
    26  
    27    key = "multi_count_derived.${count.index}"
    28  
    29    source_id   = test_thing.source.*.id[count.index]
    30    source_name = test_thing.source.*.name[count.index]
    31  }
    32  
    33  resource "test_thing" "whole_splat" {
    34    key = "whole_splat"
    35  
    36    # Can "splat" the ids directly into an attribute of type list.
    37    source_ids   = test_thing.source.*.id
    38    source_names = test_thing.source.*.name
    39  
    40    # Accessing through a function should work.
    41    source_ids_from_func   = split(" ", join(" ", test_thing.source.*.id))
    42    source_names_from_func = split(" ", join(" ", test_thing.source.*.name))
    43  
    44    # A common pattern of selecting with a default.
    45    first_source_id   = element(concat(test_thing.source.*.id, ["default"]), 0)
    46    first_source_name = element(concat(test_thing.source.*.name, ["default"]), 0)
    47  
    48    # Prior to v0.12 we were handling lists containing list interpolations as
    49    # a special case, flattening the result, for compatibility with behavior
    50    # prior to v0.10. This deprecated handling is now removed, and so these
    51    # each produce a list of lists. We're still using the interpolation syntax
    52    # here, rather than the splat expression directly, to properly mimic how
    53    # this would've looked prior to v0.12 to be explicit about what the new
    54    # behavior is for this old syntax.
    55    source_ids_wrapped   = ["${test_thing.source.*.id}"]
    56    source_names_wrapped = ["${test_thing.source.*.name}"]
    57  
    58  }
    59  
    60  module "child" {
    61    source = "./child"
    62  
    63    num          = var.num
    64    source_ids   = test_thing.source.*.id
    65    source_names = test_thing.source.*.name
    66  }
    67  
    68  output "source_ids" {
    69    value = test_thing.source.*.id
    70  }
    71  
    72  output "source_names" {
    73    value = test_thing.source.*.name
    74  }