Terraform - response_parameters:应该是一张地图
Terraform - response_parameters: should be a map
我有一个用于 api_gateway
的 terraform 脚本,它工作正常。我有很多重复的模板。我想使用 "data" "template_file"
提取所有模板。
工作解决方案:
resource "aws_api_gateway_integration_response" "ApiResponse" {
//something goes here
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
"method.response.header.Access-Control-Allow-Methods" = "'GET,DELETE,PUT,OPTIONS'"
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
重构后:
resource "aws_api_gateway_integration_response" "ApiResponse" {
//something goes here
response_parameters = "${data.template_file.response_parameters.template}"
}
data "template_file" "response_parameters" {
template = "${file("${path.module}/response_parameters.tptl")}"
}
response_parameters.tptl:
{
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
"method.response.header.Access-Control-Allow-Methods" = "'GET,DELETE,PUT,OPTIONS'"
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
错误:
* aws_api_gateway_integration_response.ApiResponse: response_parameters: should be a map
由于响应参数对于我的所有 aws_api_gateway_integration_response
都是通用的,我希望有一个通用模板并在所有资源中重复使用。
为什么我会收到这个错误?
它正在使用 map
类型的 variable
而不是 "data" "template_file"
resource "aws_api_gateway_integration_response" "ApiResponse" {
//something goes here
response_parameters = "${var.integration_response_parameters}"
}
variable "integration_response_parameters" {
type = "map"
default = {
method.response.header.Access-Control-Allow-Headers = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Methods = "'GET,OPTIONS'"
method.response.header.Access-Control-Allow-Origin = "'*'"
}
}
我有一个用于 api_gateway
的 terraform 脚本,它工作正常。我有很多重复的模板。我想使用 "data" "template_file"
提取所有模板。
工作解决方案:
resource "aws_api_gateway_integration_response" "ApiResponse" {
//something goes here
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
"method.response.header.Access-Control-Allow-Methods" = "'GET,DELETE,PUT,OPTIONS'"
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
重构后:
resource "aws_api_gateway_integration_response" "ApiResponse" {
//something goes here
response_parameters = "${data.template_file.response_parameters.template}"
}
data "template_file" "response_parameters" {
template = "${file("${path.module}/response_parameters.tptl")}"
}
response_parameters.tptl:
{
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
"method.response.header.Access-Control-Allow-Methods" = "'GET,DELETE,PUT,OPTIONS'"
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
错误:
* aws_api_gateway_integration_response.ApiResponse: response_parameters: should be a map
由于响应参数对于我的所有 aws_api_gateway_integration_response
都是通用的,我希望有一个通用模板并在所有资源中重复使用。
为什么我会收到这个错误?
它正在使用 map
类型的 variable
而不是 "data" "template_file"
resource "aws_api_gateway_integration_response" "ApiResponse" {
//something goes here
response_parameters = "${var.integration_response_parameters}"
}
variable "integration_response_parameters" {
type = "map"
default = {
method.response.header.Access-Control-Allow-Headers = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Methods = "'GET,OPTIONS'"
method.response.header.Access-Control-Allow-Origin = "'*'"
}
}