Skip to content

JamesWoolfenden/terraform-aws-apigateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-aws-apigateway

Build Status Latest Release GitHub tag (latest SemVer) Terraform Version Infrastructure Tests pre-commit checkov Infrastructure Tests


Terraform module to create an API Gateway, each gateway will have different resources hanging off it so its more of an example than a module. It's 100% Open Source and licensed under the APACHE2.

Usage

This is just a very basic example.

alt text

Include this repository as a module in your existing Terraform code:

module "apigateway" {
  source          = "git::https://github.com/JamesWoolfenden/terraform-aws-apigateway.git?ref=87a8ac3b548615d170c9f56cb30e92f11667c85c"
  allowed_range   = var.allowed_range
  common_tags     = var.common_tags
  lambda_function = aws_lambda_function.examplea
  name            = var.name
  kms_key_id      = aws_kms_key.example.arn
}

Detailed Notes

Requirements

No requirements.

Providers

Name Version
aws n/a

Modules

No modules.

Resources

Name Type
aws_api_gateway_api_key.apikey resource
aws_api_gateway_client_certificate.pike resource
aws_api_gateway_deployment.stage_api resource
aws_api_gateway_integration.messages_integration resource
aws_api_gateway_integration.mock resource
aws_api_gateway_integration_response.messages_response resource
aws_api_gateway_integration_response.options_integration_response resource
aws_api_gateway_integration_response.proxy_integration_response resource
aws_api_gateway_method.messages_method resource
aws_api_gateway_method.options_method resource
aws_api_gateway_method_response.ok resource
aws_api_gateway_method_response.options_response resource
aws_api_gateway_method_settings.example resource
aws_api_gateway_request_validator.example resource
aws_api_gateway_resource.messages_resource resource
aws_api_gateway_rest_api.api resource
aws_api_gateway_stage.examplea resource
aws_api_gateway_usage_plan.api resource
aws_api_gateway_usage_plan_key.main resource
aws_cloudwatch_log_group.example resource
aws_lambda_permission.apigw_lambda resource
aws_caller_identity.current data source
aws_iam_policy_document.api_gateway_resource_policy data source
aws_region.current data source

Inputs

Name Description Type Default Required
allowed_range List of allowed CIDR list(any) n/a yes
authorization What Auth to use for the method string "AWS_IAM" no
common_tags This is to help you add tags to your cloud objects map(any) n/a yes
kms_key_id The arn of the KMS key any n/a yes
lambda_function n/a any n/a yes
name value string n/a yes
retention n/a number 365 no
stage_name n/a string "test" no
validator n/a
object({
name = string
validate_request_body = bool
validate_request_parameters = bool
})
{
"name": "example",
"validate_request_body": true,
"validate_request_parameters": true
}
no

Outputs

Name Description
api n/a
url n/a

Policy

The Terraform resource required is:

resource "aws_iam_policy" "terraform_pike" {
  name_prefix = "terraform_pike"
  path        = "/"
  description = "Pike Autogenerated policy from IAC"

  policy = jsonencode({
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "apigateway:DELETE",
                "apigateway:GET",
                "apigateway:PATCH",
                "apigateway:POST",
                "apigateway:PUT",
                "apigateway:UpdateRestApiPolicy"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": [
                "lambda:AddPermission",
                "lambda:GetPolicy",
                "lambda:RemovePermission"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor3",
            "Effect": "Allow",
            "Action": [
                "logs:AssociateKmsKey",
                "logs:CreateLogGroup",
                "logs:DeleteLogGroup",
                "logs:DeleteRetentionPolicy",
                "logs:DescribeLogGroups",
                "logs:DisassociateKmsKey",
                "logs:ListTagsLogGroup",
                "logs:PutRetentionPolicy"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
})
}

Related Projects

Check out these related projects.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Copyrights

Copyright © 2019-2023 James Woolfenden

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

James Woolfenden
James Woolfenden