Provides an API Gateway Usage Plan.
resource "aws_api_gateway_rest_api" "example" {
body = jsonencode({
openapi = "3.0.1"
info = {
title = "example"
version = "1.0"
}
paths = {
"/path1" = {
get = {
x-amazon-apigateway-integration = {
httpMethod = "GET"
payloadFormatVersion = "1.0"
type = "HTTP_PROXY"
uri = "https://ip-ranges.amazonaws.com/ip-ranges.json"
}
}
}
}
})
name = "example"
}
resource "aws_api_gateway_deployment" "example" {
rest_api_id = aws_api_gateway_rest_api.example.id
triggers = {
redeployment = sha1(jsonencode(aws_api_gateway_rest_api.example.body))
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_api_gateway_stage" "development" {
deployment_id = aws_api_gateway_deployment.example.id
rest_api_id = aws_api_gateway_rest_api.example.id
stage_name = "development"
}
resource "aws_api_gateway_stage" "production" {
deployment_id = aws_api_gateway_deployment.example.id
rest_api_id = aws_api_gateway_rest_api.example.id
stage_name = "production"
}
resource "aws_api_gateway_usage_plan" "example" {
name = "my-usage-plan"
description = "my description"
product_code = "MYCODE"
api_stages {
api_id = aws_api_gateway_rest_api.example.id
stage = aws_api_gateway_stage.development.stage_name
}
api_stages {
api_id = aws_api_gateway_rest_api.example.id
stage = aws_api_gateway_stage.production.stage_name
}
quota_settings {
limit = 20
offset = 2
period = "WEEK"
}
throttle_settings {
burst_limit = 5
rate_limit = 10
}
}
The API Gateway Usage Plan argument layout is a structure composed of several sub-resources - these resources are laid out below.
name
- (Required) Name of the usage plan.description
- (Optional) Description of a usage plan.api_stages
- (Optional) Associated API stages of the usage plan.quota_settings
- (Optional) The quota settings of the usage plan.throttle_settings
- (Optional) The throttling limits of the usage plan.product_code
- (Optional) AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.tags
- (Optional) Key-value map of resource tags. If configured with a provider default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.api_id
(Required) - API Id of the associated API stage in a usage plan.stage
(Required) - API stage name of the associated API stage in a usage plan.throttle
- (Optional) The throttling limits of the usage plan.path
(Required) - Method to apply the throttle settings for. Specfiy the path and method, for example /test/GET
.burst_limit
(Optional) - The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.rate_limit
(Optional) - The API request steady-state rate limit.limit
(Optional) - Maximum number of requests that can be made in a given time period.offset
(Optional) - Number of requests subtracted from the given limit in the initial time period.period
(Optional) - Time period in which the limit applies. Valid values are "DAY", "WEEK" or "MONTH".burst_limit
(Optional) - The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.rate_limit
(Optional) - The API request steady-state rate limit.This resource exports the following attributes in addition to the arguments above:
id
- ID of the API resourcename
- Name of the usage plan.description
- Description of a usage plan.api_stages
- Associated API stages of the usage plan.quota_settings
- Quota of the usage plan.throttle_settings
- Throttling limits of the usage plan.product_code
- AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.arn
- ARNtags_all
- Map of tags assigned to the resource, including those inherited from the provider default_tags
configuration block.In Terraform v1.5.0 and later, use an import
block to import AWS API Gateway Usage Plan using the id
. For example:
import {
to = aws_api_gateway_usage_plan.myusageplan
id = "<usage_plan_id>"
}
Using terraform import
, import AWS API Gateway Usage Plan using the id
. For example:
% terraform import aws_api_gateway_usage_plan.myusageplan <usage_plan_id>