-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.tf
73 lines (61 loc) · 2.04 KB
/
api.tf
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
# API Gateway REST API definition
resource "aws_api_gateway_rest_api" "main" {
name = "datalayer-storage-services-api"
description = "${local.config.AWS_PROFILE} services API"
}
resource "aws_api_gateway_stage" "production" {
deployment_id = aws_api_gateway_deployment.production-deployment.id
rest_api_id = aws_api_gateway_rest_api.main.id
stage_name = "prod"
}
resource "aws_api_gateway_deployment" "production-deployment" {
rest_api_id = aws_api_gateway_rest_api.main.id
description = "${local.config.AWS_PROFILE}:: API Gateway deployment"
triggers = {
redeployment = sha1(timestamp())
}
lifecycle {
create_before_destroy = true
}
depends_on = [
aws_api_gateway_rest_api.main,
module.service-user,
module.service-subscriptions,
module.service-system-utils
]
}
resource "aws_api_gateway_usage_plan" "api-usage-plan" {
name = "${local.config.AWS_PROFILE}-api-usage-plan"
api_stages {
api_id = aws_api_gateway_rest_api.main.id
stage = aws_api_gateway_stage.production.stage_name
}
}
resource "aws_api_gateway_api_key" "app-key" {
name = "AppKey"
enabled = true
}
resource "aws_api_gateway_usage_plan_key" "usage-plan-key" {
key_id = aws_api_gateway_api_key.app-key.id
key_type = "API_KEY"
usage_plan_id = aws_api_gateway_usage_plan.api-usage-plan.id
}
resource "aws_api_gateway_domain_name" "api-subdomain" {
domain_name = "api.${local.config.SERVICE_DOMAIN}"
certificate_arn = aws_acm_certificate.wildcard-domain.arn
}
resource "aws_api_gateway_base_path_mapping" "api-base-path-mapping" {
api_id = aws_api_gateway_rest_api.main.id
stage_name = aws_api_gateway_stage.production.stage_name
domain_name = aws_api_gateway_domain_name.api-subdomain.domain_name
}
resource "aws_s3_bucket_object" "api-config-upload" {
bucket = aws_s3_bucket.storage_devops_bucket.id
key = "configurations/api.config.json"
content_type = "application/json"
content = <<EOF
{
"api_key": "${aws_api_gateway_api_key.app-key.value}",
}
EOF
}