https://pulumi.com logo
#cloudengineering-support
Title
# cloudengineering-support
e

echoing-postman-88590

10/13/2020, 3:26 PM
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

steep-spoon-2023

10/13/2020, 3:40 PM
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

echoing-postman-88590

10/13/2020, 3:40 PM
python
Tried this:
netapp_pool.total_throughput_mibps.apply(lambda x: float(x))
s

steep-spoon-2023

10/13/2020, 3:45 PM
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

echoing-postman-88590

10/13/2020, 3:45 PM
Is my syntax correct?
s

steep-spoon-2023

10/13/2020, 3:45 PM
i dont know the python sdk but from what i can see, when x is known yes this should be correct
e

echoing-postman-88590

10/13/2020, 3:46 PM
Basically I get this error:
unsupported operand type(s) for *: 'Output' and 'int'
s

steep-spoon-2023

10/13/2020, 3:46 PM
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

echoing-postman-88590

10/13/2020, 3:47 PM
Sorry that error is when I try to multiply with an int
s

steep-spoon-2023

10/13/2020, 3:47 PM
Yeah thats expected behaviour
you need to
apply
the value and create any dependent resources in the apply lambda
e

echoing-postman-88590

10/13/2020, 3:49 PM
understood. Let me try
👍 1
s

steep-spoon-2023

10/13/2020, 3:53 PM
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

echoing-postman-88590

10/13/2020, 3:54 PM
How can I do that?
s

steep-spoon-2023

10/13/2020, 3:58 PM
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

echoing-postman-88590

10/13/2020, 3:58 PM
ok let me try
s

steep-spoon-2023

10/13/2020, 3:59 PM
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

echoing-postman-88590

10/13/2020, 4:07 PM
It is working now. Thank you very much for your help
🤘 1
s

steep-spoon-2023

10/13/2020, 4:08 PM
No worries mate, good luck with the rest!
e

echoing-postman-88590

10/13/2020, 4:09 PM
Thanks. You too