Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform miss the Use Origin Cache Headers #1994

Closed
hashibot opened this issue Oct 20, 2017 · 13 comments · Fixed by #3571
Closed

terraform miss the Use Origin Cache Headers #1994

hashibot opened this issue Oct 20, 2017 · 13 comments · Fixed by #3571
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Milestone

Comments

@hashibot
Copy link

This issue was originally opened by @arbabnazar as hashicorp/terraform#16209. It was migrated here as a result of the provider split. The original body of the issue is below.


I want to use AWS cloudfront cache behaviour to Use Origin Cache Headers as sent by my server.

However in terraform, the min_ttl, max_ttl and default_ttl is required.

Is there a way to to use the Use Origin Cache Headers in terraform?

@hashibot hashibot added the enhancement Requests to existing resources that expand the functionality or scope. label Oct 20, 2017
@xavimota
Copy link

I'm facing the same problem.
I need to create a cloudfront with terraform with "Use Origin Cache Headers" from my S3 bucket.
But it's not possible to configure it in terraform so a manual operation is needed.

@radeksimko radeksimko added the service/cloudfront Issues and PRs that pertain to the cloudfront service. label Jan 28, 2018
@allanalvaro
Copy link

Hello, I've got the same problem. Any news about that?

@wintergren
Copy link

wintergren commented Feb 14, 2018

Same here, what's the status on this?

@radeksimko @bflad or anyone else working with the provider..

@bflad
Copy link
Contributor

bflad commented Feb 28, 2018

While the attributes are marked as required in Terraform, taking a look at the SDK documentation implies that CloudFront might "do the right thing" here if the appropriate headers are set in the origin.

Specifically this sentence for Default TTL and Max TTL:

The value that you specify applies only when your origin does not add HTTP headers such as Cache-Control max-age, Cache-Control s-maxage, and Expires to objects.

    // The default amount of time that you want objects to stay in CloudFront caches
    // before CloudFront forwards another request to your origin to determine whether
    // the object has been updated. The value that you specify applies only when
    // your origin does not add HTTP headers such as Cache-Control max-age, Cache-Control
    // s-maxage, and Expires to objects. For more information, see Specifying How
    // Long Objects and Errors Stay in a CloudFront Edge Cache (Expiration) (http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html)
    // in the Amazon CloudFront Developer Guide.
    DefaultTTL *int64 `type:"long"`

   // The maximum amount of time that you want objects to stay in CloudFront caches
    // before CloudFront forwards another request to your origin to determine whether
    // the object has been updated. The value that you specify applies only when
    // your origin adds HTTP headers such as Cache-Control max-age, Cache-Control
    // s-maxage, and Expires to objects. For more information, see Specifying How
    // Long Objects and Errors Stay in a CloudFront Edge Cache (Expiration) (http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html)
    // in the Amazon CloudFront Developer Guide.
    MaxTTL *int64 `type:"long"`

    // The minimum amount of time that you want objects to stay in CloudFront caches
    // before CloudFront forwards another request to your origin to determine whether
    // the object has been updated. For more information, see Specifying How Long
    // Objects and Errors Stay in a CloudFront Edge Cache (Expiration) (http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html)
    // in the Amazon Amazon CloudFront Developer Guide.
    //
    // You must specify 0 for MinTTL if you configure CloudFront to forward all
    // headers to your origin (under Headers, if you specify 1 for Quantity and
    // * for Name).
    //
    // MinTTL is a required field
    MinTTL *int64 `type:"long" required:"true"`

Luckily, it also looks like the cacheBehaviorHash function is optionally including the default_ttl and max_ttl attributes, so this seems like it wouldn't require Terraform state migrations to change those attributes due to changing set hash values. Depending on the API response back (missing vs it returning some default values) would determine if we would want Computed: true vs Default: # on the attributes to prevent perpetual diffs.

@bflad
Copy link
Contributor

bflad commented Feb 28, 2018

TL;DR is seems like we might be able to set Optional: true and Computed: true/Default: # on the default_ttl and max_ttl attributes. I'll submit a PR and run our acceptance testing against it.

For cross-reference this is the same request as #1472.

@bflad
Copy link
Contributor

bflad commented Feb 28, 2018

Upon further testing when the attributes are not supplied during creation, AWS will set the default default_ttl to 1 day and max_ttl to 365 days. A pull request to make these attributes optional (along with min_ttl) can be found here: #3571

@bflad
Copy link
Contributor

bflad commented Mar 6, 2018

Support to make all 3 TTL arguments optional has been merged into master and will be released in v1.11.0 of the AWS provider, likely at the end of the week. Please note they are default_ttl (1 day), max_ttl (365 days), and min_ttl (0 days) to match the behavior of the API and console.

@bflad bflad added this to the v1.11.0 milestone Mar 6, 2018
@bflad
Copy link
Contributor

bflad commented Mar 9, 2018

This has been released in version 1.11.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@arbabnazar
Copy link

@bflad and team, thank you very much for adding this feature.

@digitalkaoz
Copy link

@bflad i dont get it completely...

they are optional now, but then the aws defaults apply? how do i set Use Origin Cache Headers then?

@matt-zangen
Copy link

@digitalkaoz if you remove all three caching properties from your config and apply, the default values will be set in these properties, but CloudFront will be configured with Use Origin Cache Headers.

@angristan
Copy link

Thanks @matt-zangen! I can confirm that removing min_ttl, default_ttl and max_ttl enables Use Origin Cache Headers on the behavior.

@ghost
Copy link

ghost commented Apr 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Projects
None yet
10 participants