https://pulumi.com logo
#automation-api
Title
# automation-api
h

hallowed-ice-8403

06/23/2021, 7:54 AM
Hi.. I am exploring Pulumi for work and have a few doubts, is there a possible way to eliminate the intermediate function and pass arguments directly for bringing up the stack ?
Copy code
def pulumi_program():
    create_pulumi_program(content)
stack = auto.select_stack(stack_name=stack_name, project_name=project_name,program=pulumi_program)
b

billowy-army-68599

06/23/2021, 8:11 AM
hey! sorry to hear you're having doubts. Can you elaborate a little more on how you'd like it to look?
h

hallowed-ice-8403

06/23/2021, 8:22 AM
My doubt is with respect to the create stack function. The program argument in create_stack(), accepts only function name without any arguments of its own.
Copy code
auto.create_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=pulumi_program)
so in turn we create a pass function that returns the actual function that creates required resources.
Copy code
def pulumi_program():
    return create_pulumi_s3(content)
is there a workaround for this if i need to call multiple functions ?
b

billowy-army-68599

06/23/2021, 8:44 AM
you can only pass a single function to a
create_stack
call (I think) but you can pass arguments to that function there's lots of examples of different mechanisms of passing in the pulumi program here: https://github.com/pulumi/automation-api-examples/tree/main/python
h

hallowed-ice-8403

06/23/2021, 12:01 PM
ohh, I was not able to pass any arguments and I couldn’t find any similar examples.. pls let me know if the below two cases valid ?
Copy code
auto.create_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=create_pulumi_s3(content))
Copy code
def pulumi_program():
    create_pulumi_s3(content)
    create_s3(name)
    return 
auto.create_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=pulumi_program)
b

billowy-army-68599

06/23/2021, 12:30 PM
it's hard to know if they're valid without running them, but it's just standard python, there's no reason
pulumi_program(content)
wouldn't just work if defined correctly
1
r

red-match-15116

06/23/2021, 2:54 PM
@hallowed-ice-8403 the second example is valid. But you don’t need the
return
in the function.
Copy code
def pulumi_program():
    create_pulumi_s3(content)
    create_s3(name)

auto.create_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=pulumi_program)
The first is not valid because the
pulumi_program
function itself does not accept any arguments, so it needs to be a wrapper around any functions that do take arguments.
h

hallowed-ice-8403

06/23/2021, 2:55 PM
oh right got it.. Thank you !!