forked from turnerlabs/terraform-s3-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
84 lines (75 loc) · 2.03 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
/**
* A Terraform module that creates a tagged S3 bucket and an IAM user/key with access to the bucket
*/
# we need a service account user
resource "aws_iam_user" "user" {
name = "${var.iam_user_name}"
}
# generate keys for service account user
resource "aws_iam_access_key" "user_keys" {
user = "${aws_iam_user.user.name}"
}
# create an s3 bucket
resource "aws_s3_bucket" "bucket" {
bucket = "${var.bucket_name}"
force_destroy = "true"
versioning {
enabled = "${var.versioning}"
}
cors_rule {
allowed_methods = ["GET"]
allowed_origins = ["*"]
max_age_seconds = 3000
}
tags {
team = "${var.tag_team}"
application = "${var.tag_application}"
environment = "${var.tag_environment}"
contact-email = "${var.tag_contact-email}"
customer = "${var.tag_customer}"
}
}
# grant user access to the bucket
resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = "${aws_s3_bucket.bucket.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "${aws_s3_bucket.bucket.arn}/*"
},
{
"Sid": "HiveProgrammaticAccessGetBucketLocation",
"Effect": "Allow",
"Principal": {
"AWS": "${aws_iam_user.user.arn}"
},
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket"
],
"Resource": "${aws_s3_bucket.bucket.arn}"
},
{
"Sid": "HiveProgrammaticAccessPutObject",
"Effect": "Allow",
"Principal": {
"AWS": "${aws_iam_user.user.arn}"
},
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:PutObjectAcl"
],
"Resource": "${aws_s3_bucket.bucket.arn}/*"
}
]
}
EOF
}