-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsftp.tf
117 lines (105 loc) · 2.95 KB
/
sftp.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
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
# role for SFTP server
resource "aws_iam_role" "sftp" {
name = "${local.prefix_kebab}sftp-server-iam-role"
assume_role_policy = <<-POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "transfer.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}
resource "aws_iam_role" "sftp_log" {
# log role for SFTP server
name = "${local.prefix_kebab}sftp-server-iam-log-role"
assume_role_policy = <<-POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "transfer.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}
resource "aws_iam_role_policy" "sftp" {
# policy to allow invocation of IdP API
name = "${local.prefix_kebab}sftp-server-iam-policy"
role = aws_iam_role.sftp.id
policy = <<-POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InvokeApi",
"Effect": "Allow",
"Action": [
"execute-api:Invoke"
],
"Resource": "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${module.idp.rest_api_id}/${module.idp.rest_api_stage_name}/GET/*"
},
{
"Sid": "ReadApi",
"Effect": "Allow",
"Action": [
"apigateway:GET"
],
"Resource": "*"
}
]
}
POLICY
}
resource "aws_iam_role_policy" "sftp_log" {
# policy to allow logging to Cloudwatch
name = "${local.prefix_kebab}sftp-server-iam-log-policy"
role = aws_iam_role.sftp_log.id
policy = <<-POLICY
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "AmazonAPIGatewayPushToCloudWatchLogs",
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
"logs:GetLogEvents",
"logs:FilterLogEvents"
],
"Resource": "arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/transfer/${aws_transfer_server.sftp.id}*"
}
]
}
POLICY
}
resource "aws_transfer_server" "sftp" {
identity_provider_type = "API_GATEWAY"
logging_role = aws_iam_role.sftp_log.arn
url = module.idp.invoke_url # url from output of the module
invocation_role = aws_iam_role.sftp.arn
endpoint_type = "PUBLIC"
tags = {
NAME = "${local.prefix_kebab}sftp-server"
}
}
module "idp" {
source = "github.com/Bubo-AI/terraform-aws-transfer?ref=v0.5.5"
prefix = var.prefix
}