Git Product home page Git Product logo

Comments (3)

aq17 avatar aq17 commented on June 6, 2024

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

from pulumi-aws.

mivtachyahu avatar mivtachyahu commented on June 6, 2024

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?

from pulumi-aws.

mikhailshilkov avatar mikhailshilkov commented on June 6, 2024

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.

from pulumi-aws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.