https://pulumi.com logo
Title
l

little-whale-73288

11/05/2021, 3:03 PM
Hello, I am trying to set tags of an
aws.lb.ListenerRule
to the ones set on an
aws.lb.TargetGroup
like:
new aws.lb.ListenerRule(name, {[...], tags: tg.tags})
but I am getting:
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

witty-candle-66007

11/05/2021, 3:11 PM
It seems to be saying
tg.tags
is undefined. Is that the tags property from the TargetGroup?
l

little-whale-73288

11/05/2021, 3:12 PM
@witty-candle-66007 yes
but if it was undefined, then it would be ok, right?
because tags can be undefined
w

witty-candle-66007

11/05/2021, 3:19 PM
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

little-whale-73288

11/05/2021, 3:19 PM
@witty-candle-66007 passing them through this fixes the issue:
// <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:
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

witty-candle-66007

11/05/2021, 3:22 PM
Interesting. It may be worth opening an issue - you shouldn’t have to jump through hoops as such.
l

little-whale-73288

11/05/2021, 3:24 PM
ok, thanks!
l

little-cartoon-10569

11/05/2021, 8:47 PM
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-whale-73288

11/06/2021, 11:02 AM
@little-cartoon-10569 not really:
error TS2322: Type 'Output<UnwrappedObject<{ [key: string]: string; }> | undefined>' is not assignable to type 'Input<{ [key: string]: Input<string>; }> | undefined'.