Skip to content

Commit 3d4ed2a

Browse files
authored
Merge pull request #4 from TechHoldingLLC/cloudfront-cache
Cloudfront cache add ttl variables
2 parents c3b4c37 + 8ba2e60 commit 3d4ed2a

4 files changed

Lines changed: 41 additions & 1 deletion

File tree

EXAMPLE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,34 @@ module "cloudfront" {
6464
}
6565
]
6666
}
67+
```
68+
69+
## Cloudfront distribution with s3 Origin with TTL value
70+
```
71+
module "cloudfront" {
72+
source = "./cloudfront"
73+
origin = {
74+
domain_name = "s3_bucket_regional_domain_name"
75+
origin_id = "s3_bucket_name"
76+
77+
## We can only use Any one of Origin Access Control or Origin Access Identity
78+
# For Origin Access Control
79+
origin_access_control_id = "s3_cloudfront_origin_access_control_id"
80+
# For Origin Access Identity
81+
s3_origin_config = {
82+
s3_origin_access_identity = "s3_cloudfront_origin_access_identity_path"
83+
}
84+
85+
}
86+
domain_aliases = ["example.com", "www.example.com"]
87+
acm_arn = "acm_arn"
88+
89+
## TTL(Time to Live) is the time in seconds that an object is in Cloudfront Cache.
90+
# If we pass these below values then it will be overwritten by default values.
91+
ttl_values = {
92+
min_ttl = 1 # min amount of time that you want objects to stay in cloudfront cache before it sends another request to origin
93+
max_ttl = 86900 # max amount of time that you want objects to stay in cloudfront cache before it sends another request to origin
94+
default_ttl = 3500 # default amount of time that you want objects to stay in cloudfront cache before it sends another request to origin
95+
}
96+
}
6797
```

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ No modules.
2525

2626
| Name | Description | Type | Default | Required |
2727
|------|-------------|------|---------|:--------:|
28-
| <a name="input_acm_arn"></a> [acm\_arn](#input\_acm\_arn) | ACM cert arn | `string` | n/a | yes |
28+
| <a name="input_acm_arn"></a> [acm\_arn](#input\_acm\_arn) | ACM cert arn | `string` | n/a | no |
2929
| <a name="input_allowed_methods"></a> [allowed\_methods](#input\_allowed\_methods) | Allowed methods | `list(any)` | <pre>[<br> "GET",<br> "HEAD"<br>]</pre> | no |
3030
| <a name="input_cache_policy_id"></a> [cache\_policy\_id](#input\_cache\_policy\_id) | AWS managed cache policy id | `string` | `""` | no |
3131
| <a name="input_cached_methods"></a> [cached\_methods](#input\_cached\_methods) | Cached methods | `list(any)` | <pre>[<br> "GET",<br> "HEAD"<br>]</pre> | no |
@@ -42,6 +42,7 @@ No modules.
4242
| <a name="input_origin"></a> [origin](#input\_origin) | Origin configuration | `any` | n/a | yes |
4343
| <a name="input_route53_zone_id"></a> [route53\_zone\_id](#input\_route53\_zone\_id) | Route53 zone id | `string` | `""` | no |
4444
| <a name="input_web_acl_id"></a> [web\_acl\_id](#input\_web\_acl\_id) | WAF web ACL id | `string` | `""` | no |
45+
| <a name="input_ttl_values"></a> [ttl\_values](#input\_ttl\_values) | ttl values | `map` | {} | no |
4546

4647
## Outputs
4748

cloudfront.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ resource "aws_cloudfront_distribution" "cloudfront" {
6060

6161
viewer_protocol_policy = "redirect-to-https"
6262
compress = true
63+
min_ttl = lookup(var.ttl_values,"min_ttl",0)
64+
max_ttl = lookup(var.ttl_values,"max_ttl",86400)
65+
default_ttl = lookup(var.ttl_values,"default_ttl",3600)
6366

6467
dynamic "forwarded_values" {
6568
for_each = var.cache_policy_id != "" ? [] : [1]

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,10 @@ variable "ipv6" {
9696
description = "ipv6 status"
9797
type = bool
9898
default = false
99+
}
100+
101+
variable "ttl_values" {
102+
description = "map of ttl variables"
103+
type = map(any)
104+
default = {}
99105
}

0 commit comments

Comments
 (0)