https://pulumi.com logo
p

powerful-finland-22510

09/18/2023, 1:31 PM
Hello, I've been working on developing an API with Flask and Automation API lately. During my research, I encountered some challenging aspects that couldn't be resolved with a simple online search or by referring to the documentation. Therefore, I've turned to you for assistance. My idea is quite straightforward – I plan to create multiple files containing the resource creation code (by example, for Datadog i would create monitor.py, slo.py, etc), with the routes located in app.py. Users may then use a curl command to access this API. I shouldn't require Pulumi Cloud, but it seems that without a main.py file automation api in python doesn't works, and if i use a main.py file I am unable to select the resource to create.. Is what I am experiencing like this or should I be able to do what I want to do? Thank you in advance!
c

cuddly-nightfall-71097

09/18/2023, 1:34 PM
In any case if you want to define your resources in separate files - turn them into modules
p

powerful-finland-22510

09/18/2023, 1:34 PM
Hi Yuri! Yes i've check exaples of automation-api... i do not checked self-service-platyform i will check it right now!!
c

cuddly-nightfall-71097

09/18/2023, 1:35 PM
and put your "create" "program" (the one which calls to
pulumi.*
to create resources) there
p

powerful-finland-22510

09/18/2023, 1:39 PM
mmm okey, i will be researching what you said Yuri... thanks for your help!
c

cuddly-nightfall-71097

09/18/2023, 1:39 PM
You can use your custom backend like this:
Copy code
PULUMI_PROJECT_NAME = "my-service"
PULUMI_BACKEND = "s3://<bucket>/<path>"
PULUMI_SECRETS_PROVIDER = "<awskms://alias/><pulumi-key>?region=eu-north-1"

def runner(count: int):
    for i in range(count):
        ec2.Instance(f"instance-{i}")
        ...
            

def deploy_runners(name: str, count: int, config: dict):
    stack = create_or_select_stack(
        stack_name=name,
        project_name=PULUMI_PROJECT_NAME,
        program=partial(runner, count),
        opts=LocalWorkspaceOptions(
            project_settings=ProjectSettings(
                name=PULUMI_PROJECT_NAME,
                runtime="python",
                backend=ProjectBackend(PULUMI_BACKEND),
            ),
            secrets_provider=PULUMI_SECRETS_PROVIDER,
            stack_settings={
                name: StackSettings(secrets_provider=PULUMI_SECRETS_PROVIDER)
            },
        ),
    )
    stack.set_all_config(
        {f"{PULUMI_PROJECT_NAME}:{k}": ConfigValue(v) for k, v in config.items()}
    )

    result = stack.up(on_output=print, color="always")
p

powerful-finland-22510

09/18/2023, 2:05 PM
Look Yuri, what i said, i took like example self-service-platyform that has no main.py file and Pulumi shows me this error: error: unable to find main python program `__main__.py I don't know why, and this causes that every resource has to be called from main.py file and this execute every creation of resource
c

cuddly-nightfall-71097

09/19/2023, 3:48 AM
My guess would be that you're trying to run
pulumi up
. When using automation you don't run pulumi directly. You run your script.
p

powerful-finland-22510

09/19/2023, 11:20 AM
oh, i didn't know that, yes i was running pulumi up... i will try run just the script
thank you Yuri, your advices helped me!!