|
| 1 | +resource "aws_api_gateway_rest_api" "panda" { |
| 2 | + name = "panda" |
| 3 | +} |
| 4 | + |
| 5 | +resource "aws_api_gateway_resource" "healthcheck" { |
| 6 | + parent_id = aws_api_gateway_rest_api.panda.root_resource_id |
| 7 | + path_part = "healthcheck" |
| 8 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 9 | +} |
| 10 | + |
| 11 | +resource "aws_api_gateway_method" "panda1" { |
| 12 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 13 | + resource_id = aws_api_gateway_resource.healthcheck.id |
| 14 | + http_method = "POST" |
| 15 | + authorization = "NONE" |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +resource "aws_api_gateway_integration" "integration" { |
| 21 | + |
| 22 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 23 | + resource_id = aws_api_gateway_resource.healthcheck.id |
| 24 | + http_method = aws_api_gateway_method.panda1.http_method |
| 25 | + type = "MOCK" |
| 26 | + |
| 27 | + request_parameters = { |
| 28 | + "integration.request.header.X-Authorization" = "'static'" |
| 29 | + } |
| 30 | + |
| 31 | + # Transforms the incoming XML request to JSON |
| 32 | + request_templates = { |
| 33 | + "application/xml" = <<EOF |
| 34 | +{ |
| 35 | + |
| 36 | + "statusCode" : 200, |
| 37 | + "message" : "Healthy" |
| 38 | +} |
| 39 | +EOF |
| 40 | + } |
| 41 | +} |
| 42 | +resource "aws_api_gateway_method_response" "response_200" { |
| 43 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 44 | + resource_id = aws_api_gateway_resource.healthcheck.id |
| 45 | + http_method = aws_api_gateway_method.panda1.http_method |
| 46 | + status_code = "200" |
| 47 | +} |
| 48 | + |
| 49 | +resource "aws_api_gateway_integration_response" "MyDemoIntegrationResponse" { |
| 50 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 51 | + resource_id = aws_api_gateway_resource.healthcheck.id |
| 52 | + http_method = aws_api_gateway_method.panda1.http_method |
| 53 | + status_code = aws_api_gateway_method_response.response_200.status_code |
| 54 | + # Transforms the backend JSON response to XML |
| 55 | + response_templates = { |
| 56 | + "application/xml" = <<EOF |
| 57 | +#set($inputRoot = $input.path('$')) |
| 58 | +<?xml version="1.0" encoding="UTF-8"?> |
| 59 | +<message> |
| 60 | + $inputRoot.body |
| 61 | +</message> |
| 62 | +EOF |
| 63 | + } |
| 64 | +} |
| 65 | +resource "aws_api_gateway_deployment" "panda1" { |
| 66 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 67 | + |
| 68 | + triggers = { |
| 69 | + |
| 70 | + redeployment = sha1(jsonencode([ |
| 71 | + aws_api_gateway_resource.healthcheck.id, |
| 72 | + aws_api_gateway_method.panda1.id, |
| 73 | + aws_api_gateway_integration.integration.id, |
| 74 | + ])) |
| 75 | + } |
| 76 | + |
| 77 | + lifecycle { |
| 78 | + create_before_destroy = true |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +resource "aws_api_gateway_resource" "panda" { |
| 83 | + parent_id = aws_api_gateway_rest_api.panda.root_resource_id |
| 84 | + path_part = "panda" |
| 85 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 86 | +} |
| 87 | + |
| 88 | +resource "aws_api_gateway_method" "panda" { |
| 89 | + authorization = "NONE" |
| 90 | + http_method = "GET" |
| 91 | + resource_id = aws_api_gateway_resource.panda.id |
| 92 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 93 | +} |
| 94 | +resource "aws_api_gateway_integration" "panda" { |
| 95 | + http_method = aws_api_gateway_method.panda.http_method |
| 96 | + resource_id = aws_api_gateway_resource.panda.id |
| 97 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 98 | + type = "MOCK" |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +resource "aws_api_gateway_deployment" "panda" { |
| 104 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 105 | + |
| 106 | + triggers = { |
| 107 | + |
| 108 | + redeployment = sha1(jsonencode([ |
| 109 | + aws_api_gateway_resource.panda.id, |
| 110 | + aws_api_gateway_method.panda.id, |
| 111 | + aws_api_gateway_integration.panda.id, |
| 112 | + ])) |
| 113 | + } |
| 114 | + |
| 115 | + lifecycle { |
| 116 | + create_before_destroy = true |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +resource "aws_api_gateway_stage" "panda" { |
| 121 | + depends_on = [aws_api_gateway_deployment.panda1, aws_api_gateway_stage.panda] |
| 122 | + deployment_id = aws_api_gateway_deployment.panda.id |
| 123 | + rest_api_id = aws_api_gateway_rest_api.panda.id |
| 124 | + stage_name = "panda" |
| 125 | +} |
| 126 | + |
| 127 | + |
0 commit comments