I’m creating a REST api gateway resource (not a terraform resource). This requires the creation of five different terraform resources:
- *aws_api_gateway_resource
- *aws_api_gateway_method
- *aws_api_gateway_integration
- *aws_api_gateway_integration_response
- *aws_api_gateway_method_response
This is the code I have for creating the resources via iterating over a map of objects:
# Resources and Method Response with Object Variables
resource "aws_api_gateway_resource" "resource" {
for_each = var.resources
path_part = each.key #apigw_path_parts
rest_api_id = aws_api_gateway_rest_api.iddw.id
parent_id = aws_api_gateway_rest_api.iddw.root_resource_id
}
resource "aws_api_gateway_method" "method" {
for_each = var.resources
rest_api_id = aws_api_gateway_rest_api.iddw.id
resource_id = aws_api_gateway_resource.resource[each.key].id
http_method = each.value["http_method"]
authorization = each.value["authorization_type"]
request_models = try(each.value.request_models, {})
request_parameters = each.value.request_parameters
}
resource "aws_api_gateway_integration" "integration" {
for_each = var.resources
rest_api_id = aws_api_gateway_rest_api.iddw.id
resource_id = aws_api_gateway_resource.resource[each.key].id #aws_api_gateway_resource.id
http_method = each.value.http_method
integration_http_method = each.value.integration_http_method
type = each.value.integration_type
connection_type = each.value.integration_conn_type
#connection_id (Optional) ID of the VpcLink used for the integration. Required if connection_type is VPC_LINK
uri = each.value.integration_uri
#credentials
request_templates = try(each.value.integration_request_templates, {})
request_parameters = each.value.integration_request_parameters
}
resource "aws_api_gateway_integration_response" "integration_response" {
for_each = var.resources
rest_api_id = aws_api_gateway_rest_api.iddw.id
resource_id = aws_api_gateway_resource.resource[each.key].id #aws_api_gateway_resource.id
http_method = each.value.integration_http_method
status_code = each.value.integration_response_status_code
content_handling = try(each.value.integration_response_content_handling, null) #unused resource
response_parameters = try(each.value.integration_response_response_parameters, {})
response_templates = try(each.value.integration_response_templates, {})
selection_pattern = try(each.value.integration_response_selection_pattern, "")
}
resource "aws_api_gateway_method_response" "method_response" {
for_each = var.resources
rest_api_id = aws_api_gateway_rest_api.iddw.id
resource_id = aws_api_gateway_resource.resource[each.key].id #aws_api_gateway_resource.id
http_method = each.value.http_method
status_code = each.value.method_response_status_code
response_models = each.value.response_models
}
Input variable:
variable "resources" {
type = map(object({
path_part = string,
http_method = string,
authorization_type = string
api_key_required = bool,
request_parameters = map(string)
method_response_status_code = string,
response_models = map(string)
integration_type = string,
integration_http_method = string,
integration_uri = string,
integration_conn_type = string,
integration_request_parameters = map(string),
integration_passthru = string,
integration_timeout = string,
integration_cache_namespace = string
integration_response = map(string)
integration_response_status_code = string,
}))
}
This is the error it’s throwing ONLY when doing a full deploy from scratch:
╷
│ Error: creating API Gateway Integration: NotFoundException: Invalid Method identifier specified
│
│ with module.susig_gw.aws_api_gateway_integration.integration["axnadmin-token"],
│ on api-gateway/main.tf line 59, in resource "aws_api_gateway_integration" "integration":
│ 59: resource "aws_api_gateway_integration" "integration" {
│
╵
╷
│ Error: creating API Gateway Integration: NotFoundException: Invalid Method identifier specified
│
│ with module.susig_gw.aws_api_gateway_integration.integration["otp"],
│ on api-gateway/main.tf line 59, in resource "aws_api_gateway_integration" "integration":
│ 59: resource "aws_api_gateway_integration" "integration" {
│
╵
╷
│ Error: putting API Gateway Integration Response: NotFoundException: Invalid Method identifier specified
│
│ with module.susig_gw.aws_api_gateway_integration_response.integration_response["axnadmin-token"],
│ on api-gateway/main.tf line 75, in resource "aws_api_gateway_integration_response" "integration_response":
│ 75: resource "aws_api_gateway_integration_response" "integration_response" {
│
╵
╷
│ Error: putting API Gateway Integration Response: NotFoundException: Invalid Method identifier specified
│
│ with module.susig_gw.aws_api_gateway_integration_response.integration_response["otp"],
│ on api-gateway/main.tf line 75, in resource "aws_api_gateway_integration_response" "integration_response":
│ 75: resource "aws_api_gateway_integration_response" "integration_response" {
│
╵
╷
│ Error: creating API Gateway Method Response: NotFoundException: Invalid Method identifier specified
│
│ with module.susig_gw.aws_api_gateway_method_response.method_response["otp"],
│ on api-gateway/main.tf line 88, in resource "aws_api_gateway_method_response" "method_response":
│ 88: resource "aws_api_gateway_method_response" "method_response" {
It’s the same issue folks are experiencing over at this git issue, but it hasn’t been addressed. I thought i might try my luck here.