【问题标题】:Terraform error creating API Gateway Resource complains another resource with the same parent already has this name创建 API 网关资源的 Terraform 错误抱怨具有相同父级的另一个资源已经具有此名称
【发布时间】:2021-05-25 04:03:25
【问题描述】:

我正在创建一个名为“lang”的 API 网关资源:

resource "aws_api_gateway_resource" "lang" {
  path_part   = "lang"
  parent_id   = aws_api_gateway_resource.api.id
  rest_api_id = aws_api_gateway_rest_api.root_api.id
}

成功创建 API 后,在后续运行 terraform apply 时,我收到此错误:

Error: Error creating API Gateway Resource: ConflictException: Another resource with the same parent already has this name: lang

上面的资源块绝对是唯一一个具有该名称的资源块。我已经对此进行了足够的谷歌搜索,以意识到 terraform 抱怨称为“lang”的资源已经存在并且无法重新创建。我不知道如何先将其销毁。

我已尝试将此添加到我的脚本中:

resource "aws_api_gateway_deployment" "deployment" {
  rest_api_id   = aws_api_gateway_rest_api.root_api.id
  stage_name    = var.envName
  
  triggers = {
    redeployment = sha1(jsonencode(aws_api_gateway_rest_api.root_api.body))
  }

  lifecycle {
    create_before_destroy = true
  }
}

...无济于事。

create_before_destroy 属性不应该从本质上破坏 API 并导致它被重新创建还是只是舞台?

如果资源块无法更改“lang”资源,我该如何更改?这对我来说似乎是一个基本的循环问题。

【问题讨论】:

  • 为什么lang API 资源(不是 TF 资源)已经存在?您是使用 AWS 控制台/cli/sdk 手动创建的吗?
  • 在顶部附近我说过“在运行 terraform 时应用后续时间”。这意味着它是在我第一次运行应用程序时创建的。似乎无法在以下申请中更改。

标签: terraform aws-api-gateway terraform-provider-aws


【解决方案1】:

令人讨厌的是,这是一个深夜的错字...

我(故意)复制粘贴了 resource "aws_api_gateway_resource" "lang" 块,但在浏览和更新所有副本时忘记重命名副本。

【讨论】:

    猜你喜欢
    • 2018-07-09
    • 2020-08-08
    • 2011-03-29
    • 2020-10-09
    • 2021-01-03
    • 2020-04-16
    相关资源
    最近更新 更多