File tree Expand file tree Collapse file tree 2 files changed +33
-18
lines changed Expand file tree Collapse file tree 2 files changed +33
-18
lines changed Original file line number Diff line number Diff line change
1
+ resource "aws_cloudfront_origin_access_identity" "origin_access_identity" {
2
+ comment = " ${ var . site_name } ${ var . domain } Created by Terraform"
3
+ }
4
+
1
5
resource "aws_cloudfront_distribution" "s3_distribution" {
2
6
origin {
3
7
domain_name = " ${ aws_s3_bucket . main . id } .s3.amazonaws.com"
4
8
origin_id = " S3-${ aws_s3_bucket . main . id } "
9
+
10
+ s3_origin_config {
11
+ origin_access_identity = " ${ aws_cloudfront_origin_access_identity . origin_access_identity . cloudfront_access_identity_path } "
12
+ }
13
+
5
14
}
6
15
7
16
enabled = true
Original file line number Diff line number Diff line change 1
1
// Global Content Delivery Network
2
2
// S3 + Cloudfront
3
- // Content of those bucket has been populated manually
3
+ // Content of this bucket will be populated manually
4
+ data "aws_iam_policy_document" "s3_policy" {
5
+ statement {
6
+ actions = [" s3:GetObject" ]
7
+ resources = [" arn:aws:s3:::${ var . site_name } ${ replace (var. domain , " ." , " -" )} /*" ]
8
+
9
+ principals {
10
+ type = " AWS"
11
+ identifiers = [" ${ aws_cloudfront_origin_access_identity . origin_access_identity . iam_arn } " ]
12
+ }
13
+ }
14
+
15
+ statement {
16
+ actions = [" s3:ListBucket" ]
17
+ resources = [" arn:aws:s3:::${ var . site_name } ${ replace (var. domain , " ." , " -" )} " ]
18
+
19
+ principals {
20
+ type = " AWS"
21
+ identifiers = [" ${ aws_cloudfront_origin_access_identity . origin_access_identity . iam_arn } " ]
22
+ }
23
+ }
24
+ }
25
+
4
26
resource "aws_s3_bucket" "main" {
5
27
bucket = " ${ var . site_name } ${ replace (var. domain , " ." , " -" )} "
6
28
acl = " public-read"
7
29
8
- policy = << EOF
9
- {
10
- "Version": "2008-10-17",
11
- "Id": "Policy1412590466126",
12
- "Statement": [
13
- {
14
- "Sid": "Stmt1412590461560",
15
- "Effect": "Allow",
16
- "Principal": {
17
- "AWS": "*"
18
- },
19
- "Action": "s3:GetObject",
20
- "Resource": "arn:aws:s3:::${ var . site_name } ${ replace (var. domain , " ." , " -" )} /*"
21
- }
22
- ]
23
- }
24
- EOF
30
+ policy = " ${ data . aws_iam_policy_document . s3_policy . json } "
25
31
26
32
website {
27
33
index_document = " index.html"
You can’t perform that action at this time.
0 commit comments