Terraform 无法将 API 网关更改部署到多个阶段中的一个阶段?

Terraform can't deploy API Gateway changes to one stage out of many?

使用此代码:

resource "aws_api_gateway_deployment" "example_deployment" {
  depends_on = [
    "aws_api_gateway_method.example_api_method",
    "aws_api_gateway_integration.example_api_method_integration"
  ]
  rest_api_id = "${aws_api_gateway_rest_api.example_api.id}"
  stage_name = "${var.stage_name}"
}

我可以将 API 网关更改部署到我指定的任何阶段。但是,这将覆盖任何现有阶段。也就是说,如果我首先部署到一个名为 'dev' 的阶段,然后部署到 'prod',它将擦除 'dev'。

如何实现多阶段部署?这样我就可以先部署到 dev 或 staging,如果一切看起来不错,然后再部署到 prod 阶段。

经过一些研究,我们最终采取了不同的策略。基于 this and this, we split our terraform into folders per stage. So if you want to deploy dev, you run terraform inside the dev folder. To avoid code duplication, you use modules 等文章。它似乎运行良好,并允许我们部署不同版本的 API。