Newcomer to the AWS computing using terraform
I have two files for declaring an AWS API Gateway and it fails when trying to deploy using gitlab ci, especially when it is treating the generated module
Error: Error creating API Gateway Method Response: BadRequestException: Invalid model identifier specified: Empty
│
│ with module.corslambdaApiHelloWorld.aws_api_gateway_method_response._,
│ on .terraform/modules/corslambdaApiHelloWorld/main.tf line 63, in resource "aws_api_gateway_method_response" "_":
│ 63: resource "aws_api_gateway_method_response" "_" {
Here is the file that generates that module:
// https://domain/{base}/helloworld
resource "aws_api_gateway_resource" "ApiResourceHelloWorld" {
rest_api_id = aws_api_gateway_rest_api.Api.id
parent_id = aws_api_gateway_rest_api.Api.root_resource_id
path_part = "helloworld"
}
module "corslambdaApiHelloWorld" {
source = "squidfunk/api-gateway-enable-cors/aws"
version = "0.3.3"
api_id = aws_api_gateway_rest_api.Api.id
api_resource_id = aws_api_gateway_resource.ApiResourceHelloWorld.id
allow_methods = ["GET"]
}
And here is the resource generated in the module file when I use terraform init in my local workspace
resource "aws_api_gateway_method_response" "_" {
rest_api_id = var.api_id
resource_id = var.api_resource_id
http_method = aws_api_gateway_method._.http_method
status_code = 200
response_parameters = local.method_response_parameters
response_models = {
"application/json" = "Empty"
}
depends_on = [
aws_api_gateway_method._,
]
}
We have already tried declaring a resource using this method, but from the deployment process, it still generates the response_models with the same value
We have verified similar projects by using terraform init into their terraform codes, and it generates something similar as the modules
But those projects are deployed properly, unlike ours
Notes:
- using
terraform planin my workspace does not generate any error - the lambda function attached to the API was deployed succesfully and is available when browsing the AWS console
- in the gitlab job console, this output is present:
# module.corslambdaApiHelloWorld.aws_api_gateway_method_response._ will be created
+ resource "aws_api_gateway_method_response" "_" {
+ http_method = "OPTIONS"
+ id = (known after apply)
+ resource_id = "m3aimb"
+ 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
+ "method.response.header.Access-Control-Max-Age" = true
}
+ rest_api_id = "7ptzpas417"
+ status_code = "200"
}
I mainly want to know what is supposed to be generated in that module for the build to pass
Additional note asked from comments:
- The dockerfile used by gitlab-ci is using
terraform_1.0.0_linux_amd64installed usingwget - Tried using
hashicorp/aws v3.75.0locally, getting the same error onterraform applycommand
required_providershashicorp/archive, hashicorp/aws and hashicorp/random withrequired_version = ">= 0.13"3.x.xrange and see if that will work. Version 4 of the provider introduced breaking changes (not sure if any of it is related to API Gateway though).