我希望像下面这样配置使用计划、api密钥和方法。
基本上,一个api网关有10个方法,我想为每个资源配置不同的速率
usage plan api key Resource Method Rate (requests per second)
usage plan1 apiKey1 /a POST 1 qps
usage plan1 apiKey1 /b POST 2 qps
usage plan2 apiKey2 /a POST 4 qps
usage plan2 apiKey2 /b POST 6 qps但在aws_api_gateway_usage_plan中,我只能找到舞台的使用计划设置。
我可以使用什么terraform资源来配置使用计划?
我想实现以下功能配置方法节流

发布于 2020-02-11 02:14:35
在检查之后,我认为到目前为止,terraform不支持这个特性。
但是,使用aws推荐是有解决办法的。
请参阅此链接:
https://github.com/terraform-providers/terraform-provider-aws/issues/5901
我引用了这里的作品
variable "method_throttling" {
type = "list"
description = "example method throttling"
default = [
"\\\"/<RESOURCE1>/<METHOD1>\\\":{\\\"rateLimit\\\":400,\\\"burstLimit\\\":150}",
"\\\"/<RESOURCE2>/<METHOD2>\\\":{\\\"rateLimit\\\":1000,\\\"burstLimit\\\":303}"
]
}
# locals
locals {
# Delimiter for later usage
delimiter = "'"
# Base aws cli command
base_command = "aws apigateway update-usage-plan --usage-plan-id ${aws_api_gateway_usage_plan.usage_plan.id} --patch-operations op"
# Later aws cli command
base_path = "path=/apiStages/${var.api_gateway_rest_api_id}:${var.api_gateway_stage_name}/throttle,value"
# Join method throttling variable to string
methods_string = "${local.delimiter}\"{${join(",", var.method_throttling)}}\"${local.delimiter}"
}
resource "null_resource" "method_throttling" {
count = "${length(var.method_throttling) != 0 ? 1 : 0}"
# create method throttling
provisioner "local-exec" {
when = "create"
command = "${local.base_command}=add,${local.base_path}=${local.methods_string}"
on_failure = "continue"
}
# edit method throttling
provisioner "local-exec" {
command = "${local.base_command}=replace,${local.base_path}=${local.methods_string}"
on_failure = "fail"
}
# delete method throttling
provisioner "local-exec" {
when = "destroy"
command = "${local.base_command}=remove,${local.base_path}="
on_failure = "fail"
}
triggers = {
usage_plan_change = "${aws_api_gateway_usage_plan.usage_plan.id}"
methods_change = "${local.methods_string}"
}
depends_on = [
"aws_api_gateway_usage_plan.usage_plan"
]
}https://stackoverflow.com/questions/60126179
复制相似问题