Hi, I would like to do a mathematical operation on...
# cloudengineering-support
e
Hi, I would like to do a mathematical operation on an object output, for example pulumi_azure_nextgen.netapp.latest.Pool "total_throughput_mibps" attribute. But I cannot simply "netapp_pool.total_throughput_mibps * 10", is there a way to extract the float number? Thanks
s
What language are you writing in? In typescript you should be able to take an Output<T> and turn it into T:
Copy code
pulumi.all([myOutputT]).apply(([t]) => {
    // do stuff with t
    let myDownstreamDependency = new FooBar("asdasd", {
        variable: t * 10
    });
});
You should be able to the same in all languages
e
python
Tried this:
netapp_pool.total_throughput_mibps.apply(lambda x: float(x))
s
im not sure what type is returned in python but in js/ts/c# the type is a "future" type you need to wait over
e
Is my syntax correct?
s
i dont know the python sdk but from what i can see, when x is known yes this should be correct
e
Basically I get this error:
unsupported operand type(s) for *: 'Output' and 'int'
s
the problem is if you are waiting on the output from another command then the return type is a "future" type rather than a solid type
yeah, the
x
you are using is a Output of int
e
Sorry that error is when I try to multiply with an int
s
Yeah thats expected behaviour
you need to
apply
the value and create any dependent resources in the apply lambda
e
understood. Let me try
👍 1
s
alternatively what you can do is return the result of the operation, as that would be an Output[float], then pass that to the resource you wish to create
e
How can I do that?
s
Copy code
my_altered_output = your_property_thats_an_output.apply(
    lambda x: 10 * x
)

my.new.Resource('name',
  number_of_flibbles = my_altered_output
)
forgive my python, its terrible but thats the general idea
e
ok let me try
s
most libraries accept Input[T] as the input type, of which Output[T] conforms to, so unless its a custom resource you made your self it should work out the box
though do note that if you want to create anything like a json/yaml config file for anything like a kubernetes config map/app config file, then those do need the full output, so youll need to create those in the apply lambda as i mentioned above
else serialising will complain that "Output cannot be serialised" or similar
If you're still struggling im quite happy to screenshare and lend an assist (though probably tomorrow am)
e
It is working now. Thank you very much for your help
🤘 1
s
No worries mate, good luck with the rest!
e
Thanks. You too