-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
94 lines (78 loc) · 2.17 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
92
93
94
## Creamos el recurso bucket
resource "aws_s3_bucket" "bucketTesting" {
force_destroy = true
tags = {
Environment = "Testing"
}
}
# Creamos una Public ACL con Ownership, bloque de acceso publico y la ACL aplicada al dicho bucket
resource "aws_s3_bucket_ownership_controls" "public_acl_0" {
bucket = aws_s3_bucket.bucketTesting.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_public_access_block" "public_acl_1" {
bucket = aws_s3_bucket.bucketTesting.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_acl" "public_acl_2" {
depends_on = [
aws_s3_bucket_ownership_controls.public_acl_0,
aws_s3_bucket_public_access_block.public_acl_1,
]
bucket = aws_s3_bucket.bucketTesting.id
acl = "public-read"
}
# Modulo de babenko para la carga de archivos en dicho bucket
module "template_files" {
source = "hashicorp/dir/template"
base_dir = "${path.module}/web"
}
# Configuracion de las diferentes paginas del sitio dentro del bucket
resource "aws_s3_bucket_website_configuration" "bucket_proyecto_1" {
bucket = aws_s3_bucket.bucketTesting.id
index_document {
suffix = "index.html"
}
error_document {
key = "about.html"
}
routing_rule {
condition {
key_prefix_equals = "docs/"
}
redirect {
replace_key_prefix_with = "documents/"
}
}
}
# Policy del bucket para permitir el manejo de archivos
resource "aws_s3_bucket_policy" "hosting_bucket_policy" {
bucket = aws_s3_bucket.bucketTesting.id
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : "*",
"Action" : "s3:GetObject",
"Resource" : [
"arn:aws:s3:::${aws_s3_bucket.bucketTesting.id}/*"
]
}
]
})
}
resource "aws_s3_object" "hosting_bucket_files" {
bucket = aws_s3_bucket.bucketTesting.id
for_each = module.template_files.files
key = each.key
content_type = each.value.content_type
source = each.value.source_path
content = each.value.content
etag = each.value.digests.md5
}