Hi, I am using Terraform to try bootstrap API on AWS Gateway. My goal is to create new API, but reuse some existing configs, like existing usage plans and the associated API keys. I have the following .tf:
# resources for aws_api_gateway, aws_api_gateway_deployment
...
import {
to = aws_api_gateway_usage_plan.bulk_load
id = "xifkaf"
}
resource "aws_api_gateway_usage_plan" "bulk_load" {
name = "bulk_load"
api_stages {
api_id = aws_api_gateway_rest_api.my_rest_api.id
stage = aws_api_gateway_stage.qa.stage_name
}
}
After apply the code on AWS, I realize the existing APIs associated with this “bulk_load” usage plan is gone, and the settings for throttle rate and quota are missing too. See the attached image to demonstrate the difference.
I guess it’s because I didn’t declare the existing attributes for this usage plan. But what annoys me are:
-
aws_api_gateway_usage_plan on tf aws document is resource only, there is no data source for it. I am not sure if there is an entrance for it as data source can avoid this overriding, though.
-
To avoid the settings to be overrides, I can to fetch the existing settings every time, and then append/update a new API entry into the usage plan. But I hope there is a smarter way to avoid such error-prone manual work.
Target:
I can reference existing usage plans on AWS API Gateway to my newly created API, and also keep the settings of these usage plans unchanged, except adding one more associated API.
I am new to TF. I searched around but still no clues. I would really appreciate solutions for this issue, or advice about best practice. Thanks in advance!