Hello everyone, is there a way to have multiple `_...
# general
s
Hello everyone, is there a way to have multiple
__main__.py
files in Python? So I can be able to split users, databases, roles, etc.. Currently using Pulumi for the first time and I am trying to manage some Snowflake resources using pulumi_snowflake
e
Why do you need multiple
__main__.py
files? Just use normal python modules like you would for any other python program.
s
I've been trying to do that but somehow my resources are not detected, do you have any example you can point me to
e
Are you importing and calling into those modules?
s
Do you have to call things? The following seems to get detected
__main__.py
Copy code
from users import *
snowflake/user.py
Copy code
from pulumi_snowflake import User
from pulumi import ComponentResource, ResourceOptions


class SnowflakeUserArgs:
    def __init__(...
    ):
        ...


class SnowflakeUser(ComponentResource):
    def __init__(
        self, name, args: SnowflakeUserArgs, opts: ResourceOptions = None
    ):
        super().__init__("iac:snowflake:user", name, {}, opts)
        child_opts = ResourceOptions(parent=self)

        ...

        self.register_outputs({})
and then in the
users.py
Copy code
from snowflake.user import SnowflakeUser, SnowflakeUserArgs

test_user = SnowflakeUser(...)
Any thoughts on this?
e
Yup that's fine, python import will execute the top level of modules when imported
🙌 1
s
Awesome thanks for that!
b
Actually, I have a similar situation. I want to keep separated
__main__
files because I don't want to use the same Snowflake role for creating database, warehouses and for creating users/other roles. How would you do that ?
e
Have you looked at the "main" option in https://www.pulumi.com/docs/reference/pulumi-yaml/ Sounds like that might be what you need?
1064 Views