Easily add an OPTIONS method to an API Gateway resource to enable CORS
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Updated copyright year Jan 1, 2019
.gitignore Updated copyright year Jan 1, 2019
.travis.yml Updated copyright year Jan 1, 2019
CHANGELOG Prepare 0.2.0 release Dec 24, 2018
CODE_OF_CONDUCT.md Initial commit Jun 12, 2018
CONTRIBUTING.md Initial commit Jun 12, 2018
LICENSE Updated copyright year Jan 1, 2019
README.md Updated copyright year Jan 1, 2019
headers.tf Updated copyright year Jan 1, 2019
main.tf Updated copyright year Jan 1, 2019
variables.tf Updated copyright year Jan 1, 2019

README.md

Travis Gitter GitHub

Terraform AWS API Gateway Enable CORS

A Terraform module to add an OPTIONS method to allow Cross-Origin Resource Sharing (CORS) preflight requests.

Usage

module "cors" {
  source = "github.com/squidfunk/terraform-aws-api-gateway-enable-cors"
  version = "0.2.0"

  api_id          = "<api_id>"
  api_resource_id = "<api_resource_id>"
}

By default, this will create a new MOCK endpoint on the provided API Gateway resource allowing CORS preflight requests for all methods and all origins by default. Of course this can be customized using variables as stated in the next section.

Configuration

The following variables can be configured:

Required

api_id

  • Description: API identifier
  • Default: none

api_resource_id

  • Description: API resource identifier
  • Default: none

Optional

allow_headers

  • Description: Allow headers (Access-Control-Allow-Headers)

  • Default:

    [
      "Authorization",
      "Content-Type",
      "X-Amz-Date",
      "X-Amz-Security-Token",
      "X-Api-Key"
    ]

allow_methods

  • Description: Allow methods (Access-Control-Allow-Methods)

  • Default:

    [
      "OPTIONS",
      "HEAD",
      "GET",
      "POST",
      "PUT",
      "PATCH",
      "DELETE"
    ]

allow_origin

  • Description: Allow origin (Access-Control-Allow-Origin)
  • Default: "*"

allow_max_age

  • Description: Allow caching time (Access-Control-Allow-Max-Age)
  • Default: "7200"

allow_credentials

  • Description: Allow credentials (Access-Control-Allow-Credentials)
  • Default: none

Outputs

None.

License

MIT License

Copyright (c) 2018-2019 Martin Donath

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.