gpt4 book ai didi

amazon-web-services - Terraform 破坏 API 网关且 VPC 链接失败

转载 作者:行者123 更新时间:2023-12-02 19:59:01 25 4
gpt4 key购买 nike

设置

  • Terraform v 0.11.14
  • 用于定义 API 网关主体的 OpenAPI 规范 3.0

地形资源

我创建了一个私有(private) API 网关,它通过 VPC 链接将流量路由到 NLB。我已经部署了 API,但为了简洁起见,我在下面省略了该资源,因为它很琐碎。

resource "aws_api_gateway_rest_api" "this" {
name = "MyAPI"
body = "${file("./api-spec.yaml")}"

endpoint_configuration {
types = ["PRIVATE"]
}
}

resource "aws_lb" "app" {
name = "MyNLB"
internal = true
load_balancer_type = "network"
subnets = ["MySubnetIds"]
}

resource "aws_api_gateway_vpc_link" "nlb" {
name = "api-gateway-to-nlb"
target_arns = ["${aws_lb.app.arn}"]
}

api-spec.yaml 文件中引用了 VPC 链接。相关部分是:

paths:
/items:
get:
summary: Gets a collection of items
responses:
'200':
description: Ok
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Item'
x-amazon-apigateway-integration:
type: http_proxy
httpMethod: GET
uri: https://my-internal-nlb/api/v1/items
connectionType: "VPC_LINK"
connectionId: "${vpclink_id}"
responses:
default:
statusCode: '200'

问题

当我运行terraform destroy时,我收到以下消息:

Error: Error applying plan:

1 error occurred:
* aws_api_gateway_vpc_link.nlb (destroy): 1 error occurred:
* aws_api_gateway_vpc_link.nlb: error deleting API Gateway VPC Link (bgzpv1): BadRequestException: Cannot delete vpc link. Vpc link 'bgzpv1', is referenced in deployed stages [POST:50f55s:development, GET:50f55s:development] in format of [Method:Resource:Stage] and also in undeployed integration [GET:50f55s, POST:50f55s] in format of [Method:Resource]. status code: 400, request id: d9a9667b-8099-11e9-98d1-9f899674f4b9

如果我等待几分钟,然后再次运行 terraform destroy,以下资源将被销毁:

  • aws_lb.app
  • aws_api_gateway_vpc_link.nlb

我用谷歌搜索过,但找不到有关该主题的太多信息。有一个ticket raised在 AWS 支持论坛上,但这是不久前的事,AWS 表示他们将解决该问题

最佳答案

这个问题的实际答案与 @dtelaroli 提到的略有不同,我一直在研究问题可能是什么。

部署 API Gateway 后,它会内置到发行版中并推送到提供服务的 CloudFront。

如果您引用 VPC 链接,则该链接将内置到分配中并推送到 CloudFront。这就是为什么部署此API时,VPC链接无法被破坏。因为它正在实时 CloudFront 发行版中使用。

为了破坏VPC链接,您需要首先删除针对VPC链接的集成,然后再次部署API网关,这意味着您的API可能在这个阶段被破坏,但现在您将可以删除VPC链接。

此时,您应该能够销毁 API 网关,或以某种方式重建它,因为 CloudFront 不再包含与 VPC 链接的连接。

我无法想象如何通过使用空资源或类似的东西来编写脚本或将其构建到 terraform 中,但这就是问题发生的原因。

关于amazon-web-services - Terraform 破坏 API 网关且 VPC 链接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56329807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com