Giter Site home page Giter Site logo

terraform-aws-api-gateway-enable-cors's Introduction

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 = "squidfunk/api-gateway-enable-cors/aws"
  version = "0.3.3"

  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-2020 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.

terraform-aws-api-gateway-enable-cors's People

Contributors

dwaynebailey avatar frankyhun avatar kudla avatar maciejmajewski avatar mainaero avatar squidfunk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-api-gateway-enable-cors's Issues

Failing on Terraform 0.15

Terraform 0.15 removed the deprecated map() function, hence this module is not working. Error log below:

╷
│ Error: Error in function call
│
│   on .terraform/modules/cors_policy_item/headers.tf line 27, in locals:
│   27:   headers = map(
│   28:     "Access-Control-Allow-Headers", "'${join(",", var.allow_headers)}'",
│   29:     "Access-Control-Allow-Methods", "'${join(",", var.allow_methods)}'",
│   30:     "Access-Control-Allow-Origin", "'${var.allow_origin}'",
│   31:     "Access-Control-Max-Age", "'${var.allow_max_age}'",
│   32:     "Access-Control-Allow-Credentials", var.allow_credentials ? "'true'" : ""
│   33:   )
│     ├────────────────
│     │ var.allow_credentials will be known only after apply
│     │ var.allow_headers is a list of string, known only after apply
│     │ var.allow_max_age is a string, known only after apply
│     │ var.allow_methods is a list of string, known only after apply
│     │ var.allow_origin is a string, known only after apply
│
│ Call to function "map" failed: the "map" function was deprecated in Terraform v0.12 and is no longer available; use tomap({ ... }) syntax to write a literal map.

Error in versions > v0.12 Terraform

On using the terraform-aws-api-gateway-enable-cors module and running terraform plan
Error
│ on .terraform/modules/cors/headers.tf line 27, in locals:
│ 27: headers = map(
│ 28: "Access-Control-Allow-Headers", "'${join(",", var.allow_headers)}'",
│ 29: "Access-Control-Allow-Methods", "'${join(",", var.allow_methods)}'",
│ 30: "Access-Control-Allow-Origin", "'${var.allow_origin}'",
│ 31: "Access-Control-Max-Age", "'${var.allow_max_age}'",
│ 32: "Access-Control-Allow-Credentials", var.allow_credentials ? "'true'" : ""
│ 33: )
│ ├────────────────
│ │ var.allow_credentials will be known only after apply
│ │ var.allow_headers is a list of string, known only after apply
│ │ var.allow_max_age is a string, known only after apply
│ │ var.allow_methods is a list of string, known only after apply
│ │ var.allow_origin is a string, known only after apply

│ Call to function "map" failed: the "map" function was deprecated in Terraform v0.12 and is no longer available; use tomap({ ... }) syntax to write a
│ literal map.

just wanted to say thank you!

hey man,

you solved me a problem with a 10' internet search and 6 lines of code. It works like a charm and just wanted to say thank you for releasing this module. keep up with the good work!

❤️

Enabled CORS for nested resources

When I use the module to enable CORS on both a resource and its parent, I get the following error:

Error creating API Gateway Deployment: BadRequestException: No integration defined for method

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.