-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathapigateway.tf
64 lines (54 loc) · 1.79 KB
/
apigateway.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
resource "aws_iam_role" "iam_for_apigateway_idp" {
name = "iam_for_apigateway_idp-${var.stage}"
assume_role_policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "apigateway.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "apigateway-cloudwatchlogs" {
role = aws_iam_role.iam_for_apigateway_idp.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
}
resource "aws_api_gateway_account" "api_gateway_account" {
cloudwatch_role_arn = aws_iam_role.iam_for_apigateway_idp.arn
}
resource "aws_api_gateway_rest_api" "sftp-idp-secrets" {
name = "sftp-idp-secrets"
description = "This API provides an IDP for AWS Transfer service"
endpoint_configuration {
types = ["REGIONAL"]
}
body = data.template_file.api-definition.rendered
}
resource "aws_lambda_permission" "allow_apigateway" {
statement_id = "AllowExecutionFromApigateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.sftp-idp.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.sftp-idp-secrets.execution_arn}/*/*/*"
}
resource "aws_api_gateway_deployment" "deployment" {
rest_api_id = aws_api_gateway_rest_api.sftp-idp-secrets.id
triggers = {
redeployment = sha1(jsonencode([aws_api_gateway_rest_api.sftp-idp-secrets.body]))
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_api_gateway_stage" "stage" {
stage_name = var.stage
rest_api_id = aws_api_gateway_rest_api.sftp-idp-secrets.id
deployment_id = aws_api_gateway_deployment.deployment.id
}