Skip to content

Commit 829646e

Browse files
fix: root object via variable to avoid creation everytime (#12)
1 parent 06c16cb commit 829646e

4 files changed

Lines changed: 13 additions & 18 deletions

File tree

EXAMPLE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Below is an examples of calling this module.
44
## Cloudfront distribution with S3 origin
55
```
66
module "cloudfront" {
7-
source = "./cloudfront"
7+
source = "git::https://github.com/TechHoldingLLC/terraform-aws-cloudfront.git?ref=<TAG>"
88
origin = [
99
{
1010
domain_name = "s3_bucket_regional_domain_name"
@@ -28,7 +28,7 @@ module "cloudfront" {
2828
## Cloudfront distribution with custom http and https origin endpoint
2929
```
3030
module "cloudfront" {
31-
source = "./cloudfront"
31+
source = "git::https://github.com/TechHoldingLLC/terraform-aws-cloudfront.git?ref=<TAG>"
3232
origin = [
3333
{
3434
domain_name = "s3_bucket_regional_domain_name"
@@ -74,7 +74,7 @@ module "cloudfront" {
7474
## Cloudfront distribution with s3 Origin with TTL value
7575
```
7676
module "cloudfront" {
77-
source = "./cloudfront"
77+
source = "git::https://github.com/TechHoldingLLC/terraform-aws-cloudfront.git?ref=<TAG>"
7878
origin = [
7979
{
8080
domain_name = "s3_bucket_regional_domain_name"
@@ -106,7 +106,7 @@ module "cloudfront" {
106106
## Cloudfront distribution with multiple origin and cache behavior
107107
```
108108
module "cloudfront" {
109-
source = "./cloudfront"
109+
source = "git::https://github.com/TechHoldingLLC/terraform-aws-cloudfront.git?ref=<TAG>"
110110
origin = [
111111
{
112112
domain_name = "domain_name"

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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 |
1312

1413
## Modules
1514

@@ -22,7 +21,6 @@ No modules.
2221
| [aws_cloudfront_distribution.cloudfront](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution) | resource |
2322
| [aws_route53_record.cloudfront](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
2423
| [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 |
2624

2725
## Inputs
2826

@@ -38,6 +36,7 @@ No modules.
3836
| <a name="input_default_cache_behaviour_target_origin_id"></a> [default\_cache\_behaviour\_target\_origin\_id](#input\_default\_cache\_behaviour\_target\_origin\_id) | Target origin ID for default cache behaviour | `string` | n/a | yes |
3937
| <a name="input_default_cache_forwarded_values"></a> [default\_cache\_forwarded\_values](#input\_default\_cache\_forwarded\_values) | forwarded values for default cache behavior | `any` | `{}` | no |
4038
| <a name="input_default_root_object"></a> [default\_root\_object](#input\_default\_root\_object) | Default root object | `string` | `"index.html"` | no |
39+
| <a name="input_default_root_object_content"></a> [default\_root\_object\_content](#input\_default\_root\_object\_content) | Content for the default root object | `string` | `""` | no |
4140
| <a name="input_domain_aliases"></a> [domain\_aliases](#input\_domain\_aliases) | domain aliases | `list(string)` | `null` | no |
4241
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Cloudfront state | `bool` | `true` | no |
4342
| <a name="input_function_association"></a> [function\_association](#input\_function\_association) | Function association | `list(any)` | `[]` | no |

s3.tf

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,10 @@ resource "aws_s3_object" "object" {
33

44
bucket = var.s3_bucket_name
55
key = "index.html"
6-
source = "${path.cwd}/${path.module}/s3/index.html"
6+
content = var.default_root_object_content
77
content_type = "text/html"
88

99
# The filemd5() function is available in Terraform 0.11.12 and later
1010
# 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 ]
11+
etag = md5(var.default_root_object_content)
1512
}
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ variable "put_default_root_object" {
145145
default = false
146146
}
147147

148+
variable "default_root_object_content" {
149+
description = "Content for the default root object"
150+
type = string
151+
default = ""
152+
}
153+
148154
variable "s3_bucket_name" {
149155
description = "s3 bucket name for flag"
150156
type = string

0 commit comments

Comments
 (0)