Amazon web services terraform aws\u api\u网关\u方法\u设置引发冲突异常

Amazon web services terraform aws\u api\u网关\u方法\u设置引发冲突异常,amazon-web-services,terraform,aws-api-gateway,Amazon Web Services,Terraform,Aws Api Gateway,我正在尝试使用terraform为API的一些端点配置API网关缓存 问题是,当我创建多个aws\u api\u gateway\u method\u设置时,我得到了一个ConflictException 这是我的密码 locals { endpoint_ttl = { "adresse/GET" = 60 * 60 * 24 * 20 "adresse/ean/GET"

我正在尝试使用terraform为API的一些端点配置API网关缓存

问题是,当我创建多个aws\u api\u gateway\u method\u设置时,我得到了一个ConflictException

这是我的密码

locals {
  endpoint_ttl = {
    "adresse/GET"                   = 60 * 60 * 24 * 20
    "adresse/ean/GET"               = 60 * 60 * 24 * 20
    "adresse/services/GET"          = 60 * 60 * 24 * 20
    "ep/GET"                        = 60 * 15
    "pannes/planned/*"              = 60 * 60 * 4
    "pannes/unplanned/*"            = 60 * 60 * 4
    "pannes/{Id}/*"                 = 60 * 15
    "ean/GET"                       = 60 * 60 * 24
    "ean/cpt/GET"                   = 60 * 60 * 24
    "ean/{Ean}/GET"                 = 60 * 60 * 24
    "index/GET"                     = 60 * 60 * 24
    "index/passage/GET"             = 60 * 60 * 24
    "index/{MeterId}/GET"           = 60 * 60 * 24
    "demande_travaux/{Id}/GET"      = 60 * 60 * 24
    "delestage/pour_adresse/GET"    = 60 * 60 * 24
    "cab/point_rechargement/GET"    = 60 * 60 * 24
    "facturation/balance/GET"       = 60 * 60
    "facturation/factures/GET"      = 60 * 60
    "facturation/attestation/GET"   = 60 * 60
    "facturation/contrats/{Id}/GET" = 60 * 60
    "facturation/devis/GET"         = 60 * 60
    "jobs/GET"                      = 60 * 60
    "demande_travaux/*"             = 60 * 60
  }
}


resource "aws_api_gateway_method_settings" "settings" {
  depends_on = [aws_api_gateway_stage.MyAPI_Stage]
  for_each   = local.endpoint_ttl

  rest_api_id = data.aws_api_gateway_rest_api.MyAPI.id
  stage_name  = local.workspace["api_stage"]
  method_path = each.key

  settings {
    caching_enabled                         = true
    cache_ttl_in_seconds                    = min(each.value, 3600)
    require_authorization_for_cache_control = false
  }
}
这是我丢了6次

Error: Updating API Gateway Stage failed: ConflictException: Unable to complete operation due to concurrent modification. Please try again later.

  on terraform/caching.tf line 30, in resource "aws_api_gateway_method_settings" "settings":
  30: resource "aws_api_gateway_method_settings" "settings" {
我可以多次运行
terraformapply
来解决这个问题,但这是不可接受的

如果我只创建2-3个资源,我就不会有这个问题,这让我觉得资源的数量向AWS发送了太多的请求

我尝试手动创建所有这些资源(不使用for_和depends_-on链接),但仍然出现相同的错误

所以我的问题是:如何创建所有这些aws\u api\u gateway\u方法\u设置资源,运行
terraform apply
仅一次?


感谢您的帮助

您是否尝试过其他方法-使舞台依赖于方法设置?它应该告诉
terraform
在方法设置更新完成后更新stage。我尝试了很多东西-我无法在stage之前创建设置,在这种情况下,我收到一个
错误:更新API网关阶段失败:NotFoundException:指定的阶段标识符无效
我认为您无法通过本机Terraform绕过这个明显的AWS API限制。我们确实需要一个特性,用于添加延迟,并且在使用每个或计数时控制并行性。