sparse-intern-71089
12/11/2023, 8:48 PMboundless-petabyte-41580
12/11/2023, 8:49 PMconst secret = lib.makeSecret
boundless-petabyte-41580
12/11/2023, 8:50 PMconst newEntry = { SOME_SECRET: "foo" }
const secret = lib.makeSecret
boundless-petabyte-41580
12/11/2023, 8:52 PMconst updatedSecret = merge(secret,
{
data: newEntry
}
)
but that doesn't seem to cut itboundless-petabyte-41580
12/11/2023, 10:10 PMtransformations
object:
// in the library
function makeSecret(..., transformations?: pulumi.ResourceTransformation[]){
return new k8s.core.v1.Secret(name, spec, { transformations })
}
// in the app code
const newEntry = { foo: "bar" }
makeSecret(..., [
args => {
const a = args.props as k8s.core.v1.SecretArgs
if (a.data) {
a.data = pulumi.output(a.data).apply(data => ({
...data,
...newEntry
}))
}
return { props: a, opts: args.opts }
}
]
quaint-spring-93350
12/12/2023, 8:29 AMquaint-spring-93350
12/12/2023, 8:30 AM.apply
in pulumi-ts (the equivalent of .then
I mean)boundless-petabyte-41580
12/12/2023, 2:15 PMInput<T>
type.
You can assign a plain value to that type const a: Input<string> = "1"
But, if you want to modify one, you have to transform it into an Output<T>
first (or so it seems)boundless-petabyte-41580
12/12/2023, 2:20 PMconst a: pulumi.Input<string> = "a"
const aOutput: pulumi.Input<string> = pulumi.output("a")
const ab: pulumi.Input<string> = a + "b"
const abOutput: pulumi.Input<string> = aOutput + "b"
pulumi.log.info(`ab is: ${ab}`) // prints "ab"
pulumi.log.info(`abOutput is: ${abOutput}`) // prints "Calling [toString] on an [Output<T>] is not supported"
boundless-petabyte-41580
12/12/2023, 2:20 PMboundless-petabyte-41580
12/12/2023, 2:22 PMInput<T>
or get a compile errorboundless-petabyte-41580
12/12/2023, 2:23 PMquaint-spring-93350
12/12/2023, 2:52 PMboundless-petabyte-41580
12/12/2023, 2:54 PMcrd2pulumi
tool. We deal a lot with Istio, and having type support is super helpfulquaint-spring-93350
12/12/2023, 3:00 PMtype Input = T | Promise<T> | OutputInstance<T>;
quaint-spring-93350
12/12/2023, 3:11 PMquaint-spring-93350
12/12/2023, 3:12 PMconst secret = lib.makeSecret
quaint-spring-93350
12/12/2023, 3:13 PMboundless-petabyte-41580
12/12/2023, 3:14 PMmakeSecret(..., [
args => {
const a = args.props as k8s.core.v1.SecretArgs
if (a.data) { // <-- a.data is pulumi.Input<...>
a.data = pulumi.output(a.data).apply(data => ({
...data,
...newEntry
}))
}
return { props: a, opts: args.opts }
}
]
quaint-spring-93350
12/12/2023, 3:14 PMboundless-petabyte-41580
12/12/2023, 3:15 PMboundless-petabyte-41580
12/12/2023, 3:16 PMquaint-spring-93350
12/12/2023, 3:20 PMquaint-spring-93350
12/12/2023, 3:20 PMboundless-petabyte-41580
12/12/2023, 3:25 PMKnowing this can be helpful because, sincevalues have many possible representations—a plain value, a promise, or an output—you would normally need to handle all possible cases. By first transforming that value into anInput<T>
, you can treat it uniformly instead.Output<T>
boundless-petabyte-41580
12/12/2023, 3:25 PMInput<T>
, it has to be transformed into an Output<T>
?boundless-petabyte-41580
12/12/2023, 3:26 PMquaint-spring-93350
12/12/2023, 3:32 PM.asOutput()
that our codegened apply
for all the args calls for each argument. In Besom transformations won't expose Input
type because what you will see are case classes filled with respective Outputs. Then you could just .copy()
and replace fields. Transformations are TBD for 0.3.0 I think because we need to design a way to replace only what user patmats on in immutable object trees, probably using lenses.boundless-petabyte-41580
12/12/2023, 3:34 PMboundless-petabyte-41580
12/12/2023, 3:34 PMquaint-spring-93350
12/12/2023, 3:49 PMboundless-petabyte-41580
12/12/2023, 3:51 PMboundless-petabyte-41580
12/12/2023, 7:05 PMquaint-spring-93350
12/13/2023, 8:43 AM