https://pulumi.com logo
a

ancient-night-64850

08/17/2021, 7:14 PM
(typescript) How can I append a key value to this array? public static tags: pulumi.Input<{[key: string]: pulumi.Input<string>}>; tags = { "key1": "val1", "key2": "val2" }; Doing this replaces all the current tags with just the one key/value pair tags && { "key3": "val3" }
b

bored-oyster-3147

08/17/2021, 8:13 PM
Is there a reason the value type needs to be
pulumi.Input<string>
? If this is for AWS Tags they tend to be
pulumi.Input<{[key: string]: string}>
and then before you pass it to the AWS Resource you can just use and manipulate a normal
{[key: string]: string}
because the
pulumi.Input<{[key: string]: string}>
will accept that
a

ancient-night-64850

08/18/2021, 12:50 PM
Yes, this is a Pulumi data type so it needs to be that. I didn't define it. Anyway I asked how I can append to the tags value. You said to manipulate a normal {key: string}: string}. How do I go about appending to that?
b

bored-oyster-3147

08/18/2021, 1:07 PM
Can you point to reference that is expecting a type of
pulumi.Input<{[key: string]: pulumi.Input<string>}>
? I want to be certain that is necessary because that is especially painful to work with. If that is 100% the correct type - then just declare it externally as
{[key: string]: pulumi.Input<string>}
and do everything you need to do like that before passing it in.
A normal
{[key: string]: string}
is just a standard typescript object with a string value type.
a

ancient-night-64850

08/18/2021, 1:10 PM
I did some playing around and you are correct, I can substitute {[key: string]: string}. How can I append to that?
b

bored-oyster-3147

08/18/2021, 1:11 PM
tags["key3"] = "val3"
or if it is allowed
tags.key3 = "val3"
a

ancient-night-64850

08/18/2021, 1:17 PM
well that was easy. I don't work with TS very often and most languages I know won't do dynamic appending. Awesome tho. Thank you very much for the help
b

bored-oyster-3147

08/18/2021, 1:17 PM
no problem, good luck
👍 1
20 Views