-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
149 lines (123 loc) · 3.14 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
module "apigw" {
source = "armorfret/apigw-lambda/aws"
version = "0.9.2"
source_bucket = var.lambda_bucket
source_version = var.lambda_version
function_name = "frame_${var.data_bucket}"
environment_variables = {
S3_BUCKET = var.config_bucket
S3_KEY = "config.yaml"
}
access_policy_document = data.aws_iam_policy_document.lambda_perms.json
hostname = var.hostname
binary_media_types = [
"*/*",
]
auth_source_bucket = var.auth_lambda_bucket
auth_source_version = var.auth_lambda_version
auth_environment_variables = {
S3_BUCKET = var.auth_config_bucket
S3_KEY = "config.yaml"
}
auth_access_policy_document = data.aws_iam_policy_document.auth_lambda_perms.json
auth_ttl = 0
cloudwatch_retention_in_days = var.cloudwatch_retention_in_days
}
module "publish_user" {
source = "armorfret/s3-publish/aws"
version = "0.8.1"
logging_bucket = var.logging_bucket
publish_bucket = var.data_bucket
}
module "config_user" {
source = "armorfret/s3-publish/aws"
version = "0.8.1"
logging_bucket = var.logging_bucket
publish_bucket = var.config_bucket
count = var.config_bucket == var.data_bucket ? 0 : 1
}
module "auth_config_user" {
source = "armorfret/s3-publish/aws"
version = "0.8.1"
logging_bucket = var.logging_bucket
publish_bucket = var.auth_config_bucket
}
data "aws_iam_policy_document" "lambda_perms" {
statement {
actions = [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
]
resources = distinct([
"arn:aws:s3:::${var.data_bucket}/*",
"arn:aws:s3:::${var.data_bucket}",
"arn:aws:s3:::${var.config_bucket}/*",
"arn:aws:s3:::${var.config_bucket}",
])
}
statement {
actions = [
"logs:CreateLogStream",
]
resources = [
"arn:aws:logs:*:*:log-group:/aws/lambda/frame_${var.data_bucket}",
]
}
statement {
actions = [
"logs:PutLogEvents",
]
resources = [
"arn:aws:logs:*:*:log-group:/aws/lambda/frame_${var.data_bucket}:*",
]
}
}
data "aws_iam_policy_document" "auth_lambda_perms" {
statement {
actions = [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
]
resources = [
"arn:aws:s3:::${var.auth_config_bucket}/*",
"arn:aws:s3:::${var.auth_config_bucket}",
]
}
statement {
actions = [
"logs:CreateLogStream",
]
resources = [
"arn:aws:logs:*:*:log-group:/aws/lambda/frame_${var.data_bucket}_auth",
]
}
statement {
actions = [
"logs:PutLogEvents",
]
resources = [
"arn:aws:logs:*:*:log-group:/aws/lambda/frame_${var.data_bucket}_auth:*",
]
}
}
resource "aws_api_gateway_gateway_response" "this" {
rest_api_id = module.apigw.rest_api_id
status_code = "401"
response_type = "UNAUTHORIZED"
response_templates = {
"application/json" = "{'message':$context.error.messageString}"
}
response_parameters = {
"gatewayresponse.header.WWW-Authenticate" = "'Basic'"
}
}