Terraform 在aws\U api\U gateway\U gateway\U响应中设置字段状态\U代码的默认值

Terraform 在aws\U api\U gateway\U gateway\U响应中设置字段状态\U代码的默认值,terraform,terraform-provider-aws,Terraform,Terraform Provider Aws,我正在尝试修改api网关错误响应的模板。以下是AWS API网关中可能出现的错误情况 REQUEST_TOO_LARGE RESOURCE_NOT_FOUND AUTHORIZER_CONFIGURATION_ERROR MISSING_AUTHENTICATION_TOKEN BAD_REQUEST_BODY INVALID_SIGNATURE INVALID_API_KEY BAD_REQUEST_PARAMETERS AUTHORIZER_FAILURE UNAUTHORIZED INTE

我正在尝试修改api网关错误响应的模板。以下是AWS API网关中可能出现的错误情况

REQUEST_TOO_LARGE
RESOURCE_NOT_FOUND
AUTHORIZER_CONFIGURATION_ERROR
MISSING_AUTHENTICATION_TOKEN
BAD_REQUEST_BODY
INVALID_SIGNATURE
INVALID_API_KEY
BAD_REQUEST_PARAMETERS
AUTHORIZER_FAILURE
UNAUTHORIZED
INTEGRATION_TIMEOUT
ACCESS_DENIED
DEFAULT_4XX
DEFAULT_5XX
WAF_FILTERED
QUOTA_EXCEEDED
THROTTLED
API_CONFIGURATION_ERROR
UNSUPPORTED_MEDIA_TYPE
INTEGRATION_FAILURE
EXPIRED_TOKEN
这是我的资源

resource "aws_api_gateway_gateway_response" "api_gateway_response" {
  count         = length(var.api_gateway_response_types)
  rest_api_id   = aws_api_gateway_rest_api.api_gateway.id
  response_type = element(values(var.api_gateway_response_types), count.index) 

  response_templates = {
    "application/json" = "{\"errors\": [{\"errorCode\": \"${element(keys(var.api_gateway_response_types), count.index)}\", \"message\": $context.error.messageString}]}"
  }
}
在这里,我只想更改响应模板,并保持
状态\u code
不变<代码>状态代码是资源
aws\u api\u gateway\u gateway\u响应的可选字段
,但如果您未通过状态代码,它将在
地形平面图中显示为状态代码正在更改

所以每次你检查
地形平面图
。它将显示如下:

# aws_api_gateway_gateway_response.api_gateway_response[0] will be updated in-place
  ~ resource "aws_api_gateway_gateway_response" "api_gateway_response" {
        id                  = "aggr-gohnlccgwh-REQUEST_TOO_LARGE"
        response_parameters = {}
        response_templates  = {
            "application/json" = "{\"errors\": [{\"errorCode\": \"4001\", \"message\": $context.error.messageString}]}"
        }
        response_type       = "REQUEST_TOO_LARGE"
        rest_api_id         = "gohnlccgwh"
      - status_code         = "413" -> null
    }
  # aws_api_gateway_gateway_response.api_gateway_response[1] will be updated in-place
  ~ resource "aws_api_gateway_gateway_response" "api_gateway_response" {
        id                  = "aggr-gohnlccgwh-RESOURCE_NOT_FOUND"
        response_parameters = {}
        response_templates  = {
            "application/json" = "{\"errors\": [{\"errorCode\": \"4002\", \"message\": $context.error.messageString}]}"
        }
        response_type       = "RESOURCE_NOT_FOUND"
        rest_api_id         = "gohnlccgwh"
      - status_code         = "404" -> null
    }
resource "aws_api_gateway_gateway_response" "api_gateway_response" {
  count         = length(var.api_gateway_response_types)
  rest_api_id   = aws_api_gateway_rest_api.api_gateway.id
  response_type = element(values(var.api_gateway_response_types), count.index)
  status_code = aws_api_gateway_gateway_response.api_gateway_response[count.index].status_code

  response_templates = {
    "application/json" = "{\"errors\": [{\"errorCode\": \"${element(keys(var.api_gateway_response_types), count.index)}\", \"message\": $context.error.messageString}]}"
  }
}
所以我想通过从API网关获取默认状态代码来设置它。所以我试了一下

# aws_api_gateway_gateway_response.api_gateway_response[0] will be updated in-place
  ~ resource "aws_api_gateway_gateway_response" "api_gateway_response" {
        id                  = "aggr-gohnlccgwh-REQUEST_TOO_LARGE"
        response_parameters = {}
        response_templates  = {
            "application/json" = "{\"errors\": [{\"errorCode\": \"4001\", \"message\": $context.error.messageString}]}"
        }
        response_type       = "REQUEST_TOO_LARGE"
        rest_api_id         = "gohnlccgwh"
      - status_code         = "413" -> null
    }
  # aws_api_gateway_gateway_response.api_gateway_response[1] will be updated in-place
  ~ resource "aws_api_gateway_gateway_response" "api_gateway_response" {
        id                  = "aggr-gohnlccgwh-RESOURCE_NOT_FOUND"
        response_parameters = {}
        response_templates  = {
            "application/json" = "{\"errors\": [{\"errorCode\": \"4002\", \"message\": $context.error.messageString}]}"
        }
        response_type       = "RESOURCE_NOT_FOUND"
        rest_api_id         = "gohnlccgwh"
      - status_code         = "404" -> null
    }
resource "aws_api_gateway_gateway_response" "api_gateway_response" {
  count         = length(var.api_gateway_response_types)
  rest_api_id   = aws_api_gateway_rest_api.api_gateway.id
  response_type = element(values(var.api_gateway_response_types), count.index)
  status_code = aws_api_gateway_gateway_response.api_gateway_response[count.index].status_code

  response_templates = {
    "application/json" = "{\"errors\": [{\"errorCode\": \"${element(keys(var.api_gateway_response_types), count.index)}\", \"message\": $context.error.messageString}]}"
  }
}
在这里,我试图设置当前代码
status\u code=aws\u api\u gateway\u gateway\u response.api\u gateway\u response[count.index]。status\u code
。但这导致了周期误差

Error: Cycle: aws_api_gateway_gateway_response.api_gateway_response[16], aws_api_gateway_gateway_response.api_gateway_response[12], aws_api_gateway_gateway_response.api_gateway_response[11], aws_api_gateway_gateway_response.api_gateway_response[7], aws_api_gateway_gateway_response.api_gateway_response[19], aws_api_gateway_gateway_response.api_gateway_response[3], aws_api_gateway_gateway_response.api_gateway_response[9], aws_api_gateway_gateway_response.api_gateway_response[18], aws_api_gateway_gateway_response.api_gateway_response[10], aws_api_gateway_gateway_response.api_gateway_response[13], aws_api_gateway_gateway_response.api_gateway_response[14], aws_api_gateway_gateway_response.api_gateway_response[17], aws_api_gateway_gateway_response.api_gateway_response[0], aws_api_gateway_gateway_response.api_gateway_response[15], aws_api_gateway_gateway_response.api_gateway_response[8], aws_api_gateway_gateway_response.api_gateway_response[1], aws_api_gateway_gateway_response.api_gateway_response[2], aws_api_gateway_gateway_response.api_gateway_response[20], aws_api_gateway_gateway_response.api_gateway_response[4], aws_api_gateway_gateway_response.api_gateway_response[6], aws_api_gateway_gateway_response.api_gateway_response[5]
有人能帮我吗