|
| 1 | +locals { |
| 2 | + mock_200_response = file("${path.module}/nrl_mock_responses/200_response.json") |
| 3 | + mock_400_response = file("${path.module}/nrl_mock_responses/400_response.json") |
| 4 | + mock_401_response = file("${path.module}/nrl_mock_responses/401_response.json") |
| 5 | + mock_403_response = file("${path.module}/nrl_mock_responses/403_response.json") |
| 6 | + mock_404_response = file("${path.module}/nrl_mock_responses/404_response.json") |
| 7 | +} |
| 8 | + |
| 9 | +resource "aws_api_gateway_resource" "nrl_sandbox" { |
| 10 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 11 | + parent_id = aws_api_gateway_rest_api.ndr_doc_store_api.root_resource_id |
| 12 | + path_part = "sandbox" |
| 13 | +} |
| 14 | + |
| 15 | +resource "aws_api_gateway_resource" "sandbox_get_document_reference" { |
| 16 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 17 | + parent_id = aws_api_gateway_resource.nrl_sandbox.id |
| 18 | + path_part = "DocumentReference" |
| 19 | +} |
| 20 | + |
| 21 | +resource "aws_api_gateway_resource" "sandbox_get_document_reference_path_parametre" { |
| 22 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 23 | + parent_id = aws_api_gateway_resource.sandbox_get_document_reference.id |
| 24 | + path_part = "{id}" |
| 25 | +} |
| 26 | + |
| 27 | +resource "aws_api_gateway_method" "sandbox_get_document_reference" { |
| 28 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 29 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 30 | + http_method = "GET" |
| 31 | + authorization = "NONE" |
| 32 | + api_key_required = true |
| 33 | + request_parameters = { |
| 34 | + "method.request.path.id" = true |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +resource "aws_api_gateway_integration" "get_document_reference_mock_integration" { |
| 40 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 41 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 42 | + type = "MOCK" |
| 43 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 44 | + request_templates = { |
| 45 | + "application/json" = <<EOF |
| 46 | + { |
| 47 | + #if ( $input.params('id') == '16521000000101~f9ed81db-f90a-42d4-b7e4-d554d8f338fd' ) |
| 48 | + "statusCode": 200 |
| 49 | + #elseif ( $input.params('id') == '400' ) |
| 50 | + "statusCode": 400 |
| 51 | + #elseif ( $input.params('id') == '401' ) |
| 52 | + "statusCode": 401 |
| 53 | + #elseif ( $input.params('id') == '403' ) |
| 54 | + "statusCode": 403 |
| 55 | + #elseif ( $input.params('id') == '404' ) |
| 56 | + "statusCode": 404 |
| 57 | + #end |
| 58 | + } |
| 59 | + EOF |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +resource "aws_api_gateway_method_response" "response_200" { |
| 64 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 65 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 66 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 67 | + status_code = "200" |
| 68 | +} |
| 69 | + |
| 70 | +resource "aws_api_gateway_integration_response" "get_documenet_reference_mock_200_response" { |
| 71 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 72 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 73 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 74 | + status_code = aws_api_gateway_method_response.response_200.status_code |
| 75 | + selection_pattern = "200" |
| 76 | + response_templates = { |
| 77 | + "application/json" = local.mock_200_response |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +resource "aws_api_gateway_method_response" "response_400" { |
| 82 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 83 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 84 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 85 | + status_code = "400" |
| 86 | +} |
| 87 | + |
| 88 | +resource "aws_api_gateway_integration_response" "get_documenet_reference_mock_400_response" { |
| 89 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 90 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 91 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 92 | + status_code = aws_api_gateway_method_response.response_400.status_code |
| 93 | + selection_pattern = "400" |
| 94 | + response_templates = { |
| 95 | + "application/json" = local.mock_400_response |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +resource "aws_api_gateway_method_response" "response_401" { |
| 100 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 101 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 102 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 103 | + status_code = "401" |
| 104 | +} |
| 105 | + |
| 106 | +resource "aws_api_gateway_integration_response" "get_documenet_reference_mock_401_response" { |
| 107 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 108 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 109 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 110 | + status_code = aws_api_gateway_method_response.response_401.status_code |
| 111 | + selection_pattern = "401" |
| 112 | + response_templates = { |
| 113 | + "application/json" = local.mock_401_response |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +resource "aws_api_gateway_method_response" "response_403" { |
| 118 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 119 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 120 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 121 | + status_code = "403" |
| 122 | +} |
| 123 | + |
| 124 | +resource "aws_api_gateway_integration_response" "get_documenet_reference_mock_403_response" { |
| 125 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 126 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 127 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 128 | + status_code = aws_api_gateway_method_response.response_403.status_code |
| 129 | + selection_pattern = "403" |
| 130 | + response_templates = { |
| 131 | + "application/json" = local.mock_403_response |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +resource "aws_api_gateway_method_response" "response_404" { |
| 136 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 137 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 138 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 139 | + status_code = "404" |
| 140 | +} |
| 141 | + |
| 142 | +resource "aws_api_gateway_integration_response" "get_documenet_reference_mock_404_response" { |
| 143 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 144 | + resource_id = aws_api_gateway_resource.sandbox_get_document_reference_path_parametre.id |
| 145 | + http_method = aws_api_gateway_method.sandbox_get_document_reference.http_method |
| 146 | + status_code = aws_api_gateway_method_response.response_404.status_code |
| 147 | + selection_pattern = "404" |
| 148 | + response_templates = { |
| 149 | + "application/json" = local.mock_404_response |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | + |
0 commit comments