terraform - 为什么 terraform 偶尔无法创建此 api 网关资源?
问题描述
我有一个 terraform 模块,它创建一个 API 网关实例,并将几个 lambda 连接到它。它构建并可靠地创建 API,但在构建中经常会出现故障,需要通过简单重复 terraform apply 命令来解决,有时重复两次。
这是模块的相关部分:
locals {
lambda_endpoints_by_path = { for e in var.lambda_endpoints : e.api_path => e }
}
resource "aws_api_gateway_resource" "gateway_resource" {
for_each = local.lambda_endpoints_by_path
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
parent_id = aws_api_gateway_rest_api.api_gateway.root_resource_id
path_part = each.value.api_path
}
resource "aws_api_gateway_method" "gateway_method" {
for_each = local.lambda_endpoints_by_path
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
resource_id = aws_api_gateway_resource.gateway_resource[each.key].id
http_method = each.value.method
authorization = "COGNITO_USER_POOLS"
authorizer_id = aws_api_gateway_authorizer.authorizer.id
authorization_scopes = each.value.scopes
}
resource "aws_api_gateway_method_response" "gateway_response_200" {
for_each = local.lambda_endpoints_by_path
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
resource_id = aws_api_gateway_resource.gateway_resource[each.key].id
http_method = aws_api_gateway_method.gateway_method[each.key].http_method
status_code = "200"
}
resource "aws_api_gateway_integration_response" "integration_response" {
for_each = local.lambda_endpoints_by_path
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
resource_id = aws_api_gateway_resource.gateway_resource[each.key].id
http_method = aws_api_gateway_method.gateway_method[each.key].http_method
status_code = aws_api_gateway_method_response.gateway_response_200[each.key].status_code
}
resource "aws_api_gateway_integration" "proxy_integration" {
for_each = local.lambda_endpoints_by_path
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
resource_id = aws_api_gateway_resource.gateway_resource[each.key].id
http_method = each.value.method
integration_http_method = each.value.method
uri = "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${each.value.lambda_arn}:$${stageVariables.env}/invocations"
type = "AWS_PROXY"
}
var.lambda_endpoints
是一个对象列表,其中包含有关每个 lambda 端点的相关信息。
当它失败时,这是错误:
Error: Error creating API Gateway Integration: NotFoundException: Invalid Method identifier specified
Error: Error creating API Gateway Integration Response: NotFoundException: Invalid Integration identifier specified
当它失败时,第一次重新运行会清除创建集成的错误,第二次会清除创建集成响应的错误。terraform 在第一遍时没有弄清楚构建顺序是否有原因?如何避免这些重建步骤?
解决方案
推荐阅读
- notepad++ - 防止 np++ 用户定义语言中的单撇号着色
- java - 如何在另一个 Activity 中将值从 TextView 发送到 RecyclerView
- python - 'dict' 对象没有属性 'driver'
- authentication - 如何使用 Keycloak 保护前端和 REST API
- c# - 绘制矩形覆盖现有位图 c#
- assembly - 子程序被执行两次 [emu8086]
- flutter - Start slide-in animation on button press flutter
- python - 检测/删除职位发布中的样板文本 [Python]?
- javascript - 获取数据并使用状态挂钩
- java - Selenium 测试返回与 chrome 和 egde 相同的错误 java.net.SocketException