我有一个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
,我希望有一个通用的模板并在所有资源中重用。
为什么我会收到此错误?