File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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```
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments