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

silly-receptionist-99224

03/31/2022, 3:43 PM
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

echoing-dinner-19531

03/31/2022, 3:44 PM
Why do you need multiple
__main__.py
files? Just use normal python modules like you would for any other python program.
s

silly-receptionist-99224

03/31/2022, 4:28 PM
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

echoing-dinner-19531

03/31/2022, 4:36 PM
Are you importing and calling into those modules?
s

silly-receptionist-99224

03/31/2022, 4:44 PM
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

echoing-dinner-19531

03/31/2022, 4:48 PM
Yup that's fine, python import will execute the top level of modules when imported
🙌 1
s

silly-receptionist-99224

03/31/2022, 4:48 PM
Awesome thanks for that!
b

bland-lawyer-98859

04/04/2022, 12:58 PM
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

echoing-dinner-19531

04/04/2022, 1:14 PM
Have you looked at the "main" option in https://www.pulumi.com/docs/reference/pulumi-yaml/ Sounds like that might be what you need?
832 Views