forked from turnerlabs/terraform-s3-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
56 lines (48 loc) · 1.16 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
/**
* 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 = "srv_${var.bucket_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}"
}
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": [
{
"Effect": "Allow",
"Principal": {
"AWS": "${aws_iam_user.user.arn}"
},
"Action": [ "s3:*" ],
"Resource": [
"${aws_s3_bucket.bucket.arn}",
"${aws_s3_bucket.bucket.arn}/*"
]
}
]
}
EOF
}