title: Needing multiple counts on a Terraform resource?
body: <p>I have the following Terraform resource which is intended to create a separate encrypted EFS volume per warehouse, and then create mount targets in two subnets for each:</p>
  
  <pre><code>resource "aws_efs_file_system" "efs-data-share" {
    count      = "${length(var.warehouses)}"
    encrypted  = "${var.encrypted}"
    kms_key_id = "${element(data.aws_kms_key.encryption_key.*.arn,count.index)}"
    performance_mode = "${var.performance_mode}"
  
    tags {
      Name        = "${element(split(".",var.warehouses[count.index]),0)}-${var.name_suffix}"
      Warehouse   = "${element(split(".",var.warehouses[count.index]),0)}"
      Environment = "${var.environment}"
      Purpose  = "${var.purpose}"
    }
  }
  
  resource "aws_efs_mount_target" "mounts" {
    count           = "${length(var.subnets)}"
    file_system_id  = "${aws_efs_file_system.efs-data-share.*.id}"
    subnet_id       = "${element(var.subnets, count.index)}"
    security_groups = ["${var.efs_security_groups}"]
  }
  
  data "aws_kms_key" "encryption_key" {
    count = "${length(var.warehouses)}"
    key_id = "alias/${element(split(".",var.warehouses[count.index]),0)}-${var.key_alias_suffix}"
  }
  </code></pre>
  
  <p>The EFS themselves launch fine, but the mounts fail, because the file_system_id must be a single resource, not a list. </p>
  
  <pre><code>    * module.prod_multi_efs.aws_efs_mount_target.mounts[1]: file_system_id must be a single value, not a list
      * module.prod_multi_efs.aws_efs_mount_target.mounts[0]: file_system_id must be a single value, not a list
  </code></pre>
  
  <p>I'm not sure what my recourse is here in terms of Terraform syntax. I need two mounts in each case, so my count is on the length of the subnets variable, for which I'm passing in subnet-123456 and subnet-567890. How can I get the system to make both mounts for each EFS made (seven in total by length of warehouses list) without being able to use a second count within the aws_efs_mount_target?</p>
  
  <p>Here is how I am calling the module:</p>
  
  <pre><code>module "prod_multi_efs" {
    source              = "../../../../Modules/Datastore/MultiEFS"
    efs_security_groups = ["${aws_security_group.prod-efs-group.id}"]
    environment         = "Prod"
    name_suffix         = "${module.static_variables.prod_efs_name}"
    key_alias_suffix    = "prod-efs-${module.static_variables.account_id}-us-east-1"
    subnets             = ["${module.prod_private_subnet_1.subnet_id}", "${module.prod_private_subnet_2.subnet_id}"]
    warehouses          = "${module.static_variables.warehouses}" #The list of seven warehouses
  }
  </code></pre>
  
  <p>Here is my plan with the attempt of adding [count.index] as per the answer below - it does two mounts, but only to the first 2 of the 7 FS IDs:</p>
  
  <pre><code>  + module.stg_multi_efs.aws_efs_mount_target.mounts[0]
        id:                                      &lt;computed&gt;
        dns_name:                                &lt;computed&gt;
        file_system_arn:                         &lt;computed&gt;
        file_system_id:                          "fs-123456"
        ip_address:                              &lt;computed&gt;
        network_interface_id:                    &lt;computed&gt;
        security_groups.#:                       "1"
        security_groups.4286231943:              "sg-xxxxxxxxxx"
        subnet_id:                               "subnet-aaaaaaaa"
  
    + module.stg_multi_efs.aws_efs_mount_target.mounts[1]
        id:                                      &lt;computed&gt;
        dns_name:                                &lt;computed&gt;
        file_system_arn:                         &lt;computed&gt;
        file_system_id:                          "fs-567890"
        ip_address:                              &lt;computed&gt;
        network_interface_id:                    &lt;computed&gt;
        security_groups.#:                       "1"
        security_groups.4286231943:              "sg-xxxxxxxxxxx"
        subnet_id:                               "subnet-bbbbbbbbbb"
  </code></pre>