Skip to content

Commit 06c16cb

Browse files
feat: s3 object for deafult path index.html (#11)
* feat: s3 object for deafult path index.html * feat: resource to to create object locally * chore: update readme.md file
1 parent 9ffbc07 commit 06c16cb

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| Name | Version |
1010
|------|---------|
1111
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
12+
| <a name="provider_local"></a> [local](#provider\_local) | n/a |
1213

1314
## Modules
1415

@@ -20,6 +21,8 @@ No modules.
2021
|------|------|
2122
| [aws_cloudfront_distribution.cloudfront](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution) | resource |
2223
| [aws_route53_record.cloudfront](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
24+
| [aws_s3_object.object](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
25+
| [local_file.default_object](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
2326

2427
## Inputs
2528

@@ -45,7 +48,9 @@ No modules.
4548
| <a name="input_ordered_cache_behavior"></a> [ordered\_cache\_behavior](#input\_ordered\_cache\_behavior) | List of ordered cache behaviour | `any` | `[]` | no |
4649
| <a name="input_origin"></a> [origin](#input\_origin) | Origin configuration | `any` | n/a | yes |
4750
| <a name="input_origin_request_policy_id"></a> [origin\_request\_policy\_id](#input\_origin\_request\_policy\_id) | Unique identifier of the origin request policy that is attached to the behavior | `string` | `""` | no |
51+
| <a name="input_put_default_root_object"></a> [put\_default\_root\_object](#input\_put\_default\_root\_object) | flag for default s3 object on index.html | `bool` | `false` | no |
4852
| <a name="input_route53_zone_id"></a> [route53\_zone\_id](#input\_route53\_zone\_id) | Route53 zone id | `string` | `""` | no |
53+
| <a name="input_s3_bucket_name"></a> [s3\_bucket\_name](#input\_s3\_bucket\_name) | s3 bucket name for flag | `string` | `""` | no |
4954
| <a name="input_ttl_values"></a> [ttl\_values](#input\_ttl\_values) | map of ttl variables | `map(any)` | `{}` | no |
5055
| <a name="input_viewer_protocol_policy"></a> [viewer\_protocol\_policy](#input\_viewer\_protocol\_policy) | the protocol that users can use to access the files in the origin, valid values are allow-all, https-only, or redirect-to-https. | `string` | `"redirect-to-https"` | no |
5156
| <a name="input_web_acl_id"></a> [web\_acl\_id](#input\_web\_acl\_id) | WAF web ACL id | `string` | `""` | no |
@@ -62,4 +67,4 @@ No modules.
6267

6368
## License
6469

65-
Apache 2 Licensed. See [LICENSE](https://github.com/TechHoldingLLC/terraform-aws-cloudfront/blob/main/LICENSE) for full details.
70+
Apache 2 Licensed. See [LICENSE](https://github.com/TechHoldingLLC/terraform-aws-cloudfront/blob/main/LICENSE) for full details.

s3.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_s3_object" "object" {
2+
count = var.put_default_root_object ? 1 : 0
3+
4+
bucket = var.s3_bucket_name
5+
key = "index.html"
6+
source = "${path.cwd}/${path.module}/s3/index.html"
7+
content_type = "text/html"
8+
9+
# The filemd5() function is available in Terraform 0.11.12 and later
10+
# For Terraform 0.11.11 and earlier, use the md5() function and the file() function:
11+
# etag = "${md5(file("path/to/file"))}"
12+
# etag = filemd5("${path.cwd}/${path.module}/s3/index.html")
13+
14+
depends_on = [ local_file.default_object ]
15+
}
16+
17+
resource "local_file" "default_object" {
18+
count = var.put_default_root_object ? 1 : 0
19+
20+
content = ""
21+
filename = "${path.cwd}/${path.module}/s3/index.html"
22+
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,16 @@ variable "default_cache_forwarded_values" {
137137
description = "forwarded values for default cache behavior"
138138
type = any
139139
default = {}
140+
}
141+
142+
variable "put_default_root_object" {
143+
description = "flag for default s3 object on index.html"
144+
type = bool
145+
default = false
146+
}
147+
148+
variable "s3_bucket_name" {
149+
description = "s3 bucket name for flag"
150+
type = string
151+
default = ""
140152
}

0 commit comments

Comments
 (0)