Hi.. I am exploring Pulumi for work and have a few...
# automation-api
h
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
hey! sorry to hear you're having doubts. Can you elaborate a little more on how you'd like it to look?
h
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
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
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
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
@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
oh right got it.. Thank you !!