-
Notifications
You must be signed in to change notification settings - Fork 0
/
sftp.tf
62 lines (56 loc) · 1.36 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
resource "aws_transfer_server" "sftp" {
identity_provider_type = "SERVICE_MANAGED"
}
resource "aws_iam_role" "role" {
name = "sftp-user-iam-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "transfer.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_role_policy" "policy" {
name = "sftp-user-iam-policy"
role = "${aws_iam_role.role.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "${aws_s3_bucket.bucket.arn}"
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "${aws_s3_bucket.bucket.arn}/*"
}
]
}
EOF
}
resource "aws_transfer_user" "sftp_user" {
server_id = "${aws_transfer_server.sftp.id}"
user_name = "${var.user}"
home_directory = "/${aws_s3_bucket.bucket.id}"
role = "${aws_iam_role.role.arn}"
}
resource "aws_transfer_ssh_key" "key" {
server_id = "${aws_transfer_server.sftp.id}"
user_name = "${aws_transfer_user.sftp_user.user_name}"
body = "${data.template_file.pub_key.rendered}"
}