-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi-gw.tf.disabled
84 lines (70 loc) · 2.4 KB
/
api-gw.tf.disabled
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
resource "aws_api_gateway_rest_api" "graphql-api" {
name = "researchhub/cer-graphql"
description = "API for access details in the ResearchHub environment"
tags = merge(
local.common_tags,
{
"Name" = "graphql-api-gw"
},
)
}
resource "aws_api_gateway_resource" "graphql-access" {
rest_api_id = aws_api_gateway_rest_api.graphql-api.id
parent_id = aws_api_gateway_rest_api.graphql-api.root_resource_id
path_part = "{proxy+}"
}
#TODO: add some authorization!
resource "aws_api_gateway_method" "graphql-method" {
rest_api_id = aws_api_gateway_rest_api.graphql-api.id
resource_id = aws_api_gateway_resource.graphql-access.id
http_method = "ANY"
authorization = "NONE"
api_key_required = false
request_parameters = {
"method.request.path.proxy" = true
}
}
resource "aws_api_gateway_integration" "graphql-integration" {
rest_api_id = aws_api_gateway_rest_api.graphql-api.id
resource_id = aws_api_gateway_resource.graphql-access.id
http_method = aws_api_gateway_method.graphql-method.http_method
integration_http_method = "ANY"
type = "HTTP_PROXY"
uri = "https://\${stageVariables.rhElb}"
request_parameters = {
"integration.request.path.proxy" = "method.request.path.proxy"
}
}
# Deploy the API and set variables
resource "aws_api_gateway_deployment" "graphql-deployment" {
rest_api_id = aws_api_gateway_rest_api.graphql-api.id
stage_name = var.lifecycle_state
triggers = {
redeployment = sha1(join(",", list(
jsonencode(aws_api_gateway_integration.graphql-integration),
)))
}
variables = {
"rhElb" = var.lb_dns_name
}
lifecycle {
create_before_destroy = true
}
}
# Maps the API to a managed domain to make changes transparent.
# DNS will be ${var.api-gw-domain}/cer-dashboard-graphql
resource "aws_api_gateway_base_path_mapping" "graphql-mapping" {
api_id = aws_api_gateway_rest_api.graphql-api.id
stage_name = aws_api_gateway_deployment.graphql-deployment.stage_name
domain_name = var.api-gw-domain
base_path = "cer-graphql"
}
# Part of adding API Key
resource "aws_api_gateway_usage_plan" "graphql-usagepan" {
name = "graphql-usage-plan"
description = "The usage plan for GraphQL access"
api_stages {
api_id = aws_api_gateway_rest_api.graphql-api.id
stage = aws_api_gateway_deployment.graphql-deployment.stage_name
}
}