amazon-web-services - Why do I get Resource's path part only allow a-zA-Z0-9._-: when trying to create an API gateway resource using Terraform?
问题描述
Is it possible to create and AWS API gateway resources with subdirectories from the root with Terraform?
When doing
resource "aws_api_gateway_resource" "MyDemoResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
path_part = "/will/this/work"
}
I get the error:
aws_api_gateway_resource.MyDemoResource: 1 error occurred: aws_api_gateway_resource.MyDemoResource: Error creating API Gateway Resource: BadRequestException: Resource's path part only allow a-zA-Z0-9._-: or a valid greedy path variable and curly braces at the beginning and the end."
I've found this GitHub ticket and a few others like it. I'm not sure if this is a bug or by design with a workaround.
Additionally, If I create this manually in the AWS console and then import it, the full path appears in the attribute path
properly but not in the input path_part
.
"aws_api_gateway_resource.MyDemoResource": {
"type": "aws_api_gateway_resource",
"depends_on": [],
"primary": {
"id": "foo",
"attributes": {
"id": "foo",
"parent_id": "foo",
**"path": "/will/this/work"**,
**"path_part": "work"**,
"rest_api_id": "foo"
}
解决方案
The path_part
is the last path segment of an API Gateway resource, not the full path. This mirrors the tree-like structure that you see in the AWS Console.
The full path is exported, yes, but is not taken in as an argument. That's why you have the full path in the imported Terraform state as path
and the last path segment - work
- as the path_part
.
Currently, you're not passing the last path segment; you're passing the full path.
What you need to do is specify 3 different aws_api_gateway_resource
each for the different parts of the path segment, with the parent IDs correctly specified to create the structure you need:
will
with the parent ID ofaws_api_gateway_rest_api.{REST-API-NAME}.root_resource_id
this
with the parent ID ofaws_api_gateway_resource.will.id
work
with the parent ID ofaws_api_gateway_resource.this.id
Visual representation:
MyAPI
├─ /will
│ ├─ /this
│ │ ├─ /work
推荐阅读
- jhipster - 更新实体时防止 JHipster import-jdl 覆盖更改
- javascript - scrollTop 的问题 - 30 秒应该持续,29 秒停留在一个地方
- javascript - 模型与列表
使用 Ajax 向控制器发送 post 请求时 - javascript - 具有同一对象的方法的新属性?
- c++ - constexpr 函数采用 const char*
- virtual-machine - 控制台已断开连接。关闭此窗口并重新启动控制台以重新连接
- sharepoint-online - Office 365 管理 API:使用 StartTime 和 EndTime 进行筛选不起作用
- java - SpringLayout 是固定大小的布局管理器吗?
- r - R:如何编织 pdf 并且只打印输出但在没有 `suppressMessages` 的情况下抑制消息?
- r - 根据特定模式对数据框进行子集化