4

I've declared a kubernetes deployment like:

const ledgerDeployment = new k8s.extensions.v1beta1.Deployment("ledger", {
  spec: {
    template: {
      metadata: {
        labels: {name: "ledger"},
        name: "ledger",
        // namespace: namespace,
      },
      spec: {
        containers: [
          ...
        ],

        volumes: [

          {
            emptyDir: {},
            name: "gunicorn-socket-dir"
          }
        ]
      }
    }
  }
});

Later on in my index.ts I want to conditionally modify the volumes of the deployment. I think this is a quirk of pulumi I haven't wrapped my head around but here's my current attempt:

if(myCondition) {
  ledgerDeployment.spec.template.spec.volumes.apply(volumes =>
    volumes.push(
    {
      name: "certificates",
      secret: {
        items: [
          {key: "tls.key", path: "proxykey"},
          {key: "tls.crt", path: "proxycert"}],
        secretName: "star.builds.qwil.co"
      }
    })
  )
)

When I do this I get the following error: Property 'mode' is missing in type '{ key: string; path: string; }' but required in type 'KeyToPath'

I suspect I'm using apply incorrectly. When I try to directly modify ledgerDeployment.spec.template.spec.volumes.push() I get an error Property 'push' does not exist on type 'Output<Volume[]>'.

What is the pattern for modifying resources in Pulumi? How can I add a new volume to my deployment?

Paymahn Moghadasian
  • 9,301
  • 13
  • 56
  • 94

1 Answers1

3

It's not possible to modify the resource inputs after you created the resource. Instead, you should place all the logic that defines the shape of inputs before you call the constructor.

In your example, this could be:

let volumes = [
  {
    emptyDir: {},
    name: "gunicorn-socket-dir"
  }
]
if (myCondition) {
  volumes.push({...});
}
const ledgerDeployment = new k8s.extensions.v1beta1.Deployment("ledger", {
  // <-- use `volumes` here
});
Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • I have the same question. It appears that a service bus namespace needs to be provisioned in Azure before I can access and apply its connection string to another resource's app settings. – Scott Nimrod Dec 15 '22 at 16:11