https://pulumi.com logo
#general
Title
# general
m

many-house-85254

10/17/2023, 6:49 PM
Hi, my
___main___.py
is getting too big. Is it possible to move some things into a seperate python file and call them as a function? Or some other way to make my file shorter. I don't want to make a custom component (like this) because it is not going to be re-used - I just want to call the one function
deploy_kafka
and have all the services, deployments, etc deployed. The aim is to make
___main___.py
maintainable. Example: In `___main___.py`:
Copy code
from kafka.kafka import deploy_kafka
deploy_kafka()
In
kafka/kafka.py
,
Copy code
def kafka_service():
    <kafka service>

def kafka_deployment():
    <kafka deployment>

...

def deploy_kafka():
    kafka_service()
    kafka_deployment()
Thanks :)
f

fast-river-57630

10/17/2023, 7:45 PM
If you have a file like kafka/kafka.py with component resources, do you need an
__init__.py
file in the kafka folder? I would think importing component resources and functions would be the same, otherwise. That said, use component resources they are neat.
d

dry-keyboard-94795

10/17/2023, 7:45 PM
Yes, you can split up resource creation into functions. Your example should work as written with the separate files
I think it should work without the init file, but it can be added as a blank file if you get import errors
b

billowy-army-68599

10/17/2023, 7:50 PM
I would really not recommend using functions, it’s a road to complex nesting and pain.