This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
105 lines (90 loc) · 3.18 KB
/
main.tf
File metadata and controls
105 lines (90 loc) · 3.18 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* # Terraform AWS module for [AWS API gateway V2](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html) with OpenAPI spec
*
* ## Introduction
* This is a minimal Terraform module which accepts a AWS + OpenAPI spec and deploys an [AWS API Gateway V2](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html)
*
* ## Usage
* Check [examples](./examples) on how to use this module
*
* ## Authors
*
* Module managed by [Comtravo](https://github.com/comtravo).
*
* License
* -------
*
* MIT Licensed. See [LICENSE](LICENSE) for full details.
*/
resource "aws_cloudwatch_log_group" "this" {
name = "/aws/apigateway/${var.name}"
retention_in_days = var.access_log_settings.retention_in_days
tags = var.tags
}
resource "aws_apigatewayv2_api" "this" {
name = var.name
protocol_type = var.protocol_type
description = "${var.name} API Integration"
body = var.body
version = sha256(var.body)
dynamic cors_configuration {
for_each = var.cors_configuration
content {
allow_credentials = cors_configuration.value["allow_credentials"]
allow_headers = cors_configuration.value["allow_headers"]
allow_methods = cors_configuration.value["allow_methods"]
allow_origins = cors_configuration.value["allow_origins"]
expose_headers = cors_configuration.value["expose_headers"]
max_age = cors_configuration.value["max_age"]
}
}
tags = var.tags
}
resource "aws_apigatewayv2_deployment" "this" {
api_id = aws_apigatewayv2_api.this.id
description = "${var.name} API deployment"
triggers = {
"redeployment" = sha256(var.body)
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_apigatewayv2_stage" "this" {
api_id = aws_apigatewayv2_api.this.id
name = var.stage
description = "${var.name} API stage: ${var.stage}"
deployment_id = aws_apigatewayv2_deployment.this.id
access_log_settings {
destination_arn = aws_cloudwatch_log_group.this.arn
format = var.access_log_settings.format
}
tags = var.tags
}
resource "aws_apigatewayv2_domain_name" "this" {
count = var.domain_settings.enable == true ? 1 : 0
domain_name = var.domain_settings.domain_name
domain_name_configuration {
certificate_arn = var.domain_settings.certificate_arn
endpoint_type = var.domain_settings.endpoint_type
security_policy = var.domain_settings.security_policy
}
tags = var.tags
}
resource "aws_apigatewayv2_api_mapping" "this" {
count = var.domain_settings.enable == true ? 1 : 0
api_id = aws_apigatewayv2_api.this.id
domain_name = aws_apigatewayv2_domain_name.this[0].id
stage = aws_apigatewayv2_stage.this.id
}
resource "aws_route53_record" "this" {
count = var.domain_settings.enable == true ? 1 : 0
name = aws_apigatewayv2_domain_name.this[0].domain_name
type = "A"
zone_id = var.domain_settings.zone_id
alias {
name = aws_apigatewayv2_domain_name.this[0].domain_name_configuration[0].target_domain_name
zone_id = aws_apigatewayv2_domain_name.this[0].domain_name_configuration[0].hosted_zone_id
evaluate_target_health = false
}
}