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 · 12 comments

Comments

@hashibot
Copy link

commented Oct 20, 2017

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?

@xavimota

This comment has been minimized.

Copy link

commented Oct 25, 2017

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.

@allangomesptc

This comment has been minimized.

Copy link

commented Feb 12, 2018

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

@anderssoder

This comment has been minimized.

Copy link

commented Feb 14, 2018

Same here, what's the status on this?

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

@bflad

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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 bflad closed this in #3571 Mar 6, 2018

@bflad

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

commented Mar 10, 2018

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

@digitalkaoz

This comment has been minimized.

Copy link

commented May 31, 2018

@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

This comment has been minimized.

Copy link

commented Jun 19, 2018

@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

This comment has been minimized.

Copy link

commented Sep 10, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.