api网关集成响应设置在使用相同代码应用第二个terraform后被删除
我正在尝试使用terraform在AWSAPI网关中创建RESTAPI 为了启用CORS,在我的tf代码中准备了选项方法和相关的集成设置。当我第一次做“地形规划”->“地形应用”时,它工作得很好。在AWS管理控制台中检查时,我发现在我编写时创建了一个选项方法 但是,当我第二次执行“terraform plan”->“terraform apply”时,API网关没有任何更改,Option method的集成响应设置被删除,即使应用已完成。(“删除”表示所有集成响应都从管理控制台消失) 这是正常的行为吗?我的地形代码是否需要其他设置 我目前的代码如下:api网关集成响应设置在使用相同代码应用第二个terraform后被删除,terraform,aws-api-gateway,Terraform,Aws Api Gateway,我正在尝试使用terraform在AWSAPI网关中创建RESTAPI 为了启用CORS,在我的tf代码中准备了选项方法和相关的集成设置。当我第一次做“地形规划”->“地形应用”时,它工作得很好。在AWS管理控制台中检查时,我发现在我编写时创建了一个选项方法 但是,当我第二次执行“terraform plan”->“terraform apply”时,API网关没有任何更改,Option method的集成响应设置被删除,即使应用已完成。(“删除”表示所有集成响应都从管理控制台消失) 这是正常的
resource "aws_api_gateway_resource" "my_api_resource" {
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
parent_id = "${aws_api_gateway_rest_api.my_api.root_resource_id}"
path_part = "my_api_resource"
}
resource "aws_api_gateway_method" "my_api_method" {
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "integration_request" {
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "${aws_api_gateway_method.my_api_method.http_method}"
integration_http_method = "POST"
type = "AWS"
uri = "${var.my_lambda_invocation_arn}"
}
resource "aws_api_gateway_method_response" "http_status_value" {
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "${aws_api_gateway_method.my_api_method.http_method}"
status_code = "200"
response_models = {
"application/json" = "Empty"
}
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
}
resource "aws_api_gateway_integration_response" "integration_response" {
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "${aws_api_gateway_method.my_api_method.http_method}"
status_code = "${aws_api_gateway_method_response.http_status_value.status_code}"
response_templates = {
"application/json" = ""
}
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
### enable cors ###
resource "aws_api_gateway_method" "my_api_method_opt" {
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "OPTIONS"
authorization = "NONE"
api_key_required = false
}
resource "aws_api_gateway_integration" "integration_request_opt" {
depends_on = ["aws_api_gateway_method.my_api_method_opt"]
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "${aws_api_gateway_method.my_api_method_opt.http_method}"
integration_http_method = "OPTIONS"
type = "MOCK"
request_templates = {
"application/json" = "${file("./temp.txt")}"
}
}
resource "aws_api_gateway_method_response" "method_response_opt_200" {
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "${aws_api_gateway_method.my_api_method_opt.http_method}"
status_code = "200"
response_models = {
"application/json" = "Empty"
}
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = true,
"method.response.header.Access-Control-Allow-Methods" = true,
"method.response.header.Access-Control-Allow-Origin" = true
}
depends_on = ["aws_api_gateway_method.my_api_method_opt"]
}
resource "aws_api_gateway_integration_response" "integration_response_opt_200" {
depends_on = ["aws_api_gateway_method.my_api_method_opt", "aws_api_gateway_method_response.method_response_opt_200"]
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
resource_id = "${aws_api_gateway_resource.my_api_resource.id}"
http_method = "${aws_api_gateway_method.my_api_method_opt.http_method}"
status_code = "${aws_api_gateway_method_response.method_response_opt_200.status_code}"
response_templates = {
"application/json" = ""
}
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,OPTIONS'",
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
resource "aws_api_gateway_deployment" "my_api_deploy" {
depends_on = ["aws_api_gateway_integration_response.integration_response","aws_api_gateway_integration.integration_request", "aws_api_gateway_integration.integration_request_opt","aws_api_gateway_integration_response.integration_response_opt_200"]
rest_api_id = "${aws_api_gateway_rest_api.my_api.id}"
stage_name = "dev"
}
我不知道这对这个问题是否至关重要,我正在使用s3 bucket和dynamoDB来保存tfstate和状态锁。在
模拟上使用集成请求方法
,集成会导致某种形式的冲突,尝试删除该字段,因为它不是必需的在MOCK
集成上似乎有集成请求方法
会导致某种形式的冲突,尝试删除该字段,因为它不是必需的