title: Sharing resources between Terraform workspaces
body: <p>I have an infrastructure I'm deploying using Terraform in AWS. This infrastructure can be deployed to different environments, for which I'm using workspaces.</p>
  
  <p>Most of the components in the deployment should be created separately for each workspace, but I have several key components that I wish to be shared between them, primarily:</p>
  
  <ul>
  <li>IAM roles and permissions</li>
  <li>They should use the same API Gateway, but each workspace should deploy to different paths and methods</li>
  </ul>
  
  <p>For example:</p>
  
  <pre><code>resource "aws_iam_role" "lambda_iam_role" {
    name = "LambdaGeneralRole"
    policy = &lt;...&gt;
  }
  
  resource "aws_lambda_function" "my_lambda" {
    function_name = "lambda-${terraform.workspace}"
    role = "${aws_iam_role.lambda_iam_role.arn}"
  }
  </code></pre>
  
  <p>The first resource is a IAM role that should be shared across all instances of that Lambda, and shouldn't be recreated more than once.</p>
  
  <p>The second resource is a Lambda function whose name depends on the current workspace, so each workspace will deploy and keep track of the state of a different Lambda. </p>
  
  <p>How can I share resources, and their state, between different Terraform workspaces?</p>