-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.tf
125 lines (116 loc) · 3.49 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
resource "aws_iam_role" "sftp_transfer_server" {
name = "${var.name_prefix}-sftp-transfer-server-iam-role${var.name_suffix}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "transfer.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
tags = merge(
var.input_tags,
{
"Name" = "${var.name_prefix}-sftp-transfer-server-invocation-iam-role${var.name_suffix}"
},
)
}
resource "aws_iam_role_policy" "sftp_transfer_server" {
name = "${var.name_prefix}-sftp-transfer-server-iam-policy${var.name_suffix}"
role = aws_iam_role.sftp_transfer_server.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"logs:GetLogEvents",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/transfer/${aws_transfer_server.sftp_transfer_server.id}:log-stream:*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:FilterLogEvents",
"logs:CreateLogGroup"
],
"Resource": "arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/transfer/${aws_transfer_server.sftp_transfer_server.id}"
}
]
}
POLICY
}
resource "aws_iam_role" "sftp_transfer_server_invocation" {
name = "${var.name_prefix}-sftp-transfer-server-invocation-iam-role${var.name_suffix}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "transfer.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
tags = merge(
var.input_tags,
{
"Name" = "${var.name_prefix}-sftp-transfer-server-invocation-iam-role${var.name_suffix}"
},
)
}
resource "aws_iam_role_policy" "sftp_transfer_server_invocation" {
name = "${var.name_prefix}-sftp-transfer-server-invocation-iam-policy${var.name_suffix}"
role = aws_iam_role.sftp_transfer_server_invocation.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"execute-api:Invoke"
],
"Resource": "arn:aws:execute-api:${var.region}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.sftp.id}/${aws_api_gateway_stage.prod.stage_name}/${aws_api_gateway_method.get.http_method}/*",
"Effect": "Allow"
},
{
"Action": [
"apigateway:GET"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
POLICY
}
resource "aws_transfer_server" "sftp_transfer_server" {
identity_provider_type = "API_GATEWAY"
logging_role = aws_iam_role.sftp_transfer_server.arn
invocation_role = aws_iam_role.sftp_transfer_server_invocation.arn
url = aws_api_gateway_stage.prod.invoke_url
structured_log_destinations = var.server_loggroup_arns
tags = merge(
var.input_tags,
{
"Name" = "${var.name_prefix}-sftp-transfer-server${var.name_suffix}"
},
)
}