title: Terraform: How to create API Gateway endpoints and methods from a list of objects?
body: <p>I want to create a terraform (v0.12+) module that outputs an AWS API Gateway with Lambda integration(s). I cannot quite understand how (or if it is even possible) to iterate over a list of maps to dynamically output resources.</p>
  
  <p>The user should be able to instantiate the module like so:</p>
  
  <pre><code>module "api_gateway" {
    source = "./apig"
  
    endpoints = [
      {
        path = "example1"
        method = "GET"
        lambda = "some.lambda.reference"
      },
      {
        path = "example1"
        method = "POST"
        lambda = "some.lambda.reference"
      },
      {
        path = "example2"
        method = "GET"
        lambda = "another.lambda.reference"
      }
    ]
  }
  </code></pre>
  
  <p>From the <code>endpoints</code> interface, I want to output three resources:</p>
  
  <ol>
  <li>an <code>aws_api_gateway_resource</code> where <code>path_part = endpoint[i].path</code>  </li>
  <li>an <code>aws_api_gateway_method</code> where <code>http_method = endpoint[i].method</code></li>
  <li>an <code>aws_api_gateway_integration</code> that takes a reference to
  <code>endpoint[i].lambda</code>, etc</li>
  </ol>
  
  <p>Terraform's <code>for_each</code> property doesn't seem robust enough to handle this. I know Terraform also supports <code>for</code> loops and <code>for / in</code> loops, but I have not been able to find any examples of using such expressions for resource declaration.</p>