-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretriever-poc-s3.tf
52 lines (43 loc) · 1.45 KB
/
retriever-poc-s3.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
# Cloud items required for the retriever proof of concept.
# https://github.com/redhatcloudx/cloud-image-retriever
# Create a policy for the S3 bucket that allows CloudFront to read objects.
data "aws_iam_policy_document" "read_cloudx_json_bucket" {
statement {
actions = ["s3:GetObject"]
resources = ["${aws_s3_bucket.cloudx_json_bucket.arn}/*"]
principals {
type = "AWS"
identifiers = [aws_cloudfront_origin_access_identity.retriever_poc.iam_arn]
}
}
statement {
actions = ["s3:ListBucket"]
resources = [aws_s3_bucket.cloudx_json_bucket.arn]
principals {
type = "AWS"
identifiers = [aws_cloudfront_origin_access_identity.retriever_poc.iam_arn]
}
}
}
# Create a bucket for the JSON files.
resource "aws_s3_bucket" "cloudx_json_bucket" {
bucket = "cloudx-json-bucket"
}
# Add CORS to the bucket.
resource "aws_s3_bucket_cors_configuration" "cloudx_json_bucket" {
bucket = aws_s3_bucket.cloudx_json_bucket.id
cors_rule {
allowed_methods = ["GET"]
allowed_origins = ["*"]
}
}
# Add our CloudFront bucket policy.
resource "aws_s3_bucket_policy" "cloudx_json_bucket" {
bucket = aws_s3_bucket.cloudx_json_bucket.id
policy = data.aws_iam_policy_document.read_cloudx_json_bucket.json
}
# Set the bucket to private. We expose this bucket later via CloudFront.
resource "aws_s3_bucket_acl" "cloudx_json_bucket" {
bucket = aws_s3_bucket.cloudx_json_bucket.id
acl = "private"
}