title: Build output map in terraform
body: <p>I have a list of users to create, a list of sns topics and to create policies to give permissions to users on topics. These are all namespaced against the user...</p>
  
  <p>Given:</p>
  
  <p>main.tf</p>
  
  <pre><code>
  provider "aws" {
    region                  = "eu-west-1"
    profile                 = "terraform"
  }
  
  module "topics" {
    source = "./queues/topics"
  }
  
  module "users" {
    source = "./users"
  }
  
  module "policies" {
    source = "./policies"
  
    sns_topics = "${module.topics.sns_topics}"
  }
  </code></pre>
  
  <p>./queues/topics.tf</p>
  
  <pre><code>resource "aws_sns_topic" "svc_topic" {
    count = "${length(var.sns_topics)}"
    name = "${element(var.sns_topics, count.index)}"
  }
  </code></pre>
  
  <p>./queues/topics/vars.tf</p>
  
  <pre><code># List of topics
  variable "sns_topics" {
    type = "list"
  
    default = [
      "a-topic",
      "b-topic",
      "c-topic",
    ]
  }
  </code></pre>
  
  <p>./queues/topics/output.tf</p>
  
  <pre><code>output "sns_topics" {
    value = "${var.sns_topics}"
  }
  </code></pre>
  
  <p>./users/main.tf</p>
  
  <pre><code>resource "aws_iam_user" "usrs" {
    count = "${length(var.topic_user)}"
    name = "usr-msvc-${element(var.topic_user, count.index)}"
  }
  </code></pre>
  
  <p>./users/vars.tf</p>
  
  <pre><code>variable "topic_user" {
    type = "list"
  
    default =[
      "user-a",
      "user-b",
      "user-c",
    ]
  }
  </code></pre>
  
  <p>./users/output.tf</p>
  
  <pre><code>output "topic_user" {
    value = "${var.topic_user}"
  }
  </code></pre>
  
  <p>./policies/main.tf</p>
  
  <pre><code>resource "aws_iam_policy" "sns_publisher" {
    count = "${length(var.sns_topics)}"
  
    name = "sns-${element(var.sns_topics, count.index)}-publisher"
    policy = &lt;&lt;POLICY
  {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": "sns:Publish",
        "Resource": "arn:aws:sns:*:*:${element(var.sns_topics, count.index)}"
      }
    ]
  }
  POLICY
  }
  </code></pre>
  
  <p>This is where I'd like to build a map in the output to 
  map user to topic</p>
  
  <pre><code>output "usr_topic_map" {
    value = {
      "user-a" = "a-topic
      "user-b" = "c-topic
      "user-c" = "c-topic
    }
  }
  </code></pre>
  
  <p>I can pass the list of users in to the policy module but I've no idea how to generate this map in the output.</p>
  
  <p>I want to use this to attach the policy to the corresponding user.</p>
  
  <p>Open to improving structure too if it simplifies tasks.</p>