-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
91 lines (77 loc) · 1.74 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.39.0"
}
}
}
terraform {
backend "s3" {
bucket = "danoph-file-uploader-demo-terraform"
key = "terraform.tfstate"
region = "us-east-1"
}
}
locals {
upload-bucket-name = "danoph-file-uploader-demo"
}
resource "aws_s3_bucket" "uploads" {
bucket = local.upload-bucket-name
}
resource "aws_s3_bucket_server_side_encryption_configuration" "uploads" {
bucket = aws_s3_bucket.uploads.bucket
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_cors_configuration" "uploads" {
bucket = aws_s3_bucket.uploads.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "PUT", "POST"]
allowed_origins = ["*"]
expose_headers = ["ETag"]
}
}
resource "aws_iam_user" "vercel" {
name = "file-uploader-demo"
path = "/system/"
}
resource "aws_iam_access_key" "vercel" {
user = aws_iam_user.vercel.name
}
resource "aws_iam_policy" "s3_access" {
name = "vercel_file_uploader_demo"
path = "/"
description = "IAM policy for s3 access from vercel"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListMultipartUploadParts"
],
"Resource": "arn:aws:s3:::${local.upload-bucket-name}/*",
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_user_policy_attachment" "s3_access" {
user = aws_iam_user.vercel.name
policy_arn = aws_iam_policy.s3_access.arn
}
output "access_key_id" {
value = aws_iam_access_key.vercel.id
}
output "access_key_secret" {
sensitive = true
value = aws_iam_access_key.vercel.secret
}