https://pulumi.com logo
Docs
Join the conversationJoin Slack
Channels
announcements
automation-api
aws
azure
blog-posts
built-with-pulumi
cloudengineering
cloudengineering-support
content-share
contribex
contribute
docs
dotnet
finops
general
getting-started
gitlab
golang
google-cloud
hackathon-03-19-2020
hacktoberfest
install
java
jobs
kubernetes
learn-pulumi-events
linen
localstack
multi-language-hackathon
office-hours
oracle-cloud-infrastructure
plugin-framework
pulumi-cdk
pulumi-crosscode
pulumi-deployments
pulumi-kubernetes-operator
pulumi-service
pulumiverse
python
registry
status
testingtesting123
testingtesting321
typescript
welcome
workshops
yaml
Powered by Linen
typescript
  • b

    broad-helmet-79436

    12/21/2021, 11:39 AM
    The problem will also get worse when I eventually switch to pretty much exclusively running Pulumi on a CI server, which is a goal to avoid simultaneous runs on multiple computers that end up causing issues with my stack
  • f

    faint-van-25343

    12/22/2021, 5:35 PM
    Hello! The following problem has me stumped and I'm hoping someone here can help? I suspect I'm missing something obvious... I'm trying to filter an array of Resources by matching an Output property on each element against an array of strings. In addition to the following snippet, I've tried wrapping the array as an Output (
    pulumi.output(params.subnets).apply( s => s.filter(...))
    ), hoping that this filter function (https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/#UnwrappedArray-filter) might resolve as intended.
    type CreateVPCEndpointParams = {
      vpc: aws.ec2.Vpc;
      subnets: aws.ec2.Subnet[];
      region: string;
      provider: aws.Provider;
    };
    
    export const createVPCEndpoint = (params: CreateVPCEndpointParams) => {
      const supported_azs = ['use1-az2', 'use1-az4', 'use1-az6'];
      
      // FIXME: This filtering doesn't work. I think it's because the predicate returns an OutputInstance which is always truthy; it's not resolving the wrapped boolean?
      const matching_subnets = params.subnets.filter((subnet) => {
        return subnet.availabilityZoneId.apply((azid) => supported_azs.includes(azid));
      });
    
      return new aws.ec2.VpcEndpoint(
        'elastic-co-endpoint',
        {
          vpcId: params.vpc.id,
          serviceName: 'redacted.vpce-svc',
          vpcEndpointType: 'Interface',
          subnetIds: matching_subnets.map((subnet) => subnet.id),
        },
        { provider: params.provider }
      );
    }
    • 1
    • 1
  • b

    breezy-butcher-78604

    12/23/2021, 3:18 AM
    does anyone have any experience importing json files in pulumi projects? I’m using AJV to do some config validation and have the following code:
    import * as pulumi from '@pulumi/pulumi';
    import Ajv, { JTDDataType } from 'ajv/dist/jtd';
    import repoConfigSchema from './config-schema.json';
    
    // ...
    however when running the program with
    pulumi up
    i get the following error:
    pulumi:pulumi:Stack (gh-repos-main):
        error: Running program '<redacted>/src' failed with an unhandled exception:
        TSError: ⨯ Unable to compile TypeScript:
        config.ts(3,30): error TS2732: Cannot find module './config-schema.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
    
            at createTSError (<redacted>/node_modules/ts-node/src/index.ts:261:12)
            at getOutput (<redacted>/node_modules/ts-node/src/index.ts:367:40)
            at Object.compile (<redacted>/node_modules/ts-node/src/index.ts:558:11)
            at Module.m._compile (<redacted>/node_modules/ts-node/src/index.ts:439:43)
            at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
            at Object.require.extensions.<computed> [as .ts] (<redacted>/node_modules/ts-node/src/index.ts:442:12)
            at Module.load (internal/modules/cjs/loader.js:950:32)
            at Function.Module._load (internal/modules/cjs/loader.js:790:14)
            at Module.require (internal/modules/cjs/loader.js:974:19)
            at require (internal/modules/cjs/helpers.js:92:18)
    but i have enabled
    resolveJsonModule
    in my tsconfig:
    {
      "$schema": "<https://json.schemastore.org/tsconfig>",
      "display": "Node 14",
      "compilerOptions": {
        "target": "es2020",
        "lib": [
          "es2020"
        ],
        "module": "commonjs",
        "outDir": "dist/",
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true
      },
      "include": [
        "src/**/*.ts",
        "src/**/*.json"
      ]
    }
    any ideas what I’m missing?
    f
    • 2
    • 2
  • r

    refined-terabyte-65361

    12/23/2021, 8:53 PM
    Hello If i use typescript in lambda function which run time should i be choosing is it nodejs 14.x ?
    l
    • 2
    • 2
  • s

    some-church-49045

    01/01/2022, 3:50 AM
    Hello, i am implementing my first dynamic Resource. It looks to me that the type of any dynamic resource is hard coded to :
    pulumi-nodejs:dynamic:Resource
    . This generate duplicate resouce URN when the name of 2 different resource are the same . Is there a way to fix this ?
    l
    • 2
    • 8
  • c

    crooked-dawn-93088

    01/04/2022, 2:07 PM
    Hi there, I got a question regarding unit testing: My tests are running in a time-out presumably because the infrastructure definition contains a getter. How to mock a getter on an existing resource? Let's say this is the index.ts with a
    get
    to import the default security group for further reference:
    import * as aws from '@pulumi/aws';
    import * as awsx from '@pulumi/awsx';
    
    export const vpc = new awsx.ec2.Vpc('mdm-db-vpc', {
      subnets: [{ type: 'isolated' }],
    });
    
    export const securityGroup = aws.ec2.SecurityGroup.get(
      'default',
      vpc.vpc.defaultSecurityGroupId,
    );
    l
    • 2
    • 5
  • b

    breezy-bear-50708

    01/04/2022, 3:08 PM
    Hi, is there any risk to manually setting the typescript version? It seems to work okay, just concerned about running into some problems down the line. e.g.
    "dependencies": {
        "@pulumi/pulumi": "^3.0.0",
        "typescript": "^3.8.0"
    m
    • 2
    • 2
  • i

    incalculable-midnight-8291

    01/05/2022, 11:12 AM
    Edit:
    cluster.eksCluster.name.apply
    seems to work a bit differently than I thought. so basically using it like this seems to work:
    cluster.eksCluster.name.apply((eksClusterName) => {
      const nodegroup = new eks.NodeGroup(`${name}-nodegroup`, {
        cluster,
        instanceProfile,
        labels: {
          role: 'managed-nodes',
        },
        instanceType: 't2.medium',
        desiredCapacity: 1,
        minSize: 1,
        maxSize: 3,
        autoScalingGroupTags: {
          ['<http://k8s.io/cluster-autoscaler/enabled|k8s.io/cluster-autoscaler/enabled>']: 'true',
          [`<http://k8s.io/cluster-autoscaler/${eksClusterName}`|k8s.io/cluster-autoscaler/${eksClusterName}`>]: 'owned',
        },
      });
    ------------ Original: Hi! Im trying to setup an eks cluster with k8s cluster autoscaler. To get this to work, I need to tag the nodegroup with:
    autoScalingGroupTags: {
        ['<http://k8s.io/cluster-autoscaler/enabled|k8s.io/cluster-autoscaler/enabled>']: 'true',
        [`<http://k8s.io/cluster-autoscaler/${cluster.eksCluster.name}`|k8s.io/cluster-autoscaler/${cluster.eksCluster.name}`>]: 'owned',
      },
    However, the operation fails since
    Template format error: YAML not well-formed
    Checking details shows that
    cluster.eksCluster.name
    is never expanded to the name, instead it becomes:
    <http://k8s.io/cluster-autoscaler/Calling|k8s.io/cluster-autoscaler/Calling> [toString] on an [Output<T>] is not supported....
    Im creating the cluster with
    const cluster = new eks.Cluster(name, { options });
    But the eks cluster dont just get the name
    name
    , but
    ${name}-eksCluster-1234567
    The number seems to be generated on creation, so I would really need some way of extracting it so I can use it in my tag. I have tried `pulumi.interpolate`k8s.io/cluster-autoscaler/${cluster.eksCluster.name}`` and
    cluster.eksCluster.name.apply(v => `<http://k8s.io/cluster-autoscaler/${v}`|k8s.io/cluster-autoscaler/${v}`>)
    but they both fail with
    error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
    Any ideas?
  • m

    magnificent-lifeguard-15082

    01/06/2022, 5:21 PM
    ec2.Vpc.getSubnets
    returns a
    Promise<ec2.Subnet[]>
    as opposed to an
    Output<ec2.Subnet>[]
    . Is this safe to use as an arg (Input) to a subsequent resource where I need to provide a subnet id?
    b
    r
    e
    • 4
    • 14
  • p

    purple-megabyte-83002

    01/11/2022, 3:13 PM
    hello I cannot resolve path, the path is well registered ??
    cwd /Users/john/Desktop/nxapp/apps/app-web/src-infra
        {
          target: 'es6',
          module: 'commonjs',
          moduleResolution: 'node',
          sourceMap: 'true',
          baseUrl: '../../../',
          paths: {
            '@app/infra': [ 'libs/infra/src/index.ts' ],
          },
          traceResolution: true
        }
     
        error: Running program '/Users/john/Desktop/nxapp/apps/app-web/src-infra/main.ts' failed with an unhandled exception:
        Error: Cannot find module '@app/infra'
        Require stack:
        - /Users/john/Desktop/nxapp/apps/app-web/src-infra/main.ts
        - /Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/cmd/run/run.js
        - /Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/cmd/run/index.js
            at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
            at Function.Module._load (node:internal/modules/cjs/loader:778:27)
            at Module.require (node:internal/modules/cjs/loader:1005:19)
            at require (node:internal/modules/cjs/helpers:102:18)
            at Object.<anonymous> (/Users/john/Desktop/nxapp/apps/app-web/src-infra/main.ts:1:1)
            at Module._compile (node:internal/modules/cjs/loader:1101:14)
            at Module.m._compile (/Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/node_modules/ts-node/src/index.ts:439:23)
            at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
            at Object.require.extensions.<computed> [as .ts] (/Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/node_modules/ts-node/src/index.ts:442:12)
            at Module.load (node:internal/modules/cjs/loader:981:32)
    b
    • 2
    • 8
  • g

    great-sunset-355

    01/13/2022, 9:39 AM
    Hello, I'm trying to define a cloudwatch alarm and I'm getting TS error
    TS2322: Type 'Output<string | undefined>' is not assignable to type 'Input<string>'
    Because
    dimmensions
    is defined as
    /**
         * The dimensions for this metric.  For the list of available dimensions see the AWS documentation [here](<http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html>).
         */
        dimensions?: pulumi.Input<{
            [key: string]: pulumi.Input<string>;
        }>;
    Therefore I cannot use like this:
    new aws.cloudwatch.MetricAlarm(
          this.rcName('CpuHigh'),
          {
           ...
            dimensions: {
              ClusterName: this.cluster.clusterName!,
              ServiceName: this.service.name
            }
    
          }
        )
    I noticed a similar issue here: https://github.com/pulumi/pulumi-aws/pull/414 Is there any workaround for that?
    b
    w
    • 3
    • 5
  • m

    magnificent-lifeguard-15082

    01/16/2022, 11:32 PM
    Is there a utility function like the following in the available typescript api?
    pulumi.json.stringify = (obj: JsonValueWithPotentialOutputsToJsonValue) => Output<string>
    The return value here is an Output to a json string where the Output has collected all dependencies discovered while walking the passed object (JsonValueWithOutputs) Edit: just use
    pulumi.output(obj).apply(uObj => JSON.stringify(uObj))
    as output() deeply unwrapps 🎉 thanks pulumi team (lots of complexity is trivialised in the input/output api for us!)
    l
    • 2
    • 4
  • a

    acoustic-room-2113

    01/17/2022, 9:35 PM
    Hey y'all. Is it possible to try to see if a stack exists when using the S3 backend, prior to attempting to reference it or some way to allow referencing a non-existent stack to fail gracefully? This is what I'm trying currently and it's failing in preview.
    let kmsPolicy: aws.iam.Policy;
    try {
      const vaultStack = new pulumi.StackReference(`vault-${env}`);
      const vaultKey = vaultStack.getOutput(
        "vaultKey"
      ) as pulumi.Output<aws.kms.Key>;
    
      if (vaultKey != undefined && vaultKey != null) {
        kmsPolicy = new aws.iam.Policy("vaultKMSUnsealPolicy", {
          name: `VaultKMSUnsealKeyAccess-${env}`,
          description: "Allow access to Vault Unseal Key",
          policy: vaultKey.apply((key) =>
            JSON.stringify({
              Version: "2012-10-17",
              Statement: [
                {
                  Sid: "VaultKMSUnseal",
                  Effect: "Allow",
                  Action: ["kms:Encrypt", "kms:Decrypt", "kms:DescribeKey"],
                  Resource: key.arn,
                },
              ],
            })
          ),
        });
      }
    } catch (e) {
      console.log(e);
    }
    l
    • 2
    • 10
  • a

    acoustic-room-2113

    01/17/2022, 9:37 PM
    More broadly speaking, I've noticed that try/catch hasn't worked for the things I've tried under pulumi
    l
    • 2
    • 1
  • s

    sparse-florist-83224

    01/17/2022, 10:37 PM
    Maybe I'm missing something obvious, but if I have a resource that starts a Docker container, then a resource that takes an action on that Docker container (in my case, starting Consul and then connecting to Consul), and then if I kill the Consul container, refresh doesn't work. I think I need to refresh to let Pulumi know that the container is down (since just running up doesn't restart it). But the refresh fails because my second resource attempts to connect to Consul (which is down) and fails. Thus, I can't refresh and up doesn't bring me back into compliance.
    m
    • 2
    • 1
  • r

    refined-terabyte-65361

    01/18/2022, 6:35 PM
    Hello I am trying to create lambda function
    runtime: "go1.x"
    I have code and dependencies in a directory how to run go build and zip while creating lambda function i am using typescript for pulumi
    runtime: nodejs
    m
    • 2
    • 3
  • l

    little-cartoon-10569

    01/18/2022, 9:52 PM
    Pulumi seems to be running my TS code without transpiling it according to the directions in tsconfig.json. I've just added baseUrl/paths/moduleAliases, but it's complaining that it can't find the JS files in dist/.../*.js...
    m
    m
    • 3
    • 38
  • e

    echoing-actor-55539

    01/18/2022, 10:17 PM
    I have created a pulumi.dynamic.Resource that uses the check method to check if its the 1st time the provider has run through a life cycle by checking if there are any values in the olds parameter. It then passes a firstRun=true param as one of the inputs to the create method which takes action accordingly. For some reason the check method is being called twice, 1st time it has old and new values, 2nd time its called with only new values then the create method is being invoked which then has no idea if its the first time. My project only has one instance of this resource. Any thoughts? Snippet:
    export class CloudfrontInvalidationResource extends pulumi.dynamic.Resource implements CloudfrontInvalidationResourceOutputs {
      public readonly cfDistributionId!: Output<ID>;
      public readonly invalidationId!: Output<string>;
      public readonly invalidationPaths!: Output<string[]>;
      public readonly buildHash!: pulumi.Output<string>;
      public readonly firstRun!: pulumi.Output<boolean>;
    
      constructor(name: string, props: CloudfrontInvalidationResourceInputs, opts?: pulumi.CustomResourceOptions) {
        const cfInvalidationProvider: pulumi.dynamic.ResourceProvider = {
          check: async (olds: CloudfrontInvalidationResourceInputs, news: CloudfrontInvalidationResourceInputs): Promise<CheckResult> => {
            console.log('******* check ' + name, {oldFirstRun: olds.firstRun, newFirstRun: news.firstRun, oldBuildHash: olds.buildHash, newBuildHash: news.buildHash});
            const firstRun = !olds.buildHash;
            return {
              inputs: { ...news, firstRun }
            };
          },
    Looks like the method invocation order is check(with old and new), diff, check(missing old values), create
  • l

    little-cartoon-10569

    01/18/2022, 10:51 PM
    Related to my earlier thread: I'd like to try the new esm features in 3.21.1 and newer, but (due to general lack of JS/TS knowledge), changing my package.json type to module has resulted in
    TypeError: Unknown file extension ".ts" for /pulumi/projects/myproj/index.ts
    Is there an example of a good package.json + tsconfig.json that works with type: module?
    • 1
    • 2
  • r

    refined-terabyte-65361

    01/19/2022, 12:37 AM
    How to a bash file from pulumi ? tried below but dint seem to work
    import { exec } from "child_process";
    exec("./removeBuild.sh ", (err: any, stdout: any, stderr: any) => {
      if (err) {
        //some err occurred
        console.error(err);
      } else {
        // the *entire* stdout and stderr (buffered)
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
      }
    });
    l
    • 2
    • 2
  • b

    busy-magazine-6225

    01/22/2022, 1:01 AM
    I’m dealing with a strange issue - when deleting resources it seems like dependson isn’t being respected. Say I have a class that extends component resource, and builds a vpc and subnets. I make the subnets depend on the vpc. But running a pulumi destroy tries to delete the vpc first, ignoring the depends on, and then complains that it has dependencies so the vpc can’t be deleted
  • b

    busy-magazine-6225

    01/22/2022, 1:01 AM
    anyone run into this before?
  • b

    busy-magazine-6225

    01/22/2022, 1:05 AM
    Like even code this simple doesn’t work
    /** Create vpc */
        const vpc = new aws.ec2.Vpc(
          `${opts.name}-vpc`,
          {
            cidrBlock: opts.vpcCidr,
            enableDnsHostnames: true,
            tags: { Name: `${opts.name}-vpc` }
          },
          { parent: this }
        );
    
        /** Create internet gateway for VPC */
        const internetGateway = new aws.ec2.InternetGateway(
          `${opts.name}-igw`,
          {
            vpcId: vpc.id,
            tags: { Name: `${opts.name}-igw` }
          },
          { parent: this, dependsOn: vpc }
        );
    It always deletes the VPC first
    l
    • 2
    • 2
  • b

    busy-magazine-6225

    01/22/2022, 1:08 AM
    From what I’ve read I don’t even need the dependson because I am using an output from vpc as an input, but removing it doesn’t help.
  • r

    refined-terabyte-65361

    01/24/2022, 8:46 PM
    Hello i am trying to run go build within pulumi script how can i do that ? Thanks
    q
    • 2
    • 1
  • m

    magnificent-lifeguard-15082

    01/28/2022, 1:28 PM
    Has anyone come up, and resolved a workaround, against the issue of using dynamic pulumi providers & resources while using a precompiled pulumi entry file because they cant use the fixed pulumi tsc version? RE: https://github.com/pulumi/pulumi/issues/4876#issuecomment-914947851
    o
    • 2
    • 5
  • w

    wonderful-finland-34377

    01/29/2022, 11:20 PM
    hi team! Does someone has any advice on how to improve memory usage? I have 4gb ci node and it's hitting swap and crashing while doing pulumi preview with a typescript project =/
    error: an unhandled error occurred: Program exited with non-zero exit code: -1
    no more information rather than this one
    h
    • 2
    • 1
  • a

    ancient-monkey-64322

    01/31/2022, 12:47 PM
    Hi there! I have a question that basically boils down to how to go from something like
    Output<string[]>
    to
    Output<string>[]
    or
    Output<Record<string, string>>
    to
    Record<string, Output<string>>
    …
    m
    • 2
    • 7
  • m

    microscopic-dress-1605

    01/31/2022, 11:16 PM
    Published v2.3.0 of aws-iam-policy a typescript library for handling AWS IAM Policy documents. It now supports the peculiarities of values that can be a string or an array for all supported fields: Action, Resource, Principal and Condition. https://www.npmjs.com/package/@thinkinglabs/aws-iam-policy
    👍 1
    👍🏼 1
  • s

    steep-toddler-94095

    02/02/2022, 12:10 AM
    is there a way to choose which version of typescript/ts-node pulumi uses? On 
    pulumi preview
     I'm running into a compile error that should not exist on typescript version 4.4+ when using template literals the way I'm using them 
    Object literal may only specify known properties
    l
    m
    • 3
    • 3
Powered by Linen
Title
s

steep-toddler-94095

02/02/2022, 12:10 AM
is there a way to choose which version of typescript/ts-node pulumi uses? On 
pulumi preview
 I'm running into a compile error that should not exist on typescript version 4.4+ when using template literals the way I'm using them 
Object literal may only specify known properties
l

little-cartoon-10569

02/02/2022, 1:03 AM
Update your package.json with the correct version range.
s

steep-toddler-94095

02/02/2022, 1:15 AM
my package.json has these version, with the versions in the lockfile as higher than this
"ts-node": "^10.2.1",
    "typescript": "^4.4.2"
the
pulumi
CLI is using a different version of typescript. When I run similar code not through Pulumi CLI, I don't get an error.
m

miniature-musician-31262

02/02/2022, 5:01 AM
Not in a first-class way, AFAIK, but this issue mentions a couple of workarounds, e.g., Yarn `resolutions`: https://github.com/pulumi/pulumi/issues/8177
👀 1
👍 1
View count: 3