Hello, I am trying to set tags of an `aws.lb.Liste...
# typescript
l
Hello, I am trying to set tags of an
aws.lb.ListenerRule
to the ones set on an
aws.lb.TargetGroup
like:
Copy code
new aws.lb.ListenerRule(name, {[...], tags: tg.tags})
but I am getting:
Copy code
error TS2322: Type 'Output<{ [key: string]: string; } | undefined>' is not assignable to type 'Input<{ [key: string]: Input<string>; }> | undefined'.
  Type 'OutputInstance<{ [key: string]: string; } | undefined>' is not assignable to type 'Input<{ [key: string]: Input<string>; }> | undefined'.
    Type 'OutputInstance<{ [key: string]: string; } | undefined>' is not assignable to type 'OutputInstance<{ [key: string]: Input<string>; }>'.
      Type '{ [key: string]: string; } | undefined' is not assignable to type '{ [key: string]: Input<string>; }'.
        Type 'undefined' is not assignable to type '{ [key: string]: Input<string>; }'.
am I missing something obvious or should this just work?
w
It seems to be saying
tg.tags
is undefined. Is that the tags property from the TargetGroup?
l
@witty-candle-66007 yes
but if it was undefined, then it would be ok, right?
because tags can be undefined
w
true. Are they though? Is the TargetGroups tags not defined? And I may be inclined to declare a variable
tags = {"goo":"foo"}
and then assign that to the tags input for the TargetGroup and Listener resources.
l
@witty-candle-66007 passing them through this fixes the issue:
Copy code
// <https://pulumi-community.slack.com/archives/CJ909TL6P/p1636124629078600>
export function tagsOutput2Input(
    tags: pulumi.Output<{ [key: string]: string } | undefined>
): pulumi.Input<{ [key: string]: pulumi.Input<string> }> | undefined {
    if (tags === undefined) {
        return undefined
    }
    const dTags = tags as pulumi.Output<{ [key: string]: string }>
    return Object.keys(dTags).reduce(
        (result, name) => ({
            ...result,
            [name]: dTags[name],
        }),
        {}
    )
}
actually, this does the trick as well:
Copy code
export function tagsOutput2Input(
    tags: pulumi.Output<{ [key: string]: string } | undefined>
): pulumi.Input<{ [key: string]: pulumi.Input<string> }> | undefined {
    if (tags === undefined) {
        return undefined
    }
    return tags as pulumi.Output<{ [key: string]: string }>
}
w
Interesting. It may be worth opening an issue - you shouldn’t have to jump through hoops as such.
l
ok, thanks!
l
Try
tags: pulumi.output(tg.tags)
too. It's still a workaround and shouldn't be necessary, but at least it's easier to read.
l
@little-cartoon-10569 not really:
Copy code
error TS2322: Type 'Output<UnwrappedObject<{ [key: string]: string; }> | undefined>' is not assignable to type 'Input<{ [key: string]: Input<string>; }> | undefined'.