This template sets up an API Gateway with a usage plan and an API key, and associates them together.

Terraform Template

resource "aws_api_gateway_api_key" "mykey" {
  name = "my_key"
}

resource "aws_api_gateway_rest_api" "test" {
  name = "MyDemoAPI"
}

resource "aws_api_gateway_usage_plan" "myusageplan" {

  api_stages {
    api_id = aws_api_gateway_rest_api.test.id
    stage = "aws_api_gateway_stage.foo.stage_name"
  }
  name = "my_usage_plan"
}

resource "aws_api_gateway_usage_plan_key" "main" {
  key_id = aws_api_gateway_api_key.mykey.id
  key_type = "API_KEY"
  usage_plan_id = aws_api_gateway_usage_plan.myusageplan.id
}