title: Capture Terraform provisioner output?
body: <p><strong>Use Case</strong></p>
  
  <p>Trying to provision a (Docker Swarm or Consul) cluster where initializing the cluster first occurs on one node, which generates some token, which then needs to be used by other nodes joining the cluster. Key thing being that nodes 1 and 2 shouldn't attempt to join the cluster until the join key has been generated by node 0.</p>
  
  <p>Eg. on node 0, running <code>docker swarm init ...</code> will return a <em>join token</em>. Then on nodes 1 and 2, you'd need to pass that token to the same command, like <code>docker swarm init ${JOIN_TOKEN} ${NODE_0_IP_ADDRESS}:{SOME_PORT}</code>. And magic, you've got a neat little cluster...</p>
  
  <p><strong>Attempts So Far</strong></p>
  
  <ul>
  <li><p>Tried initializing all nodes with the AWS SDK installed, and storing the join key from node 0 on S3, then fetching that join key on other nodes. This is done via a null_resource with 'remote-exec' provisioners. Due to the way Terraform executes things in parallel, there are racy type conditions and predictably nodes 1 and 2 frequently attempt to fetch a key from S3 thats not there yet (eg. node 0 hasn't finished its stuff yet).</p></li>
  <li><p>Tried using the 'local-exec' provisioner to SSH into node 0 and capture its join key output. This hasn't worked well or I sucked at doing it.</p></li>
  </ul>
  
  <hr>
  
  <p>I've read the docs. And stack overflow. And Github issues, like <a href="https://github.com/hashicorp/terraform/issues/610" rel="noreferrer">this really long outstanding one</a>. Thoroughly. If this has been solved elsewhere though, links appreciated!</p>
  
  <hr>
  
  <p>PS - this is directly related to and is a smaller subset of <a href="https://github.com/hashicorp/terraform/issues/610" rel="noreferrer">this question</a>, but wanted to re-ask it in order to focus the scope of the problem.</p>