https://pulumi.com logo
Title
g

great-sunset-355

01/13/2022, 9:39 AM
Hello, I'm trying to define a cloudwatch alarm and I'm getting TS error
TS2322: Type 'Output<string | undefined>' is not assignable to type 'Input<string>'
Because
dimmensions
is defined as
/**
     * The dimensions for this metric.  For the list of available dimensions see the AWS documentation [here](<http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html>).
     */
    dimensions?: pulumi.Input<{
        [key: string]: pulumi.Input<string>;
    }>;
Therefore I cannot use like this:
new aws.cloudwatch.MetricAlarm(
      this.rcName('CpuHigh'),
      {
       ...
        dimensions: {
          ClusterName: this.cluster.clusterName!,
          ServiceName: this.service.name
        }

      }
    )
I noticed a similar issue here: https://github.com/pulumi/pulumi-aws/pull/414 Is there any workaround for that?
b

brave-planet-10645

01/13/2022, 10:17 AM
What happens if you remove the
!
from the end of
clusterName
?
g

great-sunset-355

01/13/2022, 10:44 AM
nothing
I found a workaround using
interpolate
but it's not great IMO
w

white-balloon-205

01/13/2022, 6:05 PM
I believe what you are running into here is the same issue tracked in https://github.com/pulumi/pulumi/issues/6175. Note that this actually works fine in Node.js, just the TypeScript types don't allow it - so you can just cast to
any
and it will work. But there is also an improvement at the TypeScript layer being pursued in https://github.com/pulumi/pulumi/pull/6323 which would make this work without any need for workarounds.
🙌 1