0

I want to create a secret with Pulumi in Typescript it should contain the following data:

    remote_write:
    - url: "example.com"
      basic_auth:
        username: "user"
        password: "XXX"  

the code looks like:

    const databaseSecret = new k8s.core.v1.Secret(
  "secret-config", 
  {
    data: { 
      remote_write: [
        {
          url: "example.com",
          basic_auth:
          {
            username: "user",
            password: "XXX",
          }
        }
      ], 
    }
  }, 
k8sOpts
);

But this shows the follwing error message:

"Type '{ url: string; basic_auth: { username: string; password: string; }; }[]' is not assignable to type 'Input'"

I dont know how i can fix this? How do I get such nested data into a secret ?

robolott
  • 11
  • 1

1 Answers1

1

There are a couple of problems here.

Firstly: A Kubernetes secret takes an input with a key name, and then some string data. You're passing the key name as remote_write and then trying to pass a TypeScript object - you need to stringify it first. You can do take advantage of YAML being a superset of JSON to handle this:

let secret = [
  {
    url: "example.com",
    basic_auth: {
      username: "user",
      password: "XXX",
    },
  },
];

const databaseSecret = new k8s.core.v1.Secret("secret-config", {
    data: {
      remote_write: JSON.stringify(secret),
    },
  });

However, there's an additional problem here: Kubernetes expects objects in secrets to be base64 encoded, so you'll need to encode it first:

const databaseSecret = new k8s.core.v1.Secret("secret-config", {
  data: {
    remote_write: Buffer.from(JSON.stringify(secret), 'binary').toString('base64'),
  },
});
jaxxstorm
  • 12,422
  • 5
  • 57
  • 67