github.com/LorbusChris/terraform@v0.11.12-beta1/terraform/test-fixtures/apply-multi-var-comprehensive/root.tf (about)

     1  
     2  variable "count" {
     3  }
     4  
     5  resource "test_thing" "source" {
     6    count = "${var.count}"
     7  
     8    # The diffFunc in the test exports "name" here too, which we can use
     9    # to test values that are known during plan.
    10  }
    11  
    12  resource "test_thing" "multi_count_var" {
    13    count = "${var.count}"
    14  
    15    # Can pluck a single item out of a multi-var
    16    source_id = "${test_thing.source.*.id[count.index]}"
    17    source_name = "${test_thing.source.*.name[count.index]}"
    18  }
    19  
    20  resource "test_thing" "multi_count_derived" {
    21    # Can use the source to get the count
    22    count = "${test_thing.source.count}"
    23  
    24    source_id = "${test_thing.source.*.id[count.index]}"
    25    source_name = "${test_thing.source.*.name[count.index]}"
    26  }
    27  
    28  resource "test_thing" "whole_splat" {
    29    # Can "splat" the ids directly into an attribute of type list.
    30    source_ids = "${test_thing.source.*.id}"
    31    source_names = "${test_thing.source.*.name}"
    32  
    33    # Accessing through a function should work.
    34    source_ids_from_func = "${split(" ", join(" ", test_thing.source.*.id))}"
    35    source_names_from_func = "${split(" ", join(" ", test_thing.source.*.name))}"
    36  
    37    # A common pattern of selecting with a default.
    38    first_source_id = "${element(concat(test_thing.source.*.id, list("default")), 0)}"
    39    first_source_name = "${element(concat(test_thing.source.*.name, list("default")), 0)}"
    40  
    41    # Legacy form: Prior to Terraform having comprehensive list support,
    42    # splats were treated as a special case and required to be presented
    43    # in a wrapping list. This is no longer the suggested form, but we
    44    # need it to keep working for compatibility.
    45    #
    46    # This should result in exactly the same result as the above, even
    47    # though it looks like it would result in a list of lists.
    48    source_ids_wrapped = ["${test_thing.source.*.id}"]
    49    source_names_wrapped = ["${test_thing.source.*.name}"]
    50  
    51  }
    52  
    53  module "child" {
    54    source = "./child"
    55  
    56    count = "${var.count}"
    57    source_ids = "${test_thing.source.*.id}"
    58    source_names = "${test_thing.source.*.name}"
    59  }
    60  
    61  output "source_ids" {
    62    value = "${test_thing.source.*.id}"
    63  }
    64  
    65  output "source_names" {
    66    value = "${test_thing.source.*.name}"
    67  }