-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
104 lines (89 loc) · 2.37 KB
/
main.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
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
data "aws_caller_identity" "current" {}
locals {
account_id = data.aws_caller_identity.current.account_id
}
provider "aws" {
alias = "region"
}
data "aws_region" "current" {
provider = "aws.region"
}
resource "aws_api_gateway_rest_api" "sigv4_rest_api" {
body = jsonencode({
openapi = "3.0.1"
info = {
title = "SigV4 verification"
version = "1.0"
}
paths = {
"/path1" = {
get = {
security : [
{
sigv4 : []
}
]
x-amazon-apigateway-integration = {
httpMethod = "GET"
payloadFormatVersion = "1.0"
type = "HTTP_PROXY"
uri = "https://ip-ranges.amazonaws.com/ip-ranges.json"
}
}
}
}
components = {
securitySchemes = {
sigv4 = {
type = "apiKey"
name = "Authorization"
in : "header"
x-amazon-apigateway-authtype = "awsSigv4"
}
}
}
}
)
description = "API Gateway"
name = "Regional API GW with 'AWS IAM' auth type"
endpoint_configuration {
types = ["REGIONAL"]
}
}
# Deployment
resource "aws_api_gateway_deployment" "prod-deployment" {
rest_api_id = aws_api_gateway_rest_api.sigv4_rest_api.id
triggers = {
redeployment = sha1(jsonencode(aws_api_gateway_rest_api.sigv4_rest_api.body))
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_api_gateway_stage" "PROD" {
deployment_id = aws_api_gateway_deployment.prod-deployment.id
rest_api_id = aws_api_gateway_rest_api.sigv4_rest_api.id
stage_name = "PROD"
xray_tracing_enabled = true
}
# Programmatic IAM user
resource "aws_iam_user" "user" {
name = "api-caller"
path = "/"
}
resource "aws_iam_user_policy" "apigw_invoke_policy_inline" {
name = "allow-invoke-get-method-policy"
user = aws_iam_user.user.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"execute-api:Invoke",
]
Effect = "Allow"
Resource = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.sigv4_rest_api.id}/${aws_api_gateway_stage.PROD.stage_name}/GET/path1"
},
]
})
}