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

Cloudfront distribution fills in 0'd defaultTtl / minTtl / maxTtl if not set #2688

Closed
mivtachyahu opened this issue Aug 9, 2023 · 3 comments
Labels
awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). kind/bug Some behavior is incorrect or out of spec resolution/by-design This issue won't be fixed because the functionality is working as designed

Comments

@mivtachyahu
Copy link

What happened?

I would like my defaultCacheBehaviour to use the "Use origin cache headers" setting.
In terraform I achieve this by not setting defaultTtl, minTtl or maxTtl.

If I do this in pulumi, it fills them in with 0's instead. There appears to be no option to "Use origin cache headers"

Expected Behavior

Not setting a defaultTtl, minTtl and maxTtl should use the "Use origin cache headers" behaviour instead of filling these in with 0's.

Steps to reproduce

  1. Create a cloudfront distribution with a forwardedValues set for the defaultCacheBehavior
  2. Do not set a defaultTtl, minTtl, or maxTtl

Output of pulumi about

CLI
Version 3.76.1
Go Version go1.20.6
Go Compiler gc

Plugins
NAME VERSION
aws 5.42.0
nodejs unknown

Host
OS darwin
Version 13.4
Arch arm64

This project is written in nodejs: executable='/Users/matthewbrown/.nvm/versions/node/v18.15.0/bin/node' version='v18.15.0'

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@mivtachyahu mivtachyahu added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Aug 9, 2023
@aq17
Copy link

aq17 commented Aug 10, 2023

Hi @mivtachyahu , could you provider an example or reproduction of your program? Also, what language are you using – it looks like 0's should be the correct default value for these attributes in each language regardless

@aq17 aq17 added awaiting-feedback Blocked on input from the author and removed needs-triage Needs attention from the triage team labels Aug 10, 2023
@mivtachyahu
Copy link
Author

Hi @aq17 - I'm using TypeScript.
Here's an example piece of code with minTtl / maxTtl / defaultTtl values unset:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("myBucket");

const distributionArgs: aws.cloudfront.DistributionArgs = {
    enabled: true,
    origins: [{
        domainName: bucket.bucketRegionalDomainName,
        originId: bucket.arn,
    }],
    defaultCacheBehavior: {
        targetOriginId: bucket.arn,
        viewerProtocolPolicy: "redirect-to-https",
        allowedMethods: ["GET", "HEAD", "OPTIONS"],
        cachedMethods: ["GET", "HEAD", "OPTIONS"],
        forwardedValues: {
            cookies: {
                forward: 'none',           
            },
            queryString: false,
        },
    },
    restrictions: {
        geoRestriction: {
            restrictionType: "none",
        },
    },
    viewerCertificate: {
        cloudfrontDefaultCertificate: true,
    }
};



const cdn = new aws.cloudfront.Distribution("cdn", distributionArgs);

export const cdnUrl = cdn.domainName;

Which yields this config in the aws console:
image

On a whim I decided to update the example above with the default values for maxTtl / defaultTtl from reading the aws-sdk code and a 0 of minTtl:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("myBucket");

const distributionArgs: aws.cloudfront.DistributionArgs = {
    enabled: true,
    origins: [{
        domainName: bucket.bucketRegionalDomainName,
        originId: bucket.arn,
    }],

    defaultCacheBehavior: {
        targetOriginId: bucket.arn,
        viewerProtocolPolicy: "redirect-to-https",
        allowedMethods: ["GET", "HEAD", "OPTIONS"],
        cachedMethods: ["GET", "HEAD", "OPTIONS"],
        forwardedValues: {
            cookies: {
                forward: 'none',           
            },
            queryString: false,
        },
        minTtl: 0,
        defaultTtl: 86400,
        maxTtl: 31536000,
    },
    restrictions: {
        geoRestriction: {
            restrictionType: "none",
        },
    },
    viewerCertificate: {
        cloudfrontDefaultCertificate: true,
    }
};



const cdn = new aws.cloudfront.Distribution("cdn", distributionArgs);

// Export the CloudFront distribution domain name
export const cdnUrl = cdn.domainName;

And it turns out this does yield the config setting that I was after in AWS
image

But that behaviour isn't documented anywhere, and I assume it's probably the bug that they probably should have the default values from the aws-sdk if they're not set instead of 0s?

@mikhailshilkov mikhailshilkov added needs-triage Needs attention from the triage team awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). resolution/by-design This issue won't be fixed because the functionality is working as designed and removed awaiting-feedback Blocked on input from the author needs-triage Needs attention from the triage team labels Sep 14, 2023
@mikhailshilkov
Copy link
Member

I believe this is tracked upstream in hashicorp/terraform-provider-aws#19382 which was recently closed with a doc change:

To achieve the setting of 'Use origin cache headers' without a linked cache policy, use the following TTL values: min_ttl = 0, max_ttl = 31536000, default_ttl = 86400. See this issue for additional context.

Since the upstream decided not to fix this, I think I'll go ahead and close this issue by design as well.

@mikhailshilkov mikhailshilkov closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). kind/bug Some behavior is incorrect or out of spec resolution/by-design This issue won't be fixed because the functionality is working as designed
Projects
None yet
Development

No branches or pull requests

3 participants